Sha256: d86085fb6667b98f15c70ef29fee6eb4942640645dd553e68afeaba6528d6043

Contents?: true

Size: 1.3 KB

Versions: 28

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Mihari
  module Structs
    module Onyphe
      class Result < Dry::Struct
        attribute :asn, Types::String
        attribute :country_code, Types::String.optional
        attribute :ip, Types::String
        attribute :metadata, Types::Hash

        def self.from_dynamic!(d)
          d = Types::Hash[d]
          new(
            asn: d.fetch("asn"),
            ip: d.fetch("ip"),
            # Onyphe's country = 2-letter country code
            country_code: d["country"],
            metadata: d
          )
        end
      end

      class Response < Dry::Struct
        attribute :count, Types::Int
        attribute :error, Types::Int
        attribute :max_page, Types::Int
        attribute :page, Types::Int
        attribute :results, Types.Array(Result)
        attribute :status, Types::String
        attribute :total, Types::Int

        def self.from_dynamic!(d)
          d = Types::Hash[d]
          new(
            count: d.fetch("count"),
            error: d.fetch("error"),
            max_page: d.fetch("max_page"),
            page: d.fetch("page").to_i,
            results: d.fetch("results").map { |x| Result.from_dynamic!(x) },
            status: d.fetch("status"),
            total: d.fetch("total")
          )
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

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