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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a87e48d6ef8d83ba7431093b99731ed6488d901
4
- data.tar.gz: 813db65901b6ce424544968d1cc8c1bfa78425a0
3
+ metadata.gz: 83f0267dc6d6f5b13f1a3a26f1c901e88618e9cc
4
+ data.tar.gz: d571a2205694b66dac921798eb8ae8c6d497a92e
5
5
  SHA512:
6
- metadata.gz: 99aa2501a9fbc16abe3a0fd7b354b3d29f51653507f463a1692aebb00e1f41b8e3f9b41d1a2e493aadba7f42c44cd66c3082d3e9147732cb1703c92aa11fc354
7
- data.tar.gz: 64094ce5902e6471e958810e4438feec04f6e9f7a9fdfd99a79262d3d1cf5a8b84196eb57c6ff3343cb2e262d650194ec23adb686f73e31f4df086c601c0656e
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
- url + "/" + URI.escape(query.sanitized_text.strip) + "?"
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 => "#{configuration.language}_US",
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
@@ -98,6 +98,10 @@ module Geocoder
98
98
  coordinates?
99
99
  end
100
100
 
101
+ def language
102
+ options[:language]
103
+ end
104
+
101
105
  private # ----------------------------------------------------------------
102
106
 
103
107
  def params_given?
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
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
@@ -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\/45.423733/, url)
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\/manchester/, url)
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\/manchester/, url)
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\/manchester,%20lancashire/, url)
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\/manchester,%20lancashire/, url)
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.1
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-05-12 00:00:00.000000000 Z
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,