Sha256: 98b4030494c42a04a036f58e5f9c79b6a3fee2bf06f163fc15038ee463403665

Contents?: true

Size: 1.75 KB

Versions: 20

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

module Mihari
  module Structs
    module VirusTotalIntelligence
      class ContextAttributes < Dry::Struct
        attribute :url, Types::String.optional

        def self.from_dynamic!(d)
          d = Types::Hash[d]
          new(
            url: d["url"]
          )
        end
      end

      class Datum < Dry::Struct
        attribute :type, Types::String
        attribute :id, Types::String
        attribute :context_attributes, ContextAttributes.optional
        attribute :metadata, Types::Hash

        def value
          case type
          when "file"
            id
          when "url"
            context_attributes&.url
          when "domain"
            id
          when "ip_address"
            id
          end
        end

        def self.from_dynamic!(d)
          d = Types::Hash[d]

          context_attributes = nil
          context_attributes = ContextAttributes.from_dynamic!(d.fetch("context_attributes")) if d.key?("context_attributes")

          new(
            type: d.fetch("type"),
            id: d.fetch("id"),
            context_attributes: context_attributes,
            metadata: d
          )
        end
      end

      class Meta < Dry::Struct
        attribute :cursor, Types::String.optional

        def self.from_dynamic!(d)
          d = Types::Hash[d]
          new(
            cursor: d["cursor"]
          )
        end
      end

      class Response < Dry::Struct
        attribute :meta, Meta
        attribute :data, Types.Array(Datum)

        def self.from_dynamic!(d)
          d = Types::Hash[d]
          new(
            meta: Meta.from_dynamic!(d.fetch("meta")),
            data: d.fetch("data").map { |x| Datum.from_dynamic!(x) }
          )
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mihari-5.2.1 lib/mihari/structs/virustotal_intelligence.rb
mihari-5.2.0 lib/mihari/structs/virustotal_intelligence.rb
mihari-5.1.4 lib/mihari/structs/virustotal_intelligence.rb
mihari-5.1.3 lib/mihari/structs/virustotal_intelligence.rb
mihari-5.1.2 lib/mihari/structs/virustotal_intelligence.rb
mihari-5.1.1 lib/mihari/structs/virustotal_intelligence.rb
mihari-5.1.0 lib/mihari/structs/virustotal_intelligence.rb
mihari-5.0.1 lib/mihari/structs/virustotal_intelligence.rb
mihari-5.0.0 lib/mihari/structs/virustotal_intelligence.rb
mihari-4.12.0 lib/mihari/structs/virustotal_intelligence.rb
mihari-4.11.0 lib/mihari/structs/virustotal_intelligence.rb
mihari-4.10.0 lib/mihari/structs/virustotal_intelligence.rb
mihari-4.9.0 lib/mihari/structs/virustotal_intelligence.rb
mihari-4.8.0 lib/mihari/structs/virustotal_intelligence.rb
mihari-4.7.4 lib/mihari/structs/virustotal_intelligence.rb
mihari-4.7.3 lib/mihari/structs/virustotal_intelligence.rb
mihari-4.7.2 lib/mihari/structs/virustotal_intelligence.rb
mihari-4.7.1 lib/mihari/structs/virustotal_intelligence.rb
mihari-4.7.0 lib/mihari/structs/virustotal_intelligence.rb
mihari-4.6.1 lib/mihari/structs/virustotal_intelligence.rb