Sha256: 53bd329d040d88dd1af5f0b3e333c2a8200f40d1531033b4d0bd174c8d109b38

Contents?: true

Size: 1.43 KB

Versions: 28

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module Mihari
  module Structs
    module GreyNoise
      class Metadata < Dry::Struct
        attribute :country, Types::String
        attribute :country_code, Types::String
        attribute :asn, Types::String

        def self.from_dynamic!(d)
          d = Types::Hash[d]
          new(
            country: d.fetch("country"),
            country_code: d.fetch("country_code"),
            asn: d.fetch("asn")
          )
        end
      end

      class Datum < Dry::Struct
        attribute :ip, Types::String
        attribute :metadata, Metadata
        attribute :metadata_, Types::Hash

        def self.from_dynamic!(d)
          d = Types::Hash[d]
          new(
            ip: d.fetch("ip"),
            metadata: Metadata.from_dynamic!(d.fetch("metadata")),
            metadata_: d
          )
        end
      end

      class Response < Dry::Struct
        attribute :complete, Types::Bool
        attribute :count, Types::Int
        attribute :data, Types.Array(Datum)
        attribute :message, Types::String
        attribute :query, Types::String

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

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
mihari-5.1.1 lib/mihari/structs/greynoise.rb
mihari-5.1.0 lib/mihari/structs/greynoise.rb
mihari-5.0.1 lib/mihari/structs/greynoise.rb
mihari-5.0.0 lib/mihari/structs/greynoise.rb
mihari-4.12.0 lib/mihari/structs/greynoise.rb
mihari-4.11.0 lib/mihari/structs/greynoise.rb
mihari-4.10.0 lib/mihari/structs/greynoise.rb
mihari-4.9.0 lib/mihari/structs/greynoise.rb
mihari-4.8.0 lib/mihari/structs/greynoise.rb
mihari-4.7.4 lib/mihari/structs/greynoise.rb
mihari-4.7.3 lib/mihari/structs/greynoise.rb
mihari-4.7.2 lib/mihari/structs/greynoise.rb
mihari-4.7.1 lib/mihari/structs/greynoise.rb
mihari-4.7.0 lib/mihari/structs/greynoise.rb
mihari-4.6.1 lib/mihari/structs/greynoise.rb
mihari-4.6.0 lib/mihari/structs/greynoise.rb
mihari-4.5.3 lib/mihari/structs/greynoise.rb
mihari-4.5.2 lib/mihari/structs/greynoise.rb
mihari-4.5.1 lib/mihari/structs/greynoise.rb
mihari-4.5.0 lib/mihari/structs/greynoise.rb