Sha256: afb1a8ecedca3d331401b49e3a9ab143b2e88e40a19694e8d67b70341a2a922e
Contents?: true
Size: 954 Bytes
Versions: 4
Compression:
Stored size: 954 Bytes
Contents
# frozen_string_literal: true require "net/https" module Mihari module Enrichers class IPInfo < Base # @return [Boolean] def valid? Mihari.config.ipinfo_api_key.nil? end private def configuration_keys %w[ipinfo_api_key] end class << self include Dry::Monads[:result] include Memist::Memoizable # # Query IPInfo # # @param [String] ip # # @return [Mihari::Structs::IPInfo::Response, nil] # def query(ip) headers = {} token = Mihari.config.ipinfo_api_key headers[:authorization] = "Bearer #{token}" unless token.nil? url = "https://ipinfo.io/#{ip}/json" res = HTTP.get(url, headers: headers) data = JSON.parse(res.body.to_s) Structs::IPInfo::Response.from_dynamic! data end memoize :query end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
mihari-5.4.7 | lib/mihari/enrichers/ipinfo.rb |
mihari-5.4.6 | lib/mihari/enrichers/ipinfo.rb |
mihari-5.4.5 | lib/mihari/enrichers/ipinfo.rb |
mihari-5.4.4 | lib/mihari/enrichers/ipinfo.rb |