Sha256: e9f939efe3e56664995e22f58c2b769a1e918123937ea9b83cd4330ec0da53be
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true require "json" require "dry/struct" module Mihari module Structs module Onyphe class Result < Dry::Struct attribute :asn, Types::String attribute :country_code, Types::String.optional attribute :ip, Types::String 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"] ) end end class Response < Dry::Struct attribute :count, Types::Int attribute :error, Types::Int attribute :max_page, Types::Int attribute :page, Types::String 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"), 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mihari-3.12.0 | lib/mihari/structs/onyphe.rb |