sixarm_ruby_google_maps_api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Rakefile +12 -0
- data/lib/sixarm_ruby_google_maps_api.rb +6 -0
- data/lib/sixarm_ruby_google_maps_api/geocode.rb +41 -0
- data/test/sixarm_ruby_google_maps_api_test.rb +14 -0
- data/test/sixarm_ruby_google_maps_api_test/geocode_test.rb +118 -0
- metadata +230 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bef32e724ee12752fedc7403abb079d19d298e7f80f14740c9c0b3537cbc460f
|
4
|
+
data.tar.gz: 7b45fa9470180ee77fa87776660d9e80dfbd22bb03320a3fd17233fe3fba0fe6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 231b0abb28b7c2b1dd81c235ffc10cd7e9ce912a56eff2bc0ad51215e2606cd136a4ca739231a05f60bdcd5014eb7de4bb980d54012cc7eb7684ea035a6ff201
|
7
|
+
data.tar.gz: 7e09e746f76b0a7aadefae6e0931b947b97175690bca2c2dff157bf762b3c70a682b4496f1c90d93fc8d75a1067bcf8f4965477e05f7f98ac1e9066533a23512
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin rdoc
|
3
|
+
String extensions.
|
4
|
+
=end
|
5
|
+
|
6
|
+
require 'net/http'
|
7
|
+
require 'uri'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
module Google; module Maps; module API; module Geocode
|
11
|
+
|
12
|
+
def self.address_to_lat_lng(google_maps_api_key, address)
|
13
|
+
uri = address_to_uri(google_maps_api_key, address)
|
14
|
+
json = get_uri_to_json(uri)
|
15
|
+
result = json["results"].first
|
16
|
+
return result_to_lat_lng(result)
|
17
|
+
end
|
18
|
+
|
19
|
+
## Helpers
|
20
|
+
|
21
|
+
def self.address_to_uri(google_maps_api_key, address)
|
22
|
+
return URI.parse("https://maps.googleapis.com/maps/api/geocode/json?key=#{URI.escape(google_maps_api_key)}&address=#{URI.escape(address)}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.result_to_lat_lng(result)
|
26
|
+
return [
|
27
|
+
result["geometry"]["location"]["lat"],
|
28
|
+
result["geometry"]["location"]["lng"],
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_uri(uri)
|
33
|
+
Net::HTTP.get(uri)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_uri_to_json(uri)
|
37
|
+
JSON.parse(get_uri(uri))
|
38
|
+
end
|
39
|
+
|
40
|
+
end; end; end; end
|
41
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "minitest/autorun"
|
3
|
+
#require "minitest/benchmark" if ENV["BENCH"]
|
4
|
+
require "sixarm_ruby_minitest_extensions"
|
5
|
+
require "faker"
|
6
|
+
require "coveralls"
|
7
|
+
require "simplecov"
|
8
|
+
Coveralls.wear!
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
10
|
+
SimpleCov::Formatter::HTMLFormatter,
|
11
|
+
Coveralls::SimpleCov::Formatter
|
12
|
+
]
|
13
|
+
SimpleCov.start
|
14
|
+
require "sixarm_ruby_google_maps_api"
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "sixarm_ruby_google_maps_api_test"
|
3
|
+
|
4
|
+
describe Google::Maps::API::Geocode do
|
5
|
+
|
6
|
+
## Fake info
|
7
|
+
let(:google_maps_api_key){ Faker::Lorem.characters(10) }
|
8
|
+
let(:street_address){ Faker::Address.street_address }
|
9
|
+
let(:locality){ Faker::Address.city }
|
10
|
+
let(:region){ Faker::Address.state_abbr }
|
11
|
+
let(:postal_code){ Faker::Address.postcode }
|
12
|
+
let(:address){ "#{street_address} #{locality} #{region} #{postal_code}" }
|
13
|
+
let(:latitude){ Float(latitude_text) }
|
14
|
+
let(:latitude_text){ Faker::Address.latitude }
|
15
|
+
let(:longitude){ Float(longitude_text) }
|
16
|
+
let(:longitude_text){ Faker::Address.longitude }
|
17
|
+
|
18
|
+
## Real info
|
19
|
+
let(:real_google_maps_api_key){ ENV["GOOGLE_MAPS_API_KEY"] or raise "This test needs ENV[\"GOOGLE_MAPS_API_KEY\"]" }
|
20
|
+
let(:real_address){ "1 Main Street, San Francisco, CA, 94111, US" }
|
21
|
+
let(:real_latitude){ Float(real_latitude_text) }
|
22
|
+
let(:real_latitude_text){ "37.7931108" }
|
23
|
+
let(:real_longitude){ Float(real_longitude_text) }
|
24
|
+
let(:real_longitude_text){ "-122.3964898" }
|
25
|
+
let(:real_uri){ URI.parse(real_uri_text) }
|
26
|
+
let(:real_uri_text){ "https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyCGwgBSQTEsN_F3FSIV7hq9WwEpvR1a5X0&address=1%20Main%20Street%2C%20SF%20CA%20941111" }
|
27
|
+
|
28
|
+
|
29
|
+
describe ".address_to_lat_lng" do
|
30
|
+
|
31
|
+
before do
|
32
|
+
@google_maps_api_key = real_google_maps_api_key
|
33
|
+
@address = real_address
|
34
|
+
@latitude = real_latitude
|
35
|
+
@longitude = real_longitude
|
36
|
+
end
|
37
|
+
|
38
|
+
specify "fetch" do
|
39
|
+
lat, lng = Google::Maps::API::Geocode::address_to_lat_lng(@google_maps_api_key, @address)
|
40
|
+
expect(lat).must_be_close_to @latitude, 0.001
|
41
|
+
expect(lng).must_be_close_to @longitude, 0.001
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
describe ".address_to_uri" do
|
48
|
+
|
49
|
+
before do
|
50
|
+
@google_maps_api_key = google_maps_api_key
|
51
|
+
@address = address
|
52
|
+
end
|
53
|
+
|
54
|
+
specify "parse" do
|
55
|
+
uri = Google::Maps::API::Geocode::address_to_uri(@google_maps_api_key, @address)
|
56
|
+
expect(uri.scheme).must_equal "https", "scheme"
|
57
|
+
expect(uri.host).must_equal "maps.googleapis.com", "host"
|
58
|
+
expect(uri.path).must_equal "/maps/api/geocode/json", "path"
|
59
|
+
expect(uri.query).must_exist "query"
|
60
|
+
query_hash = CGI.parse(uri.query)
|
61
|
+
expect(query_hash).must_exist "q"
|
62
|
+
expect(query_hash).must_equal({"key"=>[@google_maps_api_key], "address"=>[@address]}, "q")
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
describe ".result_to_lat_lng" do
|
69
|
+
|
70
|
+
before do
|
71
|
+
@latitude = latitude
|
72
|
+
@longitude = longitude
|
73
|
+
@result = {
|
74
|
+
"geometry" => {
|
75
|
+
"location" => {
|
76
|
+
"lat" => @latitude,
|
77
|
+
"lng" => @longitude,
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
specify "extract" do
|
84
|
+
lat, lng = Google::Maps::API::Geocode::result_to_lat_lng(@result)
|
85
|
+
expect(lat).must_equal @latitude
|
86
|
+
expect(lng).must_equal @longitude
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
describe ".get_uri" do
|
93
|
+
|
94
|
+
before do
|
95
|
+
@uri = real_uri
|
96
|
+
end
|
97
|
+
|
98
|
+
specify "request" do
|
99
|
+
response = Google::Maps::API::Geocode::get_uri(@uri)
|
100
|
+
expect(response).must_exist "response"
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
describe ".get_uri_to_json" do
|
106
|
+
|
107
|
+
before do
|
108
|
+
@uri = real_uri
|
109
|
+
end
|
110
|
+
|
111
|
+
specify "request" do
|
112
|
+
response = Google::Maps::API::Geocode::get_uri(@uri)
|
113
|
+
json = JSON.parse(response)
|
114
|
+
expect(json).must_exist "json"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
metadata
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sixarm_ruby_google_maps_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SixArm
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIFPDCCAyQCCQDx7Y5LWGuPPzANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJV
|
14
|
+
UzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzEP
|
15
|
+
MA0GA1UECgwGU2l4QXJtMRMwEQYDVQQDDApzaXhhcm0uY29tMB4XDTE4MDExMzIy
|
16
|
+
NDYyM1oXDTIwMTAwOTIyNDYyM1owYDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNh
|
17
|
+
bGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDzANBgNVBAoMBlNpeEFy
|
18
|
+
bTETMBEGA1UEAwwKc2l4YXJtLmNvbTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCC
|
19
|
+
AgoCggIBAMMPPjYWd77gRmOEkMb+1H9+ckIHlA325OkES2g5Y58hIDzZYTGIxjSP
|
20
|
+
3N7uYx5qR8qZvuO4F1McGJ/NES2robjQcV/aIRXD+5RjbokyYYGJlJujm5c/wZme
|
21
|
+
Us7pOzQxc8QcogsdInwQ6O9hTQ4zBdOFZt6YBp5y9ycXVIApBnxJHBU3W6Ir1hl6
|
22
|
+
3v6RYBgHFd3g0dCwuBoaYZE5MU/4q91vc48XhioqXdJlaDyw1ZMyvE+loi+8quVg
|
23
|
+
bpUadC/QUZukABYCu6rS6fiRLffmMy/Db7d8b1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CBDChCcEKG0Ma4IvHUgjv47f5iYpkXuhifiK4xMG/s+T5Euw3Wg9J
|
39
|
+
tzpk/VnZXj7Ek/earx+N/Z+Wtnl2xENm5IF8SFPeI1HFa9NH47pqtxF1YKpNIEVc
|
40
|
+
2xa2BNHSePe7tys/2hbmZuyMu8X5ERmovsabSXB3a+YwtJh5c2jhA21wF7986s0q
|
41
|
+
-----END CERTIFICATE-----
|
42
|
+
date: 2018-01-13 00:00:00.000000000 Z
|
43
|
+
dependencies:
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: json
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.1.0
|
51
|
+
- - "<"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.1.0
|
61
|
+
- - "<"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3'
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: minitest
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 5.7.0
|
71
|
+
- - "<"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '6'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 5.7.0
|
81
|
+
- - "<"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '6'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: sixarm_ruby_minitest_extensions
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.0.8
|
91
|
+
- - "<"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2'
|
94
|
+
type: :development
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.0.8
|
101
|
+
- - "<"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2'
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: rake
|
106
|
+
requirement: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 10.4.2
|
111
|
+
- - "<"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '11'
|
114
|
+
type: :development
|
115
|
+
prerelease: false
|
116
|
+
version_requirements: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 10.4.2
|
121
|
+
- - "<"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '11'
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: simplecov
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.10.0
|
131
|
+
- - "<"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '2'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 0.10.0
|
141
|
+
- - "<"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '2'
|
144
|
+
- !ruby/object:Gem::Dependency
|
145
|
+
name: coveralls
|
146
|
+
requirement: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 0.8.2
|
151
|
+
- - "<"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '2'
|
154
|
+
type: :development
|
155
|
+
prerelease: false
|
156
|
+
version_requirements: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: 0.8.2
|
161
|
+
- - "<"
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '2'
|
164
|
+
- !ruby/object:Gem::Dependency
|
165
|
+
name: faker
|
166
|
+
requirement: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: 1.8.7
|
171
|
+
- - "<"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '2'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 1.8.7
|
181
|
+
- - "<"
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '2'
|
184
|
+
description: Use the Google Maps API to geocode an address to a latitude and longitude
|
185
|
+
email: sixarm@sixarm.com
|
186
|
+
executables: []
|
187
|
+
extensions: []
|
188
|
+
extra_rdoc_files: []
|
189
|
+
files:
|
190
|
+
- Rakefile
|
191
|
+
- lib/sixarm_ruby_google_maps_api.rb
|
192
|
+
- lib/sixarm_ruby_google_maps_api/geocode.rb
|
193
|
+
- test/sixarm_ruby_google_maps_api_test.rb
|
194
|
+
- test/sixarm_ruby_google_maps_api_test/geocode_test.rb
|
195
|
+
homepage: http://sixarm.com/
|
196
|
+
licenses:
|
197
|
+
- Apache-2.0
|
198
|
+
- Artistic-2.0
|
199
|
+
- BSD-3-Clause
|
200
|
+
- CC-BY-NC-SA-4.0
|
201
|
+
- AGPL-3.0
|
202
|
+
- GPL-3.0
|
203
|
+
- LGPL-3.0
|
204
|
+
- MIT
|
205
|
+
- MPL-2.0
|
206
|
+
- Ruby
|
207
|
+
metadata: {}
|
208
|
+
post_install_message:
|
209
|
+
rdoc_options: []
|
210
|
+
require_paths:
|
211
|
+
- lib
|
212
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - ">="
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
217
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
requirements: []
|
223
|
+
rubyforge_project:
|
224
|
+
rubygems_version: 2.7.3
|
225
|
+
signing_key:
|
226
|
+
specification_version: 4
|
227
|
+
summary: SixArm.com → Ruby → Google Maps API geocode
|
228
|
+
test_files:
|
229
|
+
- test/sixarm_ruby_google_maps_api_test.rb
|
230
|
+
- test/sixarm_ruby_google_maps_api_test/geocode_test.rb
|
metadata.gz.sig
ADDED
Binary file
|