Sha256: 5ba5403276181522f123620f756626d9ff851d31debc030138608425b1644e0c
Contents?: true
Size: 1.06 KB
Versions: 3
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true module Mihari module Enrichers # # IPInfo enricher # class IPInfo < Base # @return [String, nil] attr_reader :api_key # # @param [Hash, nil] options # @param [String, nil] api_key # def initialize(options: nil, api_key: nil) @api_key = api_key || Mihari.config.ipinfo_api_key super(options: options) end def configuration_keys %w[ipinfo_api_key] end # # Query IPInfo # # @param [String] ip # # @return [Mihari::Structs::IPInfo::Response] # def call(ip) url = "https://ipinfo.io/#{ip}/json" res = http.get(url) Structs::IPInfo::Response.from_dynamic! JSON.parse(res.body.to_s) end memo_wise :call private def headers authorization = api_key.nil? ? nil : "Bearer #{api_key}" { authorization: authorization }.compact end def http HTTP::Factory.build headers: headers, timeout: timeout end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mihari-6.3.0 | lib/mihari/enrichers/ipinfo.rb |
mihari-6.2.0 | lib/mihari/enrichers/ipinfo.rb |
mihari-6.1.0 | lib/mihari/enrichers/ipinfo.rb |