Module: GeoIPClient
- Defined in:
- lib/geoip_client.rb,
lib/geoip_client/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Class Method Details
.host=(host) ⇒ Object
9 10 11 |
# File 'lib/geoip_client.rb', line 9 def self.host=(host) @host = host end |
.look_up(ip) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/geoip_client.rb', line 13 def self.look_up(ip) raw = Net::HTTP.get(URI.parse("#{@host}/json/#{ip}")) if raw == 'null' json = { country_code: "LO", country_code3: "LOC", country_name: "Localhost Country", region: "Localhost Region", city: "Localhost City", latitude: 0, longitude: 0, dma_code: 0, area_code: 0 } else json = JSON.parse(raw) end json.inject({}) do |hash, (key, value)| hash[key.to_sym] = value hash end end |