geocoder 1.2.8 → 1.2.9

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: d961c40e5dd577d90ddac243ccb32889ef88414e
4
- data.tar.gz: 275e6174c8aa69f413e5fea4cda24c92110fcc49
3
+ metadata.gz: 69826a3c50884c70a7a937f80f1280f234687e2f
4
+ data.tar.gz: 4bcdee80b4db4db6c7efbd2886d9fab96b4976bf
5
5
  SHA512:
6
- metadata.gz: 56be16e5480d37be9acfe3b5b7014ac218c11d82f9a559bd5047e1a93e6a0401230fb66d303d949d3d297464c101f18ecb8dc258395230f76641e195f8be982d
7
- data.tar.gz: 881e348fa2484ee731b3c0b7c53564c9ce6413d7772e9fe6e5bfa9501fae4162e95f3d08b0c033016c50cd39b2d9a70b855d17f071d83a83f8d5cf1539c6e17f
6
+ metadata.gz: c9d0cbaa046ebc593590340937a29b687e98107ea87606b4fc10ab3bd000376471f4b940f3848bd68a75e1e8f273843e29278ca4449e8ce5219a46ed9daf468e
7
+ data.tar.gz: ed245fd8affec37d6f60f54bedf3fb35a704cf6f4f134537bdcac5356bd245c64df0f707b690990585deae794d24bf30c16aaa0f754ee52b8a09c2b79236a509
data/CHANGELOG.md CHANGED
@@ -3,12 +3,19 @@ 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.9 (2015 Jun 12)
7
+ -------------------
8
+ * Don't cache unsuccessful responses from Bing (thanks github.com/peteb).
9
+ * Show API response when not valid JSON.
10
+ * Log each API request.
11
+ * Force all SmartyStreets requests to use HTTPS.
12
+
6
13
  1.2.8 (2015 Mar 21)
7
14
  -------------------
8
15
  * Add :maxmind_geoip2 lookup (thanks github.com/TrangPham).
9
16
  * Add ability to force/specify query type (street or IP address) (thanks github.com/TrangPham).
10
17
  * Add :basic_auth configuration (thanks github.com/TrangPham).
11
- * Add `paranoid_location` method for Rails controllers (thanks github.com/edslocomb).
18
+ * Add `safe_location` method for Rails controllers (thanks github.com/edslocomb).
12
19
  * Add :logger configuration (thanks github.com/TrangPham).
13
20
  * Improve error condition handling with Bing (thanks github.com/TrangPham).
14
21
 
data/README.md CHANGED
@@ -163,9 +163,9 @@ Some utility methods are also available:
163
163
  Geocoder.coordinates("25 Main St, Cooperstown, NY")
164
164
  => [42.700149, -74.922767]
165
165
 
166
- # distance (in miles) between Eiffel Tower and Empire State Building
166
+ # distance between Eiffel Tower and Empire State Building
167
167
  Geocoder::Calculations.distance_between([47.858205,2.294359], [40.748433,-73.985655])
168
- => 3619.77359999382
168
+ => 3619.77359999382 # in configured units (default miles)
169
169
 
170
170
  # find the geographic center (aka center of gravity) of objects or points
171
171
  Geocoder::Calculations.geographic_center([city1, city2, [40.22,-73.99], city4])
@@ -424,8 +424,8 @@ The [Google Places Details API](https://developers.google.com/places/documentati
424
424
  #### Bing (`:bing`)
425
425
 
426
426
  * **API key**: required (set `Geocoder.configure(:lookup => :bing, :api_key => key)`)
427
- * **Key signup**: http://www.bingmapsportal.com
428
- * **Quota**: 50,000 requests/24 hrs
427
+ * **Key signup**: https://www.microsoft.com/maps/create-a-bing-maps-key.aspx
428
+ * **Quota**: 50,0000 requests/day (Windows app), 125,000 requests/year (non-Windows app)
429
429
  * **Region**: world
430
430
  * **SSL support**: no
431
431
  * **Languages**: ?
@@ -494,16 +494,15 @@ The [Google Places Details API](https://developers.google.com/places/documentati
494
494
  * **API key**: required
495
495
  * **Key signup**: http://developer.mapquest.com/web/products/open
496
496
  * **Quota**: ?
497
- * **HTTP Headers**: in order to use the licensed API you can configure the http_headers to include a referer as so:
497
+ * **HTTP Headers**: when using the licensed API you can specify a referer like so:
498
498
  `Geocoder.configure(:http_headers => { "Referer" => "http://foo.com" })`
499
- You can also allow a blank referer from the API management console via mapquest but it is potentially a security risk that someone else could use your API key from another domain.
500
499
  * **Region**: world
501
500
  * **SSL support**: no
502
501
  * **Languages**: English
503
502
  * **Documentation**: http://www.mapquestapi.com/geocoding/
504
503
  * **Terms of Service**: http://info.mapquest.com/terms-of-use/
505
504
  * **Limitations**: ?
506
- * **Notes**: You can specify the licensed API by setting: `Geocoder.configure(:mapquest => {:licensed => true})` (defaults to free "open" version)
505
+ * **Notes**: You can use the open (non-licensed) API by setting: `Geocoder.configure(:mapquest => {:open => true})` (defaults to licensed version)
507
506
 
508
507
  #### Ovi/Nokia (`:ovi`)
509
508
 
@@ -518,7 +517,7 @@ The [Google Places Details API](https://developers.google.com/places/documentati
518
517
 
519
518
  #### Here/Nokia (`:here`)
520
519
 
521
- * **API key**: required
520
+ * **API key**: required (set `Geocoder.configure(:api_key => [app_id, app_code])`)
522
521
  * **Quota**: Depending on the API key
523
522
  * **Region**: world
524
523
  * **SSL support**: yes
@@ -581,7 +580,7 @@ Data Science Toolkit provides an API whose reponse format is like Google's but w
581
580
  * **API key**: requires auth_id and auth_token (set `Geocoder.configure(:api_key => [id, token])`)
582
581
  * **Quota**: 10,000 free, 250/month then purchase at sliding scale.
583
582
  * **Region**: US
584
- * **SSL support**: yes
583
+ * **SSL support**: yes (required)
585
584
  * **Languages**: en
586
585
  * **Documentation**: http://smartystreets.com/kb/liveaddress-api/rest-endpoint
587
586
  * **Terms of Service**: http://smartystreets.com/legal/terms-of-service
@@ -867,7 +866,7 @@ When writing tests for an app that uses Geocoder it may be useful to avoid netwo
867
866
  ]
868
867
  )
869
868
 
870
- Now, any time Geocoder looks up "New York, NY" its results array will contain one result with the above attributes. You can also set a default stub:
869
+ Now, any time Geocoder looks up "New York, NY" its results array will contain one result with the above attributes. You can also set a default stub, to be returned when no other stub is found for a given query:
871
870
 
872
871
  Geocoder.configure(:lookup => :test)
873
872
 
@@ -885,7 +884,6 @@ Now, any time Geocoder looks up "New York, NY" its results array will contain on
885
884
  ]
886
885
  )
887
886
 
888
- Any query that hasn't been explicitly stubbed will return that result.
889
887
 
890
888
  Command Line Interface
891
889
  ----------------------
@@ -16,6 +16,11 @@ module Geocoder::Lookup
16
16
  "http://api.map.baidu.com/geocoder/v2/?" + url_query_string(query)
17
17
  end
18
18
 
19
+ # HTTP only
20
+ def supported_protocols
21
+ [:http]
22
+ end
23
+
19
24
  private # ---------------------------------------------------------------
20
25
 
21
26
  def results(query, reverse = false)
@@ -52,4 +57,3 @@ module Geocoder::Lookup
52
57
 
53
58
  end
54
59
  end
55
-
@@ -16,6 +16,11 @@ module Geocoder::Lookup
16
16
  "http://api.map.baidu.com/location/ip?" + url_query_string(query)
17
17
  end
18
18
 
19
+ # HTTP only
20
+ def supported_protocols
21
+ [:http]
22
+ end
23
+
19
24
  private # ---------------------------------------------------------------
20
25
 
21
26
  def results(query, reverse = false)
@@ -86,6 +86,15 @@ module Geocoder
86
86
  @cache
87
87
  end
88
88
 
89
+ ##
90
+ # Array containing the protocols supported by the api.
91
+ # Should be set to [:http] if only HTTP is supported
92
+ # or [:https] if only HTTPS is supported.
93
+ #
94
+ def supported_protocols
95
+ [:http, :https]
96
+ end
97
+
89
98
  private # -------------------------------------------------------------
90
99
 
91
100
  ##
@@ -99,7 +108,6 @@ module Geocoder
99
108
  # Object used to make HTTP requests.
100
109
  #
101
110
  def http_client
102
- protocol = "http#{'s' if use_ssl?}"
103
111
  proxy_name = "#{protocol}_proxy"
104
112
  if proxy = configuration.send(proxy_name)
105
113
  proxy_url = !!(proxy =~ /^#{protocol}/) ? proxy : protocol + '://' + proxy
@@ -183,7 +191,7 @@ module Geocoder
183
191
  JSON.parse(data)
184
192
  end
185
193
  rescue => err
186
- raise_error(ResponseParseError.new(data)) or Geocoder.log(:warn, "Geocoding API's response was not valid JSON.")
194
+ raise_error(ResponseParseError.new(data)) or Geocoder.log(:warn, "Geocoding API's response was not valid JSON: #{data}")
187
195
  end
188
196
 
189
197
  ##
@@ -265,6 +273,7 @@ module Geocoder
265
273
  def make_api_request(query)
266
274
  timeout(configuration.timeout) do
267
275
  uri = URI.parse(query_url(query))
276
+ Geocoder.log(:debug, "Geocoder: HTTP request being made for #{uri.to_s}")
268
277
  http_client.start(uri.host, uri.port, use_ssl: use_ssl?) do |client|
269
278
  req = Net::HTTP::Get.new(uri.request_uri, configuration.http_headers)
270
279
  if configuration.basic_auth[:user] and configuration.basic_auth[:password]
@@ -279,7 +288,13 @@ module Geocoder
279
288
  end
280
289
 
281
290
  def use_ssl?
282
- configuration.use_https
291
+ if supported_protocols == [:https]
292
+ true
293
+ elsif supported_protocols == [:http]
294
+ false
295
+ else
296
+ configuration.use_https
297
+ end
283
298
  end
284
299
 
285
300
  def check_api_key_configuration!(query)
@@ -58,15 +58,23 @@ module Geocoder::Lookup
58
58
 
59
59
  def check_response_for_errors!(response)
60
60
  super
61
- if response['x-ms-bm-ws-info'].to_i == 1
62
- # Occasionally, the servers processing service requests can be overloaded,
63
- # and you may receive some responses that contain no results for queries that
64
- # you would normally receive a result. To identify this situation,
65
- # check the HTTP headers of the response. If the HTTP header X-MS-BM-WS-INFO is set to 1,
66
- # it is best to wait a few seconds and try again.
61
+ if server_overloaded?(response)
67
62
  raise_error(Geocoder::ServiceUnavailable) ||
68
63
  Geocoder.log(:warn, "Bing Geocoding API error: Service Unavailable")
69
64
  end
70
65
  end
66
+
67
+ def valid_response?(response)
68
+ super(response) and not server_overloaded?(response)
69
+ end
70
+
71
+ def server_overloaded?(response)
72
+ # Occasionally, the servers processing service requests can be overloaded,
73
+ # and you may receive some responses that contain no results for queries that
74
+ # you would normally receive a result. To identify this situation,
75
+ # check the HTTP headers of the response. If the HTTP header X-MS-BM-WS-INFO is set to 1,
76
+ # it is best to wait a few seconds and try again.
77
+ response['x-ms-bm-ws-info'].to_i == 1
78
+ end
71
79
  end
72
80
  end
@@ -12,8 +12,8 @@ module Geocoder
12
12
  ["key"]
13
13
  end
14
14
 
15
- def use_ssl?
16
- true
15
+ def supported_protocols
16
+ [:https]
17
17
  end
18
18
 
19
19
  def query_url(query)
@@ -9,7 +9,7 @@ module Geocoder::Lookup
9
9
  end
10
10
 
11
11
  def required_api_key_parts
12
- []
12
+ ["app_id", "app_code"]
13
13
  end
14
14
 
15
15
  def query_url(query)
@@ -15,8 +15,7 @@ module Geocoder::Lookup
15
15
 
16
16
  def query_url(query)
17
17
  domain = configuration[:open] ? "open" : "www"
18
- version = configuration[:version] || 1
19
- url = "#{protocol}://#{domain}.mapquestapi.com/geocoding/v#{version}/#{search_type(query)}?"
18
+ url = "#{protocol}://#{domain}.mapquestapi.com/geocoding/v1/#{search_type(query)}?"
20
19
  url + url_query_string(query)
21
20
  end
22
21
 
@@ -8,10 +8,10 @@ module Geocoder::Lookup
8
8
  "MaxMind GeoIP2"
9
9
  end
10
10
 
11
- def use_ssl?
12
- # Maxmind's GeoIP2 Precision Services only supports HTTPS,
13
- # otherwise a `404 Not Found` HTTP response will be returned
14
- true
11
+ # Maxmind's GeoIP2 Precision Services only supports HTTPS,
12
+ # otherwise a `404 Not Found` HTTP response will be returned
13
+ def supported_protocols
14
+ [:https]
15
15
  end
16
16
 
17
17
  def query_url(query)
@@ -16,6 +16,11 @@ module Geocoder::Lookup
16
16
  "#{protocol}://api.smartystreets.com/#{path}?#{url_query_string(query)}"
17
17
  end
18
18
 
19
+ # required by API as of 26 March 2015
20
+ def supported_protocols
21
+ [:https]
22
+ end
23
+
19
24
  private # ---------------------------------------------------------------
20
25
 
21
26
  def zipcode_only?(query)
@@ -9,16 +9,16 @@ module Geocoder::Lookup
9
9
  end
10
10
 
11
11
  def query_url(query)
12
- #currently doesn't support HTTPS
13
12
  "http://www.telize.com/geoip/#{query.sanitized_text}"
14
13
  end
15
14
 
16
- private # ---------------------------------------------------------------
17
-
18
- def use_ssl?
19
- false
15
+ # currently doesn't support HTTPS
16
+ def supported_protocols
17
+ [:http]
20
18
  end
21
19
 
20
+ private # ---------------------------------------------------------------
21
+
22
22
  def results(query)
23
23
  # don't look up a loopback address, just return the stored result
24
24
  return [reserved_result(query.text)] if query.loopback_ip_address?
@@ -1,5 +1,3 @@
1
- require 'geocoder'
2
-
3
1
  module Geocoder
4
2
 
5
3
  ##
@@ -13,35 +13,35 @@ module Geocoder
13
13
  end
14
14
 
15
15
  def latitude
16
- @data.fetch('location',{}).fetch('latitude',0.0)
16
+ data.fetch('location',{}).fetch('latitude',0.0)
17
17
  end
18
18
 
19
19
  def longitude
20
- @data.fetch('location',{}).fetch('longitude',0.0)
20
+ data.fetch('location',{}).fetch('longitude',0.0)
21
21
  end
22
22
 
23
23
  def city
24
- @data.fetch('city', {}).fetch('names', {}).fetch('en', '')
24
+ data.fetch('city', {}).fetch('names', {}).fetch('en', '')
25
25
  end
26
26
 
27
27
  def state
28
- @data.fetch('subdivisions',[]).fetch(0,{}).fetch('names',{}).fetch('en','')
28
+ data.fetch('subdivisions',[]).fetch(0,{}).fetch('names',{}).fetch('en','')
29
29
  end
30
30
 
31
31
  def state_code
32
- @data.fetch('subdivisions',[]).fetch(0,{}).fetch('iso_code','')
32
+ data.fetch('subdivisions',[]).fetch(0,{}).fetch('iso_code','')
33
33
  end
34
34
 
35
35
  def country
36
- @data.fetch('country', {}).fetch('names',{}).fetch('en','')
36
+ data.fetch('country', {}).fetch('names',{}).fetch('en','')
37
37
  end
38
38
 
39
39
  def country_code
40
- @data.fetch('country',{}).fetch('iso_code','')
40
+ data.fetch('country',{}).fetch('iso_code','')
41
41
  end
42
42
 
43
43
  def postal_code
44
- @data.fetch('postal',{}).fetch('code','')
44
+ data.fetch('postal',{}).fetch('code','')
45
45
  end
46
46
 
47
47
  def self.response_attributes
@@ -53,6 +53,12 @@ module Geocoder
53
53
  @data[a]
54
54
  end
55
55
  end
56
+
57
+ private
58
+
59
+ def data
60
+ @data.to_hash
61
+ end
56
62
  end
57
63
  end
58
64
  end
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.2.8"
2
+ VERSION = "1.2.9"
3
3
  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.8
4
+ version: 1.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-21 00:00:00.000000000 Z
11
+ date: 2015-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,