Class: GoogleMaps::Services::Timezone

Inherits:
Object
  • Object
show all
Defined in:
lib/googlemaps/services/timezone.rb

Overview

Performs requests to the Google Maps Timezone API.

Examples:

timezone = GoogleMaps::Services::Timezone.new(client)
result = timezone.query(location: "38.908133,-77.047119")

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Timezone

Returns a new instance of Timezone.

Since:

  • 1.0.0



15
16
17
# File 'lib/googlemaps/services/timezone.rb', line 15

def initialize(client)
  self.client = client
end

Instance Attribute Details

#clientSymbol

Returns The HTTP client.

Returns:

  • (Symbol)

    The HTTP client.

Since:

  • 1.0.0



13
14
15
# File 'lib/googlemaps/services/timezone.rb', line 13

def client
  @client
end

Instance Method Details

#query(location:, timestamp: nil, language: nil) ⇒ Hash

Get time zone for a location on the earth, as well as that location’s time offset from UTC.

Parameters:

  • location (String, Hash)

    The lat/lng value representing the location to look up.

  • timestamp (Integer, Time, Date) (defaults to: nil)

    Specifies the desired time as seconds since midnight, January 1, 1970 UTC. The 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. Optional. Defaults to Util.current_utctime.

  • language (String) (defaults to: nil)

    The language in which to return results.

Returns:

  • (Hash)

    Valid JSON or XML response.

Since:

  • 1.0.0



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/googlemaps/services/timezone.rb', line 28

def query(location:, timestamp: nil, language: nil)
  params = {
      'location' => Convert.to_latlng(location),
      'timestamp' => Convert.unix_time(timestamp || Util.current_utctime)
  }

  if language
    params['language'] = language
  end

  self.client.request(url: "/maps/api/timezone/#{self.client.response_format}", params: params)
end