Class: GoogleMaps::Services::Util
- Inherits:
-
Object
- Object
- GoogleMaps::Services::Util
- Defined in:
- lib/googlemaps/services/util.rb
Overview
Set of utility methods.
Class Method Summary collapse
-
.current_time ⇒ Time
Returns the current time.
-
.current_unix_time ⇒ Integer
Returns the current time in unix format (seconds since unix epoch).
-
.current_utctime ⇒ Time
Returns the current UTC time.
-
.sign_hmac(secret, payload) ⇒ String
Returns a base64-encoded HMAC-SHA1 signature of a given string.
-
.urlencode_params(params) ⇒ String
URL encodes the parameters.
Class Method Details
.current_time ⇒ Time
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).
71 72 73 |
# File 'lib/googlemaps/services/util.rb', line 71 def self.current_time (Time.respond_to? :current) ? Time.current : Time.now end |
.current_unix_time ⇒ Integer
Returns the current time in unix format (seconds since unix epoch).
85 86 87 |
# File 'lib/googlemaps/services/util.rb', line 85 def self.current_unix_time current_time.to_i end |
.current_utctime ⇒ Time
Returns the current UTC time.
78 79 80 |
# 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) ⇒ String
Returns a base64-encoded HMAC-SHA1 signature of a given string.
95 96 97 98 99 100 101 |
# 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) ⇒ String
URL encodes the parameters.
108 109 110 |
# File 'lib/googlemaps/services/util.rb', line 108 def self.urlencode_params(params) URI.encode_www_form(params) end |