class GoogleMapsAPI::Core::URISigner
Public Class Methods
sign(uri, client, key, channel = nil)
click to toggle source
# File lib/google_maps_api/core/uri_signer.rb, line 5 def self.sign(uri, client, key, channel = nil) uri = URI(URI.encode(uri)) path = "#{uri.path}?#{uri.query}&client=#{client}" path << "&channel=#{channel}" if channel URI("#{uri.scheme}://#{uri.host}#{path}&signature=#{signature(path, key)}") end
Private Class Methods
signature(string, key)
click to toggle source
# File lib/google_maps_api/core/uri_signer.rb, line 14 def self.signature(string, key) raw_private_key = url_safe_base64_decode(key) digest = OpenSSL::Digest.new('sha1') raw_signature = OpenSSL::HMAC.digest(digest, raw_private_key, string) url_safe_base64_encode(raw_signature) end
url_safe_base64_decode(base64_string)
click to toggle source
# File lib/google_maps_api/core/uri_signer.rb, line 21 def self.url_safe_base64_decode(base64_string) Base64.decode64(base64_string.tr('-_', '+/')) end
url_safe_base64_encode(raw)
click to toggle source
# File lib/google_maps_api/core/uri_signer.rb, line 25 def self.url_safe_base64_encode(raw) Base64.encode64(raw).tr('+/', '-_').strip end