class Timezonedb::Client
Constants
- FREE_URL
- PREMIUM_URL
- VERSION
Public Class Methods
new(api_key, options = {})
click to toggle source
# File lib/timezonedb/client.rb, line 28 def initialize(api_key, options = {}) @api_key = api_key premium = options[:premium] @url = premium ? PREMIUM_URL : FREE_URL end
Public Instance Methods
search_by_coords(latitude, longitude)
click to toggle source
# File lib/timezonedb/client.rb, line 34 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