geocoder 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of geocoder might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +6 -0
- data/README.md +1 -2
- data/lib/geocoder/lookups/base.rb +2 -0
- data/lib/geocoder/lookups/bing.rb +3 -1
- data/lib/geocoder/lookups/google.rb +1 -1
- data/lib/geocoder/lookups/nominatim.rb +1 -1
- data/lib/geocoder/lookups/yahoo.rb +3 -1
- data/lib/geocoder/lookups/yandex.rb +1 -1
- data/lib/geocoder/query.rb +4 -0
- data/lib/geocoder/version.rb +1 -1
- data/test/test_helper.rb +1 -0
- data/test/unit/error_handling_test.rb +12 -0
- data/test/unit/lookup_test.rb +17 -0
- data/test/unit/lookups/bing_test.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83f0267dc6d6f5b13f1a3a26f1c901e88618e9cc
|
4
|
+
data.tar.gz: d571a2205694b66dac921798eb8ae8c6d497a92e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78e3b5fe48c4f6827e71345e85a6edfddbb14efcaa05ebdb57ad63f7f0f4b8bf4a653e9ab75da333ebec94eb9e14745b62181cf3f77e4b958dc2840549888017
|
7
|
+
data.tar.gz: 389bd66826e1f2878ff49d55cf6f6445b5b122ac99761cc9f5d6bdba29cfb4d4ee23cb77974972ab911a44ecbfc43ee1d913f3e8c01b6d15cd903e55e94529f4
|
data/.travis.yml
CHANGED
@@ -4,7 +4,7 @@ rvm:
|
|
4
4
|
- 2.0.0
|
5
5
|
- 2.1.0
|
6
6
|
- jruby-19mode
|
7
|
-
- rbx
|
7
|
+
- rbx-2
|
8
8
|
gemfile:
|
9
9
|
- Gemfile
|
10
10
|
- gemfiles/Gemfile.mongoid-2.4.x
|
@@ -26,6 +26,6 @@ matrix:
|
|
26
26
|
- rvm: jruby-19mode
|
27
27
|
gemfile: gemfiles/Gemfile.mongoid-2.4.x
|
28
28
|
env: SSL_CERT_DIR=/etc/ssl/certs
|
29
|
-
- rvm: rbx
|
29
|
+
- rvm: rbx-2
|
30
30
|
gemfile: gemfiles/Gemfile.mongoid-2.4.x
|
31
31
|
env: SSL_CERT_DIR=/etc/ssl/certs
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,12 @@ Changelog
|
|
3
3
|
|
4
4
|
Major changes to Geocoder for each release. Please see the Git log for complete list of changes.
|
5
5
|
|
6
|
+
1.2.2 (2014 Jun 12)
|
7
|
+
|
8
|
+
* Add ability to specify language per query (thanks github.com/mkristian).
|
9
|
+
* Handle Errno::ECONNREFUSED exceptions like TimeoutError exceptions.
|
10
|
+
* Switch to 'unstructured' query format for Bing API (thanks github.com/lukewendling).
|
11
|
+
|
6
12
|
1.2.1 (2014 May 12)
|
7
13
|
-------------------
|
8
14
|
|
data/README.md
CHANGED
@@ -388,8 +388,6 @@ The following is a comparison of the supported geocoding APIs. The "Limitations"
|
|
388
388
|
|
389
389
|
#### Yahoo BOSS (`:yahoo`)
|
390
390
|
|
391
|
-
Yahoo BOSS is **not a free service**. As of November 17, 2012 Yahoo no longer offers a free geocoding API.
|
392
|
-
|
393
391
|
* **API key**: requires OAuth consumer key and secret (set `Geocoder.configure(:api_key => [key, secret])`)
|
394
392
|
* **Key signup**: http://developer.yahoo.com/boss/geo/
|
395
393
|
* **Quota**: unlimited, but subject to usage fees
|
@@ -578,6 +576,7 @@ Data Science Toolkit provides an API whose reponse format is like Google's but w
|
|
578
576
|
* **Documentation**: http://github.com/fiorix/freegeoip/blob/master/README.md
|
579
577
|
* **Terms of Service**: ?
|
580
578
|
* **Limitations**: ?
|
579
|
+
* **Notes**: If you are running your own local instance of the FreeGeoIP service you can configure the host like this: `Geocoder.configure(freegeoip: {host: "..."})`.
|
581
580
|
|
582
581
|
#### MaxMind Web Services (`:maxmind`)
|
583
582
|
|
@@ -169,6 +169,8 @@ module Geocoder
|
|
169
169
|
parse_raw_data fetch_raw_data(query)
|
170
170
|
rescue SocketError => err
|
171
171
|
raise_error(err) or warn "Geocoding API connection cannot be established."
|
172
|
+
rescue Errno::ECONNREFUSED => err
|
173
|
+
raise_error(err) or warn "Geocoding API connection refused."
|
172
174
|
rescue TimeoutError => err
|
173
175
|
raise_error(err) or warn "Geocoding API not responding fast enough " +
|
174
176
|
"(use Geocoder.configure(:timeout => ...) to set limit)."
|
@@ -27,7 +27,9 @@ module Geocoder::Lookup
|
|
27
27
|
if !query.reverse_geocode? and r = query.options[:region]
|
28
28
|
url << "/#{r}"
|
29
29
|
end
|
30
|
-
|
30
|
+
# use the more forgiving 'unstructured' query format to allow special
|
31
|
+
# chars, newlines, brackets, typos.
|
32
|
+
url + "?q=" + URI.escape(query.sanitized_text.strip) + "&"
|
31
33
|
end
|
32
34
|
|
33
35
|
def results(query)
|
@@ -44,7 +44,7 @@ module Geocoder::Lookup
|
|
44
44
|
params = {
|
45
45
|
(query.reverse_geocode? ? :latlng : :address) => query.sanitized_text,
|
46
46
|
:sensor => "false",
|
47
|
-
:language => configuration.language
|
47
|
+
:language => (query.language || configuration.language)
|
48
48
|
}
|
49
49
|
unless (bounds = query.options[:bounds]).nil?
|
50
50
|
params[:bounds] = bounds.map{ |point| "%f,%f" % point }.join('|')
|
@@ -37,7 +37,7 @@ module Geocoder::Lookup
|
|
37
37
|
params = {
|
38
38
|
:format => "json",
|
39
39
|
:addressdetails => "1",
|
40
|
-
:"accept-language" => configuration.language
|
40
|
+
:"accept-language" => (query.language || configuration.language)
|
41
41
|
}.merge(super)
|
42
42
|
if query.reverse_geocode?
|
43
43
|
lat,lon = query.coordinates
|
@@ -62,11 +62,13 @@ module Geocoder::Lookup
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def query_url_params(query)
|
65
|
+
lang = (query.language || configuration.language).to_s
|
66
|
+
lang += '_US' if lang == 'en'
|
65
67
|
{
|
66
68
|
:location => query.sanitized_text,
|
67
69
|
:flags => "JXTSR",
|
68
70
|
:gflags => "AC#{'R' if query.reverse_geocode?}",
|
69
|
-
:locale =>
|
71
|
+
:locale => lang,
|
70
72
|
:appid => configuration.api_key
|
71
73
|
}.merge(super)
|
72
74
|
end
|
@@ -46,7 +46,7 @@ module Geocoder::Lookup
|
|
46
46
|
{
|
47
47
|
:geocode => q,
|
48
48
|
:format => "json",
|
49
|
-
:plng => "#{configuration.language}", # supports ru, uk, be
|
49
|
+
:plng => "#{query.language || configuration.language}", # supports ru, uk, be
|
50
50
|
:key => configuration.api_key
|
51
51
|
}.merge(super)
|
52
52
|
end
|
data/lib/geocoder/query.rb
CHANGED
data/lib/geocoder/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -110,6 +110,7 @@ module Geocoder
|
|
110
110
|
def make_api_request(query)
|
111
111
|
raise TimeoutError if query.text == "timeout"
|
112
112
|
raise SocketError if query.text == "socket_error"
|
113
|
+
raise Errno::ECONNREFUSED if query.text == "connection_refused"
|
113
114
|
read_fixture fixture_for_query(query)
|
114
115
|
end
|
115
116
|
end
|
@@ -41,4 +41,16 @@ class ErrorHandlingTest < GeocoderTestCase
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
def test_always_raise_connection_refused_error
|
46
|
+
Geocoder.configure(:always_raise => [Errno::ECONNREFUSED])
|
47
|
+
Geocoder::Lookup.all_services_except_test.each do |l|
|
48
|
+
next if l == :maxmind_local # local, does not raise timeout
|
49
|
+
lookup = Geocoder::Lookup.get(l)
|
50
|
+
set_api_key!(l)
|
51
|
+
assert_raises Errno::ECONNREFUSED do
|
52
|
+
lookup.send(:results, Geocoder::Query.new("connection_refused"))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
44
56
|
end
|
data/test/unit/lookup_test.rb
CHANGED
@@ -56,6 +56,23 @@ class LookupTest < GeocoderTestCase
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
{
|
60
|
+
:google => :language,
|
61
|
+
:google_premier => :language,
|
62
|
+
:nominatim => :"accept-language",
|
63
|
+
:yahoo => :locale,
|
64
|
+
:yandex => :plng
|
65
|
+
}.each do |l,p|
|
66
|
+
define_method "test_passing_language_to_#{l}_query_overrides_configuration_value" do
|
67
|
+
set_api_key!(l)
|
68
|
+
url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new(
|
69
|
+
"test", :language => 'xxxx'
|
70
|
+
))
|
71
|
+
assert_match(/#{p}=xxxx/, url,
|
72
|
+
"Param passed to #{l} lookup does not override configuration value")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
59
76
|
def test_raises_exception_on_invalid_key
|
60
77
|
Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey])
|
61
78
|
#Geocoder::Lookup.all_services_except_test.each do |l|
|
@@ -12,7 +12,7 @@ class BingTest < GeocoderTestCase
|
|
12
12
|
def test_query_for_reverse_geocode
|
13
13
|
lookup = Geocoder::Lookup::Bing.new
|
14
14
|
url = lookup.query_url(Geocoder::Query.new([45.423733, -75.676333]))
|
15
|
-
assert_match(/Locations
|
15
|
+
assert_match(/Locations\?q=45.423733/, url)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_result_components
|
@@ -33,7 +33,7 @@ class BingTest < GeocoderTestCase
|
|
33
33
|
"manchester",
|
34
34
|
:region => "uk"
|
35
35
|
))
|
36
|
-
assert_match(/Locations\/uk
|
36
|
+
assert_match(/Locations\/uk\?q=manchester/, url)
|
37
37
|
assert_no_match(/query/, url)
|
38
38
|
end
|
39
39
|
|
@@ -42,7 +42,7 @@ class BingTest < GeocoderTestCase
|
|
42
42
|
url = lookup.query_url(Geocoder::Query.new(
|
43
43
|
"manchester"
|
44
44
|
))
|
45
|
-
assert_match(/Locations
|
45
|
+
assert_match(/Locations\?q=manchester/, url)
|
46
46
|
assert_no_match(/query/, url)
|
47
47
|
end
|
48
48
|
|
@@ -52,7 +52,7 @@ class BingTest < GeocoderTestCase
|
|
52
52
|
"manchester, lancashire",
|
53
53
|
:region => "uk"
|
54
54
|
))
|
55
|
-
assert_match(/Locations\/uk
|
55
|
+
assert_match(/Locations\/uk\?q=manchester,%20lancashire/, url)
|
56
56
|
assert_no_match(/query/, url)
|
57
57
|
end
|
58
58
|
|
@@ -62,7 +62,7 @@ class BingTest < GeocoderTestCase
|
|
62
62
|
" manchester, lancashire ",
|
63
63
|
:region => "uk"
|
64
64
|
))
|
65
|
-
assert_match(/Locations\/uk
|
65
|
+
assert_match(/Locations\/uk\?q=manchester,%20lancashire/, url)
|
66
66
|
assert_no_match(/query/, url)
|
67
67
|
end
|
68
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geocoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Reisner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Provides object geocoding (by street or IP address), reverse geocoding
|
14
14
|
(coordinates to street address), distance queries for ActiveRecord and Mongoid,
|