Class: Geo

Inherits:
Object
  • Object
show all
Defined in:
lib/meteo/geo.rb

Constant Summary collapse

GEO_LOCATION_SERVICE_URL =
"http://freegeoip.net/json/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGeo

Returns a new instance of Geo.



9
10
11
# File 'lib/meteo/geo.rb', line 9

def initialize
  @url = GEO_LOCATION_SERVICE_URL
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/meteo/geo.rb', line 7

def url
  @url
end

Instance Method Details

#quote(ip_address = nil) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/meteo/geo.rb', line 13

def quote ip_address=nil
  quote_url = ip_address ? "#{url}#{ip_address}" : url

  uri = URI.parse(URI.escape(quote_url))

  JSON.parse(Net::HTTP.get(uri))
end