forked from alexreisner/geocoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5dcaf5
commit 46ab278
Showing
6 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'openssl' | ||
require 'base64' | ||
require 'geocoder/lookups/google' | ||
require 'geocoder/results/google_premier' | ||
|
||
module Geocoder::Lookup | ||
class GooglePremier < Google | ||
|
||
private # --------------------------------------------------------------- | ||
|
||
def query_url(query, reverse = false) | ||
params = { | ||
(reverse ? :latlng : :address) => query, | ||
:sensor => 'false', | ||
:language => Geocoder::Configuration.language, | ||
:client => Geocoder::Configuration.api_client, | ||
:channel => Geocoder::Configuration.api_channel | ||
}.reject{ |key, value| value.nil? } | ||
|
||
path = "/maps/api/geocode/json?#{hash_to_query(params)}" | ||
|
||
signature = sign(path) | ||
|
||
"#{protocol}://maps.googleapis.com#{path}&signature=#{signature}" | ||
end | ||
|
||
def sign(string) | ||
raw_private_key = url_safe_base64_decode(Geocoder::Configuration.api_key) | ||
digest = OpenSSL::Digest::Digest.new('sha1') | ||
raw_signature = OpenSSL::HMAC.digest(digest, raw_private_key, string) | ||
url_safe_base64_encode(raw_signature) | ||
end | ||
|
||
def url_safe_base64_decode(base64_string) | ||
Base64.decode64(base64_string.tr('-_', '+/')) | ||
end | ||
|
||
def url_safe_base64_encode(raw) | ||
Base64.encode64(raw).tr('+/', '-_').strip | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'geocoder/results/google' | ||
|
||
module Geocoder::Result | ||
class GooglePremier < Google | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters