Class: Eztz::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/eztz/client.rb

Class Method Summary collapse

Class Method Details

.timezone(params = {}) ⇒ Hashie::Mash

Gets timezone information for a location on earth, as well as that location's time offset from UTC.

Examples:

Get timezone data

Eztz::Client.timezone(location: "-33.86,151.20")
=> #<Hashie::Mash dstOffset=3600.0 rawOffset=36000.0 status="OK" timeZoneId="Australia/Sydney" timeZoneName="Australian Eastern Daylight Time">

Options Hash (params):

  • :location (String)

    a comma-separated lat,lng tuple. (eg. “-33.86,151.20”)

  • :lat (String, Float)

    latitude (eg. -33.86)

  • :lng (String, Float)

    longitude (ex. 151.20)

  • :sensor (Boolean)

    specifies whether the application requesting data is using a sensor. Defaults to false

  • :timestamp (Integer)

    specifies the desired time as seconds since midnight, January 1, 1970 UTC. Defaults to now

  • :language (String)

    the language in which to return results. Defaults to en.

Raises:

  • (ArgumentError)

    if :location or :lat and :lng are not provided


41
42
43
44
45
46
47
# File 'lib/eztz/client.rb', line 41

def self.timezone(params={})
  params[:location] = "#{params.delete(:lat)},#{params.delete(:lng)}" if params[:lat] && params[:lng]
  raise ArgumentError, 'You must provide a location' if params[:location].nil? || params[:location].empty? || params[:location] == ','
  params[:sensor] ||= false
  params[:timestamp] ||= Time.now.to_i
  Hashie::Mash.new self.get('/maps/api/timezone/json', query: params)
end