Class: Timezone::Lookup::Google
- Defined in:
- lib/timezone/lookup/google.rb
Instance Attribute Summary
Attributes inherited from Basic
Instance Method Summary collapse
-
#initialize(config) ⇒ Google
constructor
A new instance of Google.
- #lookup(lat, lng) ⇒ Object
Methods inherited from Basic
Constructor Details
#initialize(config) ⇒ Google
Returns a new instance of Google.
12 13 14 15 16 17 |
# File 'lib/timezone/lookup/google.rb', line 12 def initialize(config) if config.google_api_key.nil? raise(::Timezone::Error::InvalidConfig, 'missing api key') end super end |
Instance Method Details
#lookup(lat, lng) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/timezone/lookup/google.rb', line 19 def lookup(lat,lng) response = client.get(url(lat,lng)) if response.code == '403' raise(Timezone::Error::Google, '403 Forbidden') end return unless response.code =~ /^2\d\d$/ data = JSON.parse(response.body) if data['status'] != 'OK' raise(Timezone::Error::Google, data['errorMessage']) end data['timeZoneId'] rescue => e raise(Timezone::Error::Google, e.) end |