Module: Eztz

Defined in:
lib/eztz.rb,
lib/eztz/client.rb,
lib/eztz/errors.rb,
lib/eztz/version.rb,
lib/eztz/response.rb

Overview

Ruby wrapper for the Google Time Zone API.

Examples:

Sample usage

# Set your api key
Eztz.api_key = 'YOUR_API_KEY'
# location as a string
Eztz.timezone(location: "-33.86,151.20")
# location as an array
Eztz.timezone(location: [-33.86,151.20])

Defined Under Namespace

Classes: ApiError, Client, TimeZoneResponse

Constant Summary collapse

VERSION =
"2.0.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyString

Returns Your application’s API key. Api keys can be obtained at developers.google.com/maps/documentation/timezone/get-api-key.

Returns:



22
23
24
# File 'lib/eztz.rb', line 22

def api_key
  @api_key
end

Class Method Details

.clientEztz::Client

The Eztz client

Returns:



35
36
37
# File 'lib/eztz.rb', line 35

def client
  @client ||= Eztz::Client.new
end

.configure {|_self| ... } ⇒ Object

Examples:

Configure api key with a configuration block

Eztz.configure do |config|
  config.api_key = 'XYZ'
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Eztz)

    the object that the method was called on



28
29
30
31
# File 'lib/eztz.rb', line 28

def configure
  yield self
  true
end

.timezone(location:, timestamp: Time.now.utc.to_i, language: "en") ⇒ Eztz::TimeZoneResponse

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

Examples:

Get the timezone for a location

Eztz.timezone(location: "-33.86,151.20")
=> #<Eztz::TimeZoneResponse:0x007fe71c906298 @timestamp=1488580176,
  @dst_offset=3600, @error_message=nil, @raw_offset=36000,
  @status="OK", @id="Australia/Sydney",
  @name="Australian Eastern Daylight Time">

Parameters:

  • location (String, Array)

    a comma-separated lat,lng tuple (eg. “-33.86,151.20”), representing the location to look up. Can also be an array (eg. [-33.86, 151.20]).

  • timestamp (Integer) (defaults to: Time.now.utc.to_i)

    specifies the desired time as seconds since midnight, January 1, 1970 UTC. The Google Maps Time Zone API uses the timestamp to determine whether or not Daylight Savings should be applied. Times before 1970 can be expressed as negative values. Defaults to the current time.

  • language (String) (defaults to: "en")

    The language in which to return results Defaults to ‘en’. A list of supported languages can be found at developers.google.com/maps/faq#languagesupport

Returns:

Raises:

  • (ArgumentError)

    if location is not provided

  • (ApiError)

    if the API returns an error response.



62
63
64
65
66
# File 'lib/eztz.rb', line 62

def timezone(location:, timestamp: Time.now.utc.to_i, language: "en")
  client.timezone(location: location,
    timestamp: timestamp,
    language: language)
end