Module: Ipregistry
- Defined in:
- lib/ipregistry.rb,
lib/ipregistry/cache.rb,
lib/ipregistry/client.rb,
lib/ipregistry/errors.rb,
lib/ipregistry/version.rb,
lib/ipregistry/models/base.rb,
lib/ipregistry/batch_response.rb,
lib/ipregistry/models/ip_info.rb,
lib/ipregistry/models/location.rb,
lib/ipregistry/models/user_agent.rb
Overview
Official Ruby client for the Ipregistry API (https://ipregistry.co), a fast and reliable IP geolocation and threat data service.
client = Ipregistry::Client.new("YOUR_API_KEY")
info = client.lookup("8.8.8.8")
info.location.country.name # => "United States"
info.security.vpn? # => false
Defined Under Namespace
Modules: Cache, Models Classes: ApiError, BadRequestError, BatchResponse, Client, ClientError, ConnectionError, DisabledApiKeyError, Error, ForbiddenIpError, ForbiddenIpOriginError, ForbiddenOriginError, InsufficientCreditsError, InternalError, InvalidApiKeyError, InvalidAsnError, InvalidFilterSyntaxError, InvalidIpAddressError, MissingApiKeyError, ParseError, ReservedAsnError, ReservedIpAddressError, TimeoutError, TooManyAsnsError, TooManyIpsError, TooManyRequestsError, TooManyUserAgentsError, UnknownAsnError
Constant Summary collapse
- ERRORS_BY_CODE =
Maps raw Ipregistry API error codes to their dedicated error class. See https://ipregistry.co/docs/errors for the authoritative list.
{ "BAD_REQUEST" => BadRequestError, "DISABLED_API_KEY" => DisabledApiKeyError, "FORBIDDEN_IP" => ForbiddenIpError, "FORBIDDEN_ORIGIN" => ForbiddenOriginError, "FORBIDDEN_IP_ORIGIN" => ForbiddenIpOriginError, "INTERNAL" => InternalError, "INSUFFICIENT_CREDITS" => InsufficientCreditsError, "INVALID_API_KEY" => InvalidApiKeyError, "INVALID_ASN" => InvalidAsnError, "INVALID_FILTER_SYNTAX" => InvalidFilterSyntaxError, "INVALID_IP_ADDRESS" => InvalidIpAddressError, "MISSING_API_KEY" => MissingApiKeyError, "RESERVED_ASN" => ReservedAsnError, "RESERVED_IP_ADDRESS" => ReservedIpAddressError, "TOO_MANY_ASNS" => TooManyAsnsError, "TOO_MANY_IPS" => TooManyIpsError, "TOO_MANY_REQUESTS" => TooManyRequestsError, "TOO_MANY_USER_AGENTS" => TooManyUserAgentsError, "UNKNOWN_ASN" => UnknownAsnError }.freeze
- VERSION =
Version of the client library, reported as part of the User-Agent header sent with every request to the Ipregistry API.
"1.0.0"
Class Method Summary collapse
-
.bot?(user_agent) ⇒ Boolean
Reports whether the given raw User-Agent string looks like a crawler or bot.
Class Method Details
.bot?(user_agent) ⇒ Boolean
Reports whether the given raw User-Agent string looks like a crawler or bot. It is a lightweight heuristic — useful for skipping IP lookups on automated traffic — that matches the substrings "bot", "spider", and "slurp" case-insensitively.
unless Ipregistry.bot?(request.user_agent)
info = client.lookup(request.remote_ip)
end
29 30 31 32 |
# File 'lib/ipregistry.rb', line 29 def self.bot?(user_agent) value = user_agent.to_s.downcase value.include?("bot") || value.include?("spider") || value.include?("slurp") end |