Class: Timezonedb::Client
- Inherits:
-
Object
- Object
- Timezonedb::Client
- Defined in:
- lib/timezonedb/client.rb,
lib/timezonedb/client/error.rb,
lib/timezonedb/client/version.rb,
lib/timezonedb/client/response.rb
Defined Under Namespace
Constant Summary collapse
- FREE_URL =
'http://api.timezonedb.com'
- PREMIUM_URL =
'http://vip.timezonedb.com'
- VERSION =
'0.1.1'
Instance Method Summary collapse
-
#initialize(api_key, premium = false) ⇒ Client
constructor
A new instance of Client.
- #search_by_coords(latitude, longitude) ⇒ Object
Constructor Details
#initialize(api_key, premium = false) ⇒ Client
Returns a new instance of Client.
28 29 30 31 |
# File 'lib/timezonedb/client.rb', line 28 def initialize(api_key, premium = false) @api_key = api_key @url = premium ? PREMIUM_URL : FREE_URL end |
Instance Method Details
#search_by_coords(latitude, longitude) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/timezonedb/client.rb', line 33 def search_by_coords(latitude, longitude) params = { key: @api_key, lat: latitude, lng: longitude, format: 'json' } response = RestClient.get @url, params: params response_hash = JSON.parse(response) if response_hash['status'] == 'OK' Response.new(response_hash) else fail Timezonedb::Client::Error.new(response_hash['message']) end rescue RestClient::Exception => e raise Timezonedb::Client::Error.new(e.inspect) end |