google_maps_api-core 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edb38a4fdc4dc65e2d024791b65c43e441015cf9
|
4
|
+
data.tar.gz: 37c3a0a25634e8da7ff2ba3d68df94fdac2908d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3e559b9837422185c2c882f9a884b72e4f719cf054f2282d75487732b71e12435ab187cff89ac74f9cd2532a51c737fd6cff014fa5065d1c3c304d1a6dfa2fa
|
7
|
+
data.tar.gz: b7da242ce0f93e431a8a650c96cde1c4854f9ad9cf849d492d1f33baceadb06883f8d6dffdc964ce59a431c9f254adcd25a66e0690867e3a5a739bbc0e6ce76a
|
data/lib/google_maps_api/core.rb
CHANGED
@@ -3,7 +3,10 @@ require "google_maps_api/core/metric"
|
|
3
3
|
require "google_maps_api/core/duration"
|
4
4
|
require "google_maps_api/core/distance"
|
5
5
|
require "google_maps_api/core/coordinate"
|
6
|
+
require "google_maps_api/core/uri_signer"
|
6
7
|
|
7
8
|
module GoogleMapsAPI
|
8
|
-
module Core
|
9
|
+
module Core
|
10
|
+
BASE_HOST = "maps.googleapis.com"
|
11
|
+
end
|
9
12
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "base64"
|
3
|
+
|
4
|
+
class GoogleMapsAPI::Core::URISigner
|
5
|
+
def self.sign(uri, client, key, channel = nil)
|
6
|
+
uri = URI(URI.encode(uri))
|
7
|
+
path = "#{uri.path}?#{uri.query}&client=#{client}"
|
8
|
+
path << "&channel=#{channel}" if channel
|
9
|
+
URI("#{uri.scheme}://#{uri.host}#{path}&signature=#{signature(path, key)}")
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def self.signature(string, key)
|
15
|
+
raw_private_key = url_safe_base64_decode(key)
|
16
|
+
digest = OpenSSL::Digest.new('sha1')
|
17
|
+
raw_signature = OpenSSL::HMAC.digest(digest, raw_private_key, string)
|
18
|
+
url_safe_base64_encode(raw_signature)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.url_safe_base64_decode(base64_string)
|
22
|
+
Base64.decode64(base64_string.tr('-_', '+/'))
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.url_safe_base64_encode(raw)
|
26
|
+
Base64.encode64(raw).tr('+/', '-_').strip
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GoogleMapsAPI::Core::URISigner do
|
4
|
+
subject { GoogleMapsAPI::Core::URISigner }
|
5
|
+
|
6
|
+
describe ".sign" do
|
7
|
+
it "returns a signed uri" do
|
8
|
+
uri = "http://maps.googleapis.com/maps/api/geocode/json?address=1845,AV+IMPERATRIZ+LEOPOLDINA,05305-007&sensor=false®ion=br"
|
9
|
+
signed_uri = subject.sign(uri, 'a', 'b', 'c').to_s
|
10
|
+
expect(signed_uri).to eq("http://maps.googleapis.com/maps/api/geocode/json?address=1845,AV+IMPERATRIZ+LEOPOLDINA,05305-007&sensor=false®ion=br&client=a&channel=c&signature=imI9JSO4iz8RGVeJx_EAmccAnPM=")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_maps_api-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felipe Zavan
|
@@ -77,9 +77,11 @@ files:
|
|
77
77
|
- lib/google_maps_api/core/distance.rb
|
78
78
|
- lib/google_maps_api/core/duration.rb
|
79
79
|
- lib/google_maps_api/core/metric.rb
|
80
|
+
- lib/google_maps_api/core/uri_signer.rb
|
80
81
|
- lib/google_maps_api/core/version.rb
|
81
82
|
- spec/google_maps_api/core/coordinate_spec.rb
|
82
83
|
- spec/google_maps_api/core/metric_spec.rb
|
84
|
+
- spec/google_maps_api/core/uri_signer_spec.rb
|
83
85
|
- spec/spec_helper.rb
|
84
86
|
homepage: https://github.com/zavan/google_maps_api-core
|
85
87
|
licenses:
|
@@ -108,4 +110,5 @@ summary: Common stuff used by the google_maps_api gem components.
|
|
108
110
|
test_files:
|
109
111
|
- spec/google_maps_api/core/coordinate_spec.rb
|
110
112
|
- spec/google_maps_api/core/metric_spec.rb
|
113
|
+
- spec/google_maps_api/core/uri_signer_spec.rb
|
111
114
|
- spec/spec_helper.rb
|