class GoogleMaps::Services::Util

Set of utility methods.

Public Class Methods

current_time() click to toggle source

Returns the current time

Rails extends the Time and DateTime objects, and includes the “current” property for retrieving the time the Rails environment is set to (default = UTC), as opposed to the server time (Could be anything).

@return [Time] a new Time object for the current time.

# File lib/googlemaps/services/util.rb, line 71
def self.current_time
  (Time.respond_to? :current) ? Time.current : Time.now
end
current_unix_time() click to toggle source

Returns the current time in unix format (seconds since unix epoch).

@return [Integer] number of seconds since unix epoch.

# File lib/googlemaps/services/util.rb, line 85
def self.current_unix_time
  current_time.to_i
end
current_utctime() click to toggle source

Returns the current UTC time.

@return [Time] a new Time object for the current UTC (GMT) time.

# File lib/googlemaps/services/util.rb, line 78
def self.current_utctime
  (Time.respond_to? :current) ? Time.current.utc : Time.now.utc
end
sign_hmac(secret, payload) click to toggle source

Returns a base64-encoded HMAC-SHA1 signature of a given string.

@param [String] secret The key used for the signature, base64 encoded. @param [String] payload The payload to sign.

@return [String] a base64-encoded signature string.

# File lib/googlemaps/services/util.rb, line 95
def self.sign_hmac(secret, payload)
  payload = payload.encode('ascii')
  secret = secret.encode('ascii')
  digest = OpenSSL::Digest.new('sha1')
  sig = OpenSSL::HMAC.digest(digest, Base64.urlsafe_decode64(secret), payload)
  return Base64.urlsafe_encode64(sig).encode('utf-8')
end
urlencode_params(params) click to toggle source

URL encodes the parameters.

@param [Hash] params The parameters.

@return [String] URL-encoded string.

# File lib/googlemaps/services/util.rb, line 108
def self.urlencode_params(params)
  URI.encode_www_form(params)
end