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.
9 10 11 12 13 14 |
# File 'lib/timezone/lookup/google.rb', line 9 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/timezone/lookup/google.rb', line 16 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'] != 'OK' raise(Timezone::Error::Google, data['errorMessage']) end data['timeZoneId'] rescue => e raise(Timezone::Error::Google, e.) end |