geocoder 1.4.5 → 1.4.7

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: aafaf6b62b506a191b17fcdde0bb1b325769fc8a
4
- data.tar.gz: 61f40f9ac0c89f3bcf25ff417515b60b2421f14c
3
+ metadata.gz: dab954ab0ccd1f5c7829f019e78b754a950939c1
4
+ data.tar.gz: 8dd3db6e80446b91d9c35f9b2ad0f73a5bc28f0b
5
5
  SHA512:
6
- metadata.gz: 0ee51c45355b969282a51fd79725e5fae1538dc56a5b60e659c0b2d3e072c72e83886f9d0d145928e977ed457d4753f5e0cbd424c0fe5c673d1f741a11a200d2
7
- data.tar.gz: 6e4816464c910b0be21bc75d78c2290aabb44b1563af5bac86e6db48b6bae83a5b62c80b8c88c21240b0f8d45c75079e79557698e3aa8ebca4dccfbd99208eb3
6
+ metadata.gz: f796a95c55636b84fd46a58dd7c5e8c96ffea757270d6b8aba584abcc2634e3c30d6cce30fa6d1abf7d8ed683fecf43db6e0f1ec9512ed4b1f607786ba0289cc
7
+ data.tar.gz: f87b1b4860241b21a2ecebfeb8345660acf6c51d92483957eb9ec84999752588c75b4e3248366ecf591919859b8c1880c6d7d0fd29dbd67253443945cfce99a2
@@ -3,6 +3,15 @@ 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.4.7 (2018 Mar 13)
7
+ -------------------
8
+ * Allow HTTP protocol for Nominatim.
9
+
10
+ 1.4.6 (2018 Feb 28)
11
+ -------------------
12
+ * Add support for :ipdata_co lookup (thanks github.com/roschaefer).
13
+ * Update for Rails 5.2 compatibility (thanks github.com/stevenharman).
14
+
6
15
  1.4.5 (2017 Nov 29)
7
16
  -------------------
8
17
  * Add support for :pickpoint lookup (thanks github.com/cylon-v).
data/README.md CHANGED
@@ -156,10 +156,10 @@ Please use MongoDB's [geospatial query language](https://docs.mongodb.org/manual
156
156
 
157
157
  To find objects by location, use the following scopes:
158
158
 
159
- Venue.near('Omaha, NE, US', 20) # venues within 20 miles of Omaha
160
- Venue.near([40.71, -100.23], 20) # venues within 20 miles of a point
161
- Venue.near([40.71, -100.23], 20, :units => :km)
162
- # venues within 20 kilometres of a point
159
+ Venue.near('Omaha, NE, US') # venues within 20 (default) miles of Omaha
160
+ Venue.near([40.71, -100.23], 50) # venues within 50 miles of a point
161
+ Venue.near([40.71, -100.23], 50, :units => :km)
162
+ # venues within 50 kilometres of a point
163
163
  Venue.geocoded # venues with coordinates
164
164
  Venue.not_geocoded # venues without coordinates
165
165
 
@@ -662,11 +662,11 @@ Data Science Toolkit provides an API whose response format is like Google's but
662
662
 
663
663
  * **API key**: required
664
664
  * **Quota**: 2,500 free requests/day then purchase $0.0005 for each, also has volume pricing and plans.
665
- * **Region**: US
665
+ * **Region**: USA & Canada
666
666
  * **SSL support**: yes
667
667
  * **Languages**: en
668
- * **Documentation**: http://geocod.io/docs
669
- * **Terms of Service**: http://geocod.io/terms-of-use
668
+ * **Documentation**: https://geocod.io/docs/
669
+ * **Terms of Service**: https://geocod.io/terms-of-use/
670
670
  * **Limitations**: No restrictions on use
671
671
 
672
672
  #### SmartyStreets (`:smarty_streets`)
@@ -856,6 +856,18 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string
856
856
  * **Documentation**: https://db-ip.com/api/doc.php
857
857
  * **Terms of Service**: https://db-ip.com/tos.php
858
858
 
859
+ #### Ipdata.co (`:ipdata_co`)
860
+
861
+ * **API key**: optional, see: https://ipdata.co/pricing.html
862
+ * **Quota**: 1500/day (up to 600k with paid API keys)
863
+ * **Region**: world
864
+ * **SSL support**: yes
865
+ * **Languages**: English
866
+ * **Documentation**: https://ipdata.co/docs.html
867
+ * **Terms of Service**: https://ipdata.co/terms.html
868
+ * **Limitations**: ?
869
+
870
+
859
871
  ### IP Address Local Database Services
860
872
 
861
873
  #### MaxMind Local (`:maxmind_local`) - EXPERIMENTAL
@@ -1067,6 +1079,7 @@ Notes:
1067
1079
 
1068
1080
  - Keys must be strings not symbols when calling `add_stub` or `set_default_stub`. For example `'latitude' =>` not `:latitude =>`.
1069
1081
  - To clear stubs (e.g. prior to another spec), use `Geocoder::Lookup::Test.reset`. This will clear all stubs _including the default stub_.
1082
+ - The stubbed result objects returned by the Test lookup do not support all the methods real result objects do. If you need to test interaction with real results it may be better to use an external stubbing tool and something like WebMock or VCR to prevent network calls.
1070
1083
 
1071
1084
 
1072
1085
  Command Line Interface
@@ -71,6 +71,7 @@ module Geocoder
71
71
  :maxmind_geoip2,
72
72
  :ipinfo_io,
73
73
  :ipapi_com,
74
+ :ipdata_co,
74
75
  :db_ip_com
75
76
  ]
76
77
  end
@@ -44,6 +44,11 @@ module Geocoder::Lookup
44
44
  return doc['resourceSets'].first['estimatedTotal'] > 0 ? doc['resourceSets'].first['resources'] : []
45
45
  elsif doc['statusCode'] == 401 and doc["authenticationResultCode"] == "InvalidCredentials"
46
46
  raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid Bing API key.")
47
+ elsif doc['statusCode'] == 403
48
+ raise_error(Geocoder::RequestDenied) || Geocoder.log(:warn, "Bing Geocoding API error: Forbidden Request")
49
+ elsif [500, 503].include?(doc['statusCode'])
50
+ raise_error(Geocoder::ServiceUnavailable) ||
51
+ Geocoder.log(:warn, "Bing Geocoding API error: Service Unavailable")
47
52
  else
48
53
  Geocoder.log(:warn, "Bing Geocoding API error: #{doc['statusCode']} (#{doc['statusDescription']}).")
49
54
  end
@@ -10,7 +10,7 @@ module Geocoder::Lookup
10
10
 
11
11
  def query_url(query)
12
12
  path = query.reverse_geocode? ? "reverse" : "geocode"
13
- "#{protocol}://api.geocod.io/v1/#{path}?#{url_query_string(query)}"
13
+ "#{protocol}://api.geocod.io/v1.2/#{path}?#{url_query_string(query)}"
14
14
  end
15
15
 
16
16
  def results(query)
@@ -11,7 +11,7 @@ module Geocoder::Lookup
11
11
  end
12
12
 
13
13
  def required_api_key_parts
14
- ["private key", "client", "channel"]
14
+ ["private key"]
15
15
  end
16
16
 
17
17
  def query_url(query)
@@ -0,0 +1,57 @@
1
+ require 'geocoder/lookups/base'
2
+ require 'geocoder/results/ipdata_co'
3
+
4
+ module Geocoder::Lookup
5
+ class IpdataCo < Base
6
+
7
+ def name
8
+ "ipdata.co"
9
+ end
10
+
11
+ def supported_protocols
12
+ [:https]
13
+ end
14
+
15
+ def query_url(query)
16
+ "#{protocol}://#{host}/#{query.sanitized_text}"
17
+ end
18
+
19
+ private # ---------------------------------------------------------------
20
+
21
+ def results(query)
22
+ Geocoder.configure(:ipdata_co => {:http_headers => { "api-key" => configuration.api_key }}) if configuration.api_key
23
+ # don't look up a loopback address, just return the stored result
24
+ return [reserved_result(query.text)] if query.loopback_ip_address?
25
+ # note: Ipdata.co returns plain text on bad request
26
+ (doc = fetch_data(query)) ? [doc] : []
27
+ end
28
+
29
+ def reserved_result(ip)
30
+ {
31
+ "ip" => ip,
32
+ "city" => "",
33
+ "region_code" => "",
34
+ "region_name" => "",
35
+ "metrocode" => "",
36
+ "zipcode" => "",
37
+ "latitude" => "0",
38
+ "longitude" => "0",
39
+ "country_name" => "Reserved",
40
+ "country_code" => "RD"
41
+ }
42
+ end
43
+
44
+ def host
45
+ "api.ipdata.co"
46
+ end
47
+
48
+ def check_response_for_errors!(response)
49
+ if response.code.to_i == 403
50
+ raise_error(Geocoder::RequestDenied) ||
51
+ Geocoder.log(:warn, "Geocoding API error: 403 API key does not exist")
52
+ else
53
+ super(response)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -13,11 +13,15 @@ module Geocoder::Lookup
13
13
 
14
14
  def query_url(query)
15
15
  method = query.reverse_geocode? ? "reverse" : "search"
16
- "#{protocol}://locationiq.org/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query)
16
+ "#{protocol}://#{configured_host}/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query)
17
17
  end
18
18
 
19
19
  private
20
20
 
21
+ def configured_host
22
+ configuration[:host] || "locationiq.org"
23
+ end
24
+
21
25
  def results(query)
22
26
  return [] unless doc = fetch_data(query)
23
27
 
@@ -9,17 +9,29 @@ module Geocoder::Lookup
9
9
  end
10
10
 
11
11
  def map_link_url(coordinates)
12
- "http://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M"
12
+ "https://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M"
13
13
  end
14
14
 
15
15
  def query_url(query)
16
16
  method = query.reverse_geocode? ? "reverse" : "search"
17
- host = configuration[:host] || "nominatim.openstreetmap.org"
18
- "#{protocol}://#{host}/#{method}?" + url_query_string(query)
17
+ "#{protocol}://#{configured_host}/#{method}?" + url_query_string(query)
19
18
  end
20
19
 
21
20
  private # ---------------------------------------------------------------
22
21
 
22
+ def configured_host
23
+ configuration[:host] || "nominatim.openstreetmap.org"
24
+ end
25
+
26
+ def use_ssl?
27
+ # nominatim.openstreetmap.org redirects HTTP requests to HTTPS
28
+ if configured_host == "nominatim.openstreetmap.org"
29
+ true
30
+ else
31
+ super
32
+ end
33
+ end
34
+
23
35
  def results(query)
24
36
  return [] unless doc = fetch_data(query)
25
37
  doc.is_a?(Array) ? doc : [doc]
@@ -81,7 +81,18 @@ module Geocoder
81
81
  end
82
82
 
83
83
  def geocoder_remove_port_from_addresses(ip_addresses)
84
- ip_addresses.map { |ip| ip.split(':').first }
84
+ ip_addresses.map do |ip|
85
+ # IPv4
86
+ if ip.count('.') > 0
87
+ ip.split(':').first
88
+ # IPv6 bracket notation
89
+ elsif match = ip.match(/\[(\S+)\]/)
90
+ match.captures.first
91
+ # IPv6 bare notation
92
+ else
93
+ ip
94
+ end
95
+ end
85
96
  end
86
97
 
87
98
  def geocoder_reject_non_ipv4_addresses(ip_addresses)
@@ -120,19 +120,30 @@ module Geocoder::Result
120
120
  def precision
121
121
  geometry['location_type'] if geometry
122
122
  end
123
-
123
+
124
124
  def partial_match
125
125
  @data['partial_match']
126
126
  end
127
-
127
+
128
128
  def place_id
129
129
  @data['place_id']
130
- end
130
+ end
131
131
 
132
132
  def viewport
133
133
  viewport = geometry['viewport'] || fail
134
- south, west = %w(lat lng).map { |c| viewport['southwest'][c] }
135
- north, east = %w(lat lng).map { |c| viewport['northeast'][c] }
134
+ bounding_box_from viewport
135
+ end
136
+
137
+ def bounds
138
+ bounding_box_from geometry['bounds']
139
+ end
140
+
141
+ private
142
+
143
+ def bounding_box_from(box)
144
+ return nil unless box
145
+ south, west = %w(lat lng).map { |c| box['southwest'][c] }
146
+ north, east = %w(lat lng).map { |c| box['northeast'][c] }
136
147
  [south, west, north, east]
137
148
  end
138
149
  end
@@ -0,0 +1,45 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class IpdataCo < Base
5
+
6
+ def address(format = :full)
7
+ s = state_code.to_s == "" ? "" : ", #{state_code}"
8
+ "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
9
+ end
10
+
11
+ def city
12
+ @data['city']
13
+ end
14
+
15
+ def state
16
+ @data['region']
17
+ end
18
+
19
+ def state_code
20
+ @data['region_code']
21
+ end
22
+
23
+ def country
24
+ @data['country_name']
25
+ end
26
+
27
+ def country_code
28
+ @data['country_code']
29
+ end
30
+
31
+ def postal_code
32
+ @data['postal']
33
+ end
34
+
35
+ def self.response_attributes
36
+ %w[ip asn organisation currency currency_symbol calling_code flag time_zone is_eu]
37
+ end
38
+
39
+ response_attributes.each do |a|
40
+ define_method a do
41
+ @data[a]
42
+ end
43
+ end
44
+ end
45
+ end
@@ -87,8 +87,6 @@ module Geocoder::Store
87
87
  end
88
88
  end
89
89
 
90
- private # ----------------------------------------------------------------
91
-
92
90
  ##
93
91
  # Get options hash suitable for passing to ActiveRecord.find to get
94
92
  # records within a radius (in kilometers) of the given point.
@@ -168,6 +166,8 @@ module Geocoder::Store
168
166
  }
169
167
  end
170
168
 
169
+ private # ----------------------------------------------------------------
170
+
171
171
  ##
172
172
  # SQL for calculating distance based on the current database's
173
173
  # capabilities (trig functions?).
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.4.5"
2
+ VERSION = "1.4.7"
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.4.5
4
+ version: 1.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-29 00:00:00.000000000 Z
11
+ date: 2018-03-13 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,
@@ -69,6 +69,7 @@ files:
69
69
  - lib/geocoder/lookups/google_premier.rb
70
70
  - lib/geocoder/lookups/here.rb
71
71
  - lib/geocoder/lookups/ipapi_com.rb
72
+ - lib/geocoder/lookups/ipdata_co.rb
72
73
  - lib/geocoder/lookups/ipinfo_io.rb
73
74
  - lib/geocoder/lookups/latlon.rb
74
75
  - lib/geocoder/lookups/location_iq.rb
@@ -119,6 +120,7 @@ files:
119
120
  - lib/geocoder/results/google_premier.rb
120
121
  - lib/geocoder/results/here.rb
121
122
  - lib/geocoder/results/ipapi_com.rb
123
+ - lib/geocoder/results/ipdata_co.rb
122
124
  - lib/geocoder/results/ipinfo_io.rb
123
125
  - lib/geocoder/results/latlon.rb
124
126
  - lib/geocoder/results/location_iq.rb