googlestaticmap 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.txt +3 -0
- data/lib/googlestaticmap.rb +5 -24
- data/lib/googlestaticmap_helper.rb +20 -0
- data/test/tc_google_static_map.rb +2 -2
- data/test/tc_helper.rb +10 -1
- metadata +38 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71d11263c1112a4dcbf313e0fb3e133bb4602090
|
4
|
+
data.tar.gz: 5e5e853c9c7d71c6bb2f59ae09f180f9b3aa9b03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b84b6bc8dd68641b0b6c96eed2e377559e1a61c2401465653325a77a22fb1bba8c9268741481ec66b7b05f8095913797d8679995c5bb6f04688980083fb3dbc1
|
7
|
+
data.tar.gz: f6dd673216d577fbc3b2f174355666259fd8e79c53634b98c0ef8a1ddc049a13f47d01baca66fc0fb28addc183cb9383d37877dc5a5f515e648d51a29be4510b
|
data/History.txt
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
== 1.2.1 / 2014-03-03
|
2
|
+
* Fixed bug in the signature generation for business customers from 1.2.0
|
3
|
+
|
1
4
|
== 1.2.0 / 2014-03-03
|
2
5
|
* Added support for setting an API key for monitoring, and a client ID/private key for business customers (thanks forrest!)
|
3
6
|
* Changed to use maps.googleapis.com instead of maps.google.com (thanks nathany!)
|
data/lib/googlestaticmap.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
# info, etc.
|
3
3
|
|
4
4
|
require 'cgi'
|
5
|
-
require 'base64'
|
6
|
-
require 'openssl'
|
7
5
|
require 'net/http'
|
8
6
|
require 'net/https' if RUBY_VERSION < "1.9"
|
9
7
|
require File.dirname(__FILE__) + '/googlestaticmap_helper'
|
@@ -114,9 +112,10 @@ class GoogleStaticMap
|
|
114
112
|
attrs << ["center", @center.to_s] if !@center.nil?
|
115
113
|
attrs << ["key", @api_key] if !@api_key.nil?
|
116
114
|
attrs << ["client", @client_id] if @api_key.nil? && !@client_id.nil? && !@private_key.nil?
|
117
|
-
path << attrs.collect {|attr| "#{attr[0]}=#{attr[1]}"}.join("&")
|
115
|
+
path << attrs.sort_by {|k,v| k}.collect {|attr| "#{attr[0]}=#{attr[1]}"}.join("&")
|
118
116
|
if @api_key.nil? && !@client_id.nil? && !@private_key.nil?
|
119
|
-
|
117
|
+
signature = GoogleStaticMapHelpers.sign(path, @private_key)
|
118
|
+
path << "&signature=" << signature
|
120
119
|
end
|
121
120
|
base + path
|
122
121
|
end
|
@@ -157,24 +156,6 @@ class GoogleStaticMap
|
|
157
156
|
end
|
158
157
|
end
|
159
158
|
|
160
|
-
private
|
161
|
-
|
162
|
-
# signing code is grabbed from https://github.com/alexreisner/geocoder
|
163
|
-
def sign(path)
|
164
|
-
raw_private_key = url_safe_base64_decode(@private_key)
|
165
|
-
digest = OpenSSL::Digest.new('sha1')
|
166
|
-
raw_signature = OpenSSL::HMAC.digest(digest, raw_private_key, path)
|
167
|
-
url_safe_base64_encode(raw_signature)
|
168
|
-
end
|
169
|
-
|
170
|
-
def url_safe_base64_decode(base64_string)
|
171
|
-
Base64.decode64(base64_string.tr('-_', '+/'))
|
172
|
-
end
|
173
|
-
|
174
|
-
def url_safe_base64_encode(raw)
|
175
|
-
Base64.encode64(raw).tr('+/', '-_').strip
|
176
|
-
end
|
177
|
-
|
178
159
|
end
|
179
160
|
|
180
161
|
# Container class for a location on the map. Set either a latitude and
|
@@ -239,7 +220,7 @@ class MapMarker
|
|
239
220
|
def to_s
|
240
221
|
raise Exception.new("Need a location for the marker") unless @location && @location.is_a?(MapLocation)
|
241
222
|
attrs = GoogleStaticMapHelpers.safe_instance_variables(self, ["location"])
|
242
|
-
s = attrs.to_a.collect do |k|
|
223
|
+
s = attrs.to_a.sort_by {|x| x[0]}.collect do |k|
|
243
224
|
# If the icon URL is URL encoded, it won't work
|
244
225
|
val = (k[0] == "icon" ? k[1] : CGI.escape(k[1].to_s))
|
245
226
|
"#{k[0]}:#{val}"
|
@@ -273,7 +254,7 @@ class MapPath
|
|
273
254
|
def to_s
|
274
255
|
raise Exception.new("Need more than one point for the path") unless @points && @points.length > 1
|
275
256
|
attrs = GoogleStaticMapHelpers.safe_instance_variables(self, ["points"])
|
276
|
-
s = attrs.to_a.collect {|k| "#{k[0]}:#{CGI.escape(k[1].to_s)}"}.join(MAP_SEPARATOR)
|
257
|
+
s = attrs.to_a.sort_by {|x| x[0]}.collect {|k| "#{k[0]}:#{CGI.escape(k[1].to_s)}"}.join(MAP_SEPARATOR)
|
277
258
|
s << MAP_SEPARATOR << @points.join(MAP_SEPARATOR)
|
278
259
|
end
|
279
260
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
|
1
4
|
# Helper methods used in this code
|
2
5
|
module GoogleStaticMapHelpers #:nodoc: all
|
3
6
|
# Returns a hash of instance variables for the passed in Object, where the
|
@@ -24,4 +27,21 @@ module GoogleStaticMapHelpers #:nodoc: all
|
|
24
27
|
end
|
25
28
|
ivs
|
26
29
|
end
|
30
|
+
|
31
|
+
# signing code is grabbed from https://github.com/alexreisner/geocoder
|
32
|
+
def self.sign(path, key)
|
33
|
+
raw_private_key = self.url_safe_base64_decode(key)
|
34
|
+
digest = OpenSSL::Digest.new('sha1')
|
35
|
+
raw_signature = OpenSSL::HMAC.digest(digest, raw_private_key, path)
|
36
|
+
self.url_safe_base64_encode(raw_signature)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.url_safe_base64_decode(base64_string)
|
40
|
+
Base64.decode64(base64_string.tr('-_', '+/'))
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.url_safe_base64_encode(raw)
|
44
|
+
Base64.encode64(raw).tr('+/', '-_').strip
|
45
|
+
end
|
46
|
+
|
27
47
|
end
|
@@ -116,11 +116,11 @@ class GoogleStaticMapTest < Test::Unit::TestCase #:nodoc: all
|
|
116
116
|
def test_url_for_business
|
117
117
|
g = default_map
|
118
118
|
g.client_id = "asdfclientid"
|
119
|
-
g.private_key = "
|
119
|
+
g.private_key = "vNIXE0xscrmjlyV-12Nj_BvUPaw="
|
120
120
|
u = nil
|
121
121
|
assert_nothing_raised { u = g.url }
|
122
122
|
assert_equal 9, u.split("&").length, u
|
123
|
-
assert u.include?("signature="), u
|
123
|
+
assert u.include?("signature=qB3i5UMtI7tHPz-cy_BGrl-5i80="), u
|
124
124
|
assert u.include?("client=asdfclientid"), u
|
125
125
|
assert !u.include?("key="), u
|
126
126
|
end
|
data/test/tc_helper.rb
CHANGED
@@ -50,6 +50,15 @@ class GoogleStaticMapHelperTest < Test::Unit::TestCase #:nodoc: all
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
def test_signature
|
54
|
+
# This comes from the google example at
|
55
|
+
# https://developers.google.com/maps/documentation/business/webservices/auth
|
56
|
+
private_key = "vNIXE0xscrmjlyV-12Nj_BvUPaw="
|
57
|
+
url = "/maps/api/geocode/json?address=New+York&sensor=false&client=clientID"
|
58
|
+
sig = GoogleStaticMapHelpers.sign(url, private_key)
|
59
|
+
assert_equal sig, "KrU1TzVQM7Ur0i8i7K3huiw3MsA="
|
60
|
+
end
|
61
|
+
|
53
62
|
private
|
54
63
|
def ivs_no_at
|
55
64
|
ivs = {}
|
@@ -58,4 +67,4 @@ class GoogleStaticMapHelperTest < Test::Unit::TestCase #:nodoc: all
|
|
58
67
|
end
|
59
68
|
ivs
|
60
69
|
end
|
61
|
-
end
|
70
|
+
end
|
metadata
CHANGED
@@ -1,19 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: googlestaticmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brent Sowers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 10.1.1
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 10.1.1
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mocha
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 1.0.0
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
description: Easily retrieve single PNG, GIF, or JPG map images from Google with your own custom markers and paths using the Static Maps API service with this gem. Simply set the attributes you want for your map and GoogleStaticMap will take care of getting the map for you, or giving your the URL to retrieve the map.
|
17
42
|
email: brent@coordinatecommons.com
|
18
43
|
executables: []
|
19
44
|
extensions: []
|
@@ -34,24 +59,24 @@ homepage: http://www.coordinatecommons.com/googlestaticmap/
|
|
34
59
|
licenses:
|
35
60
|
- MIT
|
36
61
|
metadata: {}
|
37
|
-
post_install_message:
|
62
|
+
post_install_message:
|
38
63
|
rdoc_options: []
|
39
64
|
require_paths:
|
40
65
|
- lib
|
41
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
67
|
requirements:
|
43
|
-
- -
|
68
|
+
- - '>='
|
44
69
|
- !ruby/object:Gem::Version
|
45
70
|
version: '0'
|
46
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
72
|
requirements:
|
48
|
-
- -
|
73
|
+
- - '>='
|
49
74
|
- !ruby/object:Gem::Version
|
50
75
|
version: '0'
|
51
76
|
requirements: []
|
52
|
-
rubyforge_project:
|
77
|
+
rubyforge_project:
|
53
78
|
rubygems_version: 2.2.2
|
54
|
-
signing_key:
|
79
|
+
signing_key:
|
55
80
|
specification_version: 4
|
56
81
|
summary: Class for retrieving maps from the Google Maps Static API service
|
57
82
|
test_files:
|