Sha256: 314fe46db50fc7a13690f772baab2d3ee155dfe33ff5a2bc199a66f3db82786d

Contents?: true

Size: 1.51 KB

Versions: 20

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Mihari
  module Structs
    module IPInfo
      class Response < Dry::Struct
        attribute :ip, Types::String
        attribute :hostname, Types::String.optional
        attribute :loc, Types::String.optional
        attribute :country_code, Types::String.optional
        attribute :asn, Types::Integer.optional

        #
        # @return [String]
        #
        def ip
          attributes[:ip]
        end

        #
        # @return [String, nil]
        #
        def hostname
          attributes[:hostname]
        end

        #
        # @return [String, nil]
        #
        def loc
          attributes[:loc]
        end

        #
        # @return [String, nil]
        #
        def country_code
          attributes[:country_code]
        end

        #
        # @return [Integer, nil]
        #
        def asn
          attributes[:asn]
        end

        class << self
          include Mixins::AutonomousSystem

          #
          # @param [Hash] d
          #
          # @return [Response]
          #
          def from_dynamic!(d)
            d = d.deep_stringify_keys
            d = Types::Hash[d]

            asn = nil
            asn_ = d.dig("asn", "asn")
            asn = normalize_asn(asn_) unless asn_.nil?

            new(
              ip: d.fetch("ip"),
              loc: d["loc"],
              hostname: d["hostname"],
              country_code: d["country"],
              asn: asn
            )
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mihari-5.6.2 lib/mihari/structs/ipinfo.rb
mihari-5.6.1 lib/mihari/structs/ipinfo.rb
mihari-5.6.0 lib/mihari/structs/ipinfo.rb
mihari-5.5.0 lib/mihari/structs/ipinfo.rb
mihari-5.4.9 lib/mihari/structs/ipinfo.rb
mihari-5.4.8 lib/mihari/structs/ipinfo.rb
mihari-5.4.7 lib/mihari/structs/ipinfo.rb
mihari-5.4.6 lib/mihari/structs/ipinfo.rb
mihari-5.4.5 lib/mihari/structs/ipinfo.rb
mihari-5.4.4 lib/mihari/structs/ipinfo.rb
mihari-5.4.3 lib/mihari/structs/ipinfo.rb
mihari-5.4.2 lib/mihari/structs/ipinfo.rb
mihari-5.4.1 lib/mihari/structs/ipinfo.rb
mihari-5.4.0 lib/mihari/structs/ipinfo.rb
mihari-5.3.2 lib/mihari/structs/ipinfo.rb
mihari-5.3.1 lib/mihari/structs/ipinfo.rb
mihari-5.3.0 lib/mihari/structs/ipinfo.rb
mihari-5.2.4 lib/mihari/structs/ipinfo.rb
mihari-5.2.3 lib/mihari/structs/ipinfo.rb
mihari-5.2.2 lib/mihari/structs/ipinfo.rb