geocoder2 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.travis.yml +27 -0
- data/CHANGELOG.md +329 -0
- data/LICENSE +20 -0
- data/README.md +796 -0
- data/Rakefile +25 -0
- data/bin/geocode2 +5 -0
- data/examples/autoexpire_cache_dalli.rb +62 -0
- data/examples/autoexpire_cache_redis.rb +28 -0
- data/examples/cache_bypass.rb +48 -0
- data/gemfiles/Gemfile.mongoid-2.4.x +15 -0
- data/json?address=26+leonard+street%2C+Belmont&key=AIzaSyDoltU6YL8XeIQrSLFGk6ZfpKaWkPukwYQ&language=en +68 -0
- data/lib/generators/geocoder2/config/config_generator.rb +14 -0
- data/lib/generators/geocoder2/config/templates/initializer.rb +21 -0
- data/lib/geocoder2/cache.rb +89 -0
- data/lib/geocoder2/calculations.rb +389 -0
- data/lib/geocoder2/cli.rb +121 -0
- data/lib/geocoder2/configuration.rb +130 -0
- data/lib/geocoder2/configuration_hash.rb +11 -0
- data/lib/geocoder2/exceptions.rb +21 -0
- data/lib/geocoder2/lookup.rb +86 -0
- data/lib/geocoder2/lookups/baidu.rb +54 -0
- data/lib/geocoder2/lookups/base.rb +266 -0
- data/lib/geocoder2/lookups/bing.rb +47 -0
- data/lib/geocoder2/lookups/dstk.rb +20 -0
- data/lib/geocoder2/lookups/esri.rb +48 -0
- data/lib/geocoder2/lookups/freegeoip.rb +43 -0
- data/lib/geocoder2/lookups/geocoder_ca.rb +54 -0
- data/lib/geocoder2/lookups/geocoder_us.rb +39 -0
- data/lib/geocoder2/lookups/google.rb +69 -0
- data/lib/geocoder2/lookups/google_premier.rb +47 -0
- data/lib/geocoder2/lookups/mapquest.rb +59 -0
- data/lib/geocoder2/lookups/maxmind.rb +88 -0
- data/lib/geocoder2/lookups/nominatim.rb +44 -0
- data/lib/geocoder2/lookups/ovi.rb +62 -0
- data/lib/geocoder2/lookups/test.rb +44 -0
- data/lib/geocoder2/lookups/yahoo.rb +86 -0
- data/lib/geocoder2/lookups/yandex.rb +54 -0
- data/lib/geocoder2/models/active_record.rb +46 -0
- data/lib/geocoder2/models/base.rb +42 -0
- data/lib/geocoder2/models/mongo_base.rb +60 -0
- data/lib/geocoder2/models/mongo_mapper.rb +26 -0
- data/lib/geocoder2/models/mongoid.rb +32 -0
- data/lib/geocoder2/query.rb +107 -0
- data/lib/geocoder2/railtie.rb +26 -0
- data/lib/geocoder2/request.rb +23 -0
- data/lib/geocoder2/results/baidu.rb +79 -0
- data/lib/geocoder2/results/base.rb +67 -0
- data/lib/geocoder2/results/bing.rb +48 -0
- data/lib/geocoder2/results/dstk.rb +6 -0
- data/lib/geocoder2/results/esri.rb +51 -0
- data/lib/geocoder2/results/freegeoip.rb +45 -0
- data/lib/geocoder2/results/geocoder_ca.rb +60 -0
- data/lib/geocoder2/results/geocoder_us.rb +39 -0
- data/lib/geocoder2/results/google.rb +124 -0
- data/lib/geocoder2/results/google_premier.rb +6 -0
- data/lib/geocoder2/results/mapquest.rb +51 -0
- data/lib/geocoder2/results/maxmind.rb +135 -0
- data/lib/geocoder2/results/nominatim.rb +94 -0
- data/lib/geocoder2/results/ovi.rb +62 -0
- data/lib/geocoder2/results/test.rb +16 -0
- data/lib/geocoder2/results/yahoo.rb +55 -0
- data/lib/geocoder2/results/yandex.rb +80 -0
- data/lib/geocoder2/sql.rb +106 -0
- data/lib/geocoder2/stores/active_record.rb +272 -0
- data/lib/geocoder2/stores/base.rb +120 -0
- data/lib/geocoder2/stores/mongo_base.rb +89 -0
- data/lib/geocoder2/stores/mongo_mapper.rb +13 -0
- data/lib/geocoder2/stores/mongoid.rb +13 -0
- data/lib/geocoder2/version.rb +3 -0
- data/lib/geocoder2.rb +55 -0
- data/lib/hash_recursive_merge.rb +74 -0
- data/lib/oauth_util.rb +112 -0
- data/lib/tasks/geocoder2.rake +27 -0
- data/test/active_record_test.rb +15 -0
- data/test/cache_test.rb +35 -0
- data/test/calculations_test.rb +211 -0
- data/test/configuration_test.rb +78 -0
- data/test/custom_block_test.rb +32 -0
- data/test/error_handling_test.rb +43 -0
- data/test/fixtures/baidu_invalid_key +1 -0
- data/test/fixtures/baidu_no_results +1 -0
- data/test/fixtures/baidu_reverse +1 -0
- data/test/fixtures/baidu_shanghai_pearl_tower +12 -0
- data/test/fixtures/bing_invalid_key +1 -0
- data/test/fixtures/bing_madison_square_garden +40 -0
- data/test/fixtures/bing_no_results +16 -0
- data/test/fixtures/bing_reverse +42 -0
- data/test/fixtures/esri_madison_square_garden +59 -0
- data/test/fixtures/esri_no_results +8 -0
- data/test/fixtures/esri_reverse +21 -0
- data/test/fixtures/freegeoip_74_200_247_59 +12 -0
- data/test/fixtures/freegeoip_no_results +1 -0
- data/test/fixtures/geocoder_ca_madison_square_garden +1 -0
- data/test/fixtures/geocoder_ca_no_results +1 -0
- data/test/fixtures/geocoder_ca_reverse +34 -0
- data/test/fixtures/geocoder_us_madison_square_garden +1 -0
- data/test/fixtures/geocoder_us_no_results +1 -0
- data/test/fixtures/google_garbage +456 -0
- data/test/fixtures/google_madison_square_garden +57 -0
- data/test/fixtures/google_no_city_data +44 -0
- data/test/fixtures/google_no_locality +51 -0
- data/test/fixtures/google_no_results +4 -0
- data/test/fixtures/google_over_limit +4 -0
- data/test/fixtures/mapquest_error +16 -0
- data/test/fixtures/mapquest_invalid_api_key +16 -0
- data/test/fixtures/mapquest_invalid_request +16 -0
- data/test/fixtures/mapquest_madison_square_garden +52 -0
- data/test/fixtures/mapquest_no_results +16 -0
- data/test/fixtures/maxmind_24_24_24_21 +1 -0
- data/test/fixtures/maxmind_24_24_24_22 +1 -0
- data/test/fixtures/maxmind_24_24_24_23 +1 -0
- data/test/fixtures/maxmind_24_24_24_24 +1 -0
- data/test/fixtures/maxmind_74_200_247_59 +1 -0
- data/test/fixtures/maxmind_invalid_key +1 -0
- data/test/fixtures/maxmind_no_results +1 -0
- data/test/fixtures/nominatim_madison_square_garden +150 -0
- data/test/fixtures/nominatim_no_results +1 -0
- data/test/fixtures/ovi_madison_square_garden +72 -0
- data/test/fixtures/ovi_no_results +8 -0
- data/test/fixtures/yahoo_error +1 -0
- data/test/fixtures/yahoo_invalid_key +2 -0
- data/test/fixtures/yahoo_madison_square_garden +52 -0
- data/test/fixtures/yahoo_no_results +10 -0
- data/test/fixtures/yahoo_over_limit +2 -0
- data/test/fixtures/yandex_invalid_key +1 -0
- data/test/fixtures/yandex_kremlin +48 -0
- data/test/fixtures/yandex_no_city_and_town +112 -0
- data/test/fixtures/yandex_no_results +16 -0
- data/test/geocoder_test.rb +59 -0
- data/test/https_test.rb +16 -0
- data/test/integration/smoke_test.rb +26 -0
- data/test/lookup_test.rb +117 -0
- data/test/method_aliases_test.rb +25 -0
- data/test/mongoid_test.rb +46 -0
- data/test/mongoid_test_helper.rb +43 -0
- data/test/near_test.rb +61 -0
- data/test/oauth_util_test.rb +30 -0
- data/test/proxy_test.rb +36 -0
- data/test/query_test.rb +52 -0
- data/test/request_test.rb +29 -0
- data/test/result_test.rb +42 -0
- data/test/services_test.rb +393 -0
- data/test/test_helper.rb +289 -0
- data/test/test_mode_test.rb +59 -0
- metadata +213 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestModeTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@_original_lookup = Geocoder2.config.lookup
|
7
|
+
Geocoder2.configure(:lookup => :test)
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
Geocoder2::Lookup::Test.reset
|
12
|
+
Geocoder2.configure(:lookup => @_original_lookup)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_search_with_known_stub
|
16
|
+
Geocoder2::Lookup::Test.add_stub("New York, NY", [mock_attributes])
|
17
|
+
|
18
|
+
results = Geocoder2.search("New York, NY")
|
19
|
+
result = results.first
|
20
|
+
|
21
|
+
assert_equal 1, results.size
|
22
|
+
mock_attributes.keys.each do |attr|
|
23
|
+
assert_equal mock_attributes[attr], result.send(attr)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_search_with_unknown_stub_without_default
|
28
|
+
assert_raise ArgumentError do
|
29
|
+
Geocoder2.search("New York, NY")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_search_with_unknown_stub_with_default
|
34
|
+
Geocoder2::Lookup::Test.set_default_stub([mock_attributes])
|
35
|
+
|
36
|
+
results = Geocoder2.search("Atlantis, OC")
|
37
|
+
result = results.first
|
38
|
+
|
39
|
+
assert_equal 1, results.size
|
40
|
+
mock_attributes.keys.each do |attr|
|
41
|
+
assert_equal mock_attributes[attr], result.send(attr)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def mock_attributes
|
47
|
+
coordinates = [40.7143528, -74.0059731]
|
48
|
+
@mock_attributes ||= {
|
49
|
+
'coordinates' => coordinates,
|
50
|
+
'latitude' => coordinates[0],
|
51
|
+
'longitude' => coordinates[1],
|
52
|
+
'address' => 'New York, NY, USA',
|
53
|
+
'state' => 'New York',
|
54
|
+
'state_code' => 'NY',
|
55
|
+
'country' => 'United States',
|
56
|
+
'country_code' => 'US',
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geocoder2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alex Reisner
|
14
|
+
- Ian Heggie
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2018-10-03 00:00:00 +10:00
|
20
|
+
default_executable:
|
21
|
+
dependencies: []
|
22
|
+
|
23
|
+
description: Provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), distance queries for ActiveRecord and Mongoid, result caching, and more. Designed for Rails but works with Sinatra and other Rack frameworks too. (clone of Geocode for older rails/ruby versions)
|
24
|
+
email:
|
25
|
+
- ian@heggie.biz
|
26
|
+
executables:
|
27
|
+
- geocode2
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- .travis.yml
|
35
|
+
- CHANGELOG.md
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- bin/geocode2
|
40
|
+
- examples/autoexpire_cache_dalli.rb
|
41
|
+
- examples/autoexpire_cache_redis.rb
|
42
|
+
- examples/cache_bypass.rb
|
43
|
+
- gemfiles/Gemfile.mongoid-2.4.x
|
44
|
+
- json?address=26+leonard+street%2C+Belmont&key=AIzaSyDoltU6YL8XeIQrSLFGk6ZfpKaWkPukwYQ&language=en
|
45
|
+
- lib/generators/geocoder2/config/config_generator.rb
|
46
|
+
- lib/generators/geocoder2/config/templates/initializer.rb
|
47
|
+
- lib/geocoder2.rb
|
48
|
+
- lib/geocoder2/cache.rb
|
49
|
+
- lib/geocoder2/calculations.rb
|
50
|
+
- lib/geocoder2/cli.rb
|
51
|
+
- lib/geocoder2/configuration.rb
|
52
|
+
- lib/geocoder2/configuration_hash.rb
|
53
|
+
- lib/geocoder2/exceptions.rb
|
54
|
+
- lib/geocoder2/lookup.rb
|
55
|
+
- lib/geocoder2/lookups/baidu.rb
|
56
|
+
- lib/geocoder2/lookups/base.rb
|
57
|
+
- lib/geocoder2/lookups/bing.rb
|
58
|
+
- lib/geocoder2/lookups/dstk.rb
|
59
|
+
- lib/geocoder2/lookups/esri.rb
|
60
|
+
- lib/geocoder2/lookups/freegeoip.rb
|
61
|
+
- lib/geocoder2/lookups/geocoder_ca.rb
|
62
|
+
- lib/geocoder2/lookups/geocoder_us.rb
|
63
|
+
- lib/geocoder2/lookups/google.rb
|
64
|
+
- lib/geocoder2/lookups/google_premier.rb
|
65
|
+
- lib/geocoder2/lookups/mapquest.rb
|
66
|
+
- lib/geocoder2/lookups/maxmind.rb
|
67
|
+
- lib/geocoder2/lookups/nominatim.rb
|
68
|
+
- lib/geocoder2/lookups/ovi.rb
|
69
|
+
- lib/geocoder2/lookups/test.rb
|
70
|
+
- lib/geocoder2/lookups/yahoo.rb
|
71
|
+
- lib/geocoder2/lookups/yandex.rb
|
72
|
+
- lib/geocoder2/models/active_record.rb
|
73
|
+
- lib/geocoder2/models/base.rb
|
74
|
+
- lib/geocoder2/models/mongo_base.rb
|
75
|
+
- lib/geocoder2/models/mongo_mapper.rb
|
76
|
+
- lib/geocoder2/models/mongoid.rb
|
77
|
+
- lib/geocoder2/query.rb
|
78
|
+
- lib/geocoder2/railtie.rb
|
79
|
+
- lib/geocoder2/request.rb
|
80
|
+
- lib/geocoder2/results/baidu.rb
|
81
|
+
- lib/geocoder2/results/base.rb
|
82
|
+
- lib/geocoder2/results/bing.rb
|
83
|
+
- lib/geocoder2/results/dstk.rb
|
84
|
+
- lib/geocoder2/results/esri.rb
|
85
|
+
- lib/geocoder2/results/freegeoip.rb
|
86
|
+
- lib/geocoder2/results/geocoder_ca.rb
|
87
|
+
- lib/geocoder2/results/geocoder_us.rb
|
88
|
+
- lib/geocoder2/results/google.rb
|
89
|
+
- lib/geocoder2/results/google_premier.rb
|
90
|
+
- lib/geocoder2/results/mapquest.rb
|
91
|
+
- lib/geocoder2/results/maxmind.rb
|
92
|
+
- lib/geocoder2/results/nominatim.rb
|
93
|
+
- lib/geocoder2/results/ovi.rb
|
94
|
+
- lib/geocoder2/results/test.rb
|
95
|
+
- lib/geocoder2/results/yahoo.rb
|
96
|
+
- lib/geocoder2/results/yandex.rb
|
97
|
+
- lib/geocoder2/sql.rb
|
98
|
+
- lib/geocoder2/stores/active_record.rb
|
99
|
+
- lib/geocoder2/stores/base.rb
|
100
|
+
- lib/geocoder2/stores/mongo_base.rb
|
101
|
+
- lib/geocoder2/stores/mongo_mapper.rb
|
102
|
+
- lib/geocoder2/stores/mongoid.rb
|
103
|
+
- lib/geocoder2/version.rb
|
104
|
+
- lib/hash_recursive_merge.rb
|
105
|
+
- lib/oauth_util.rb
|
106
|
+
- lib/tasks/geocoder2.rake
|
107
|
+
- test/active_record_test.rb
|
108
|
+
- test/cache_test.rb
|
109
|
+
- test/calculations_test.rb
|
110
|
+
- test/configuration_test.rb
|
111
|
+
- test/custom_block_test.rb
|
112
|
+
- test/error_handling_test.rb
|
113
|
+
- test/fixtures/baidu_invalid_key
|
114
|
+
- test/fixtures/baidu_no_results
|
115
|
+
- test/fixtures/baidu_reverse
|
116
|
+
- test/fixtures/baidu_shanghai_pearl_tower
|
117
|
+
- test/fixtures/bing_invalid_key
|
118
|
+
- test/fixtures/bing_madison_square_garden
|
119
|
+
- test/fixtures/bing_no_results
|
120
|
+
- test/fixtures/bing_reverse
|
121
|
+
- test/fixtures/esri_madison_square_garden
|
122
|
+
- test/fixtures/esri_no_results
|
123
|
+
- test/fixtures/esri_reverse
|
124
|
+
- test/fixtures/freegeoip_74_200_247_59
|
125
|
+
- test/fixtures/freegeoip_no_results
|
126
|
+
- test/fixtures/geocoder_ca_madison_square_garden
|
127
|
+
- test/fixtures/geocoder_ca_no_results
|
128
|
+
- test/fixtures/geocoder_ca_reverse
|
129
|
+
- test/fixtures/geocoder_us_madison_square_garden
|
130
|
+
- test/fixtures/geocoder_us_no_results
|
131
|
+
- test/fixtures/google_garbage
|
132
|
+
- test/fixtures/google_madison_square_garden
|
133
|
+
- test/fixtures/google_no_city_data
|
134
|
+
- test/fixtures/google_no_locality
|
135
|
+
- test/fixtures/google_no_results
|
136
|
+
- test/fixtures/google_over_limit
|
137
|
+
- test/fixtures/mapquest_error
|
138
|
+
- test/fixtures/mapquest_invalid_api_key
|
139
|
+
- test/fixtures/mapquest_invalid_request
|
140
|
+
- test/fixtures/mapquest_madison_square_garden
|
141
|
+
- test/fixtures/mapquest_no_results
|
142
|
+
- test/fixtures/maxmind_24_24_24_21
|
143
|
+
- test/fixtures/maxmind_24_24_24_22
|
144
|
+
- test/fixtures/maxmind_24_24_24_23
|
145
|
+
- test/fixtures/maxmind_24_24_24_24
|
146
|
+
- test/fixtures/maxmind_74_200_247_59
|
147
|
+
- test/fixtures/maxmind_invalid_key
|
148
|
+
- test/fixtures/maxmind_no_results
|
149
|
+
- test/fixtures/nominatim_madison_square_garden
|
150
|
+
- test/fixtures/nominatim_no_results
|
151
|
+
- test/fixtures/ovi_madison_square_garden
|
152
|
+
- test/fixtures/ovi_no_results
|
153
|
+
- test/fixtures/yahoo_error
|
154
|
+
- test/fixtures/yahoo_invalid_key
|
155
|
+
- test/fixtures/yahoo_madison_square_garden
|
156
|
+
- test/fixtures/yahoo_no_results
|
157
|
+
- test/fixtures/yahoo_over_limit
|
158
|
+
- test/fixtures/yandex_invalid_key
|
159
|
+
- test/fixtures/yandex_kremlin
|
160
|
+
- test/fixtures/yandex_no_city_and_town
|
161
|
+
- test/fixtures/yandex_no_results
|
162
|
+
- test/geocoder_test.rb
|
163
|
+
- test/https_test.rb
|
164
|
+
- test/integration/smoke_test.rb
|
165
|
+
- test/lookup_test.rb
|
166
|
+
- test/method_aliases_test.rb
|
167
|
+
- test/mongoid_test.rb
|
168
|
+
- test/mongoid_test_helper.rb
|
169
|
+
- test/near_test.rb
|
170
|
+
- test/oauth_util_test.rb
|
171
|
+
- test/proxy_test.rb
|
172
|
+
- test/query_test.rb
|
173
|
+
- test/request_test.rb
|
174
|
+
- test/result_test.rb
|
175
|
+
- test/services_test.rb
|
176
|
+
- test/test_helper.rb
|
177
|
+
- test/test_mode_test.rb
|
178
|
+
has_rdoc: true
|
179
|
+
homepage: https://github.com/ianheggie/geocoder2
|
180
|
+
licenses: []
|
181
|
+
|
182
|
+
post_install_message:
|
183
|
+
rdoc_options: []
|
184
|
+
|
185
|
+
require_paths:
|
186
|
+
- lib
|
187
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
188
|
+
none: false
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
hash: 3
|
193
|
+
segments:
|
194
|
+
- 0
|
195
|
+
version: "0"
|
196
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
|
+
none: false
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
hash: 3
|
202
|
+
segments:
|
203
|
+
- 0
|
204
|
+
version: "0"
|
205
|
+
requirements: []
|
206
|
+
|
207
|
+
rubyforge_project:
|
208
|
+
rubygems_version: 1.6.2
|
209
|
+
signing_key:
|
210
|
+
specification_version: 3
|
211
|
+
summary: Complete geocoding solution for Ruby on Rails v2.
|
212
|
+
test_files: []
|
213
|
+
|