Module: SimpleGeolocator

Defined in:
lib/simple_geolocator/ipapi_response.rb,
lib/simple_geolocator.rb

Overview

noinspection RubyTooManyInstanceVariablesInspection

Defined Under Namespace

Classes: IPAPIResponse

Constant Summary collapse

URL_FORMAT =
'http://ip-api.com/json/%s?fields=258047'.freeze

Class Method Summary collapse

Class Method Details

.get(ip) ⇒ IPAPIResponse

Gets the full response. From here, all the data related to the IP can be accessed. Caches the result in order to

prevent reaching the rate limit.

Parameters:

  • ip (String)

    The IP to get data for.

Returns:



17
18
19
20
21
22
23
# File 'lib/simple_geolocator.rb', line 17

def get(ip)
  return @cache[ip] if @cache.key?(ip)
  url = format(URL_FORMAT, ip)
  response = Curl.get(url).body_str
  ipapi = SimpleGeolocator::IPAPIResponse.new(Oj.load(response))
  @cache[ip] = ipapi
end