Class: Timezone::Lookup::Geonames

Inherits:
Basic
  • Object
show all
Defined in:
lib/timezone/lookup/geonames.rb

Instance Attribute Summary

Attributes inherited from Basic

#config

Instance Method Summary collapse

Methods inherited from Basic

#client, #initialize

Constructor Details

This class inherits a constructor from Timezone::Lookup::Basic

Instance Method Details

#lookup(lat, lng) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/timezone/lookup/geonames.rb', line 9

def lookup(lat, lng)
  response = client.get(url(lat, lng))

  return unless response.code =~ /^2\d\d$/

  data = JSON.parse(response.body)

  if data['status'] && data['status']['value'] == 18
    raise(Timezone::Error::GeoNames, 'api limit reached')
  end

  data['timezoneId']
rescue => e
  raise(Timezone::Error::GeoNames, e.message)
end