Class: MaxmindCity

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/maxmind_city.rb,
lib/maxmind_city/version.rb

Constant Summary collapse

VERSION =
"0.1.1"
@@license_key =
nil

Class Method Summary collapse

Class Method Details

.license_key=(new_license_key) ⇒ Object



10
11
12
# File 'lib/maxmind_city.rb', line 10

def self.license_key=( new_license_key )
  @@license_key = new_license_key
end

.lookup(ip) ⇒ Object



14
15
16
17
18
# File 'lib/maxmind_city.rb', line 14

def self.lookup( ip )
  self.parse_response(
    self.get("/b", :query => {:l => @@license_key, :i => ip})
  )
end

.parse_response(response) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/maxmind_city.rb', line 20

def self.parse_response( response )
  {
    :country_code => response.split(",")[0],
    :region_code => response.split(",")[1],
    :city => response.split(",")[2],
    :latitude => response.split(",")[3],
    :longitude => response.split(",")[4]
  }
end