geocoder 1.8.2 → 1.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26c7b5c88c38ee619a8fdc7452014b9601db83539334353758d451d2b300faf2
4
- data.tar.gz: 873c8a8148b792c43302b921665880d2f4b54cdc8ad7e4698fafee4e2a24c8b4
3
+ metadata.gz: 447dfedeffcb5c111f6441badccf6d1c25c38a3a0fed32aaeb31151d27425a3d
4
+ data.tar.gz: 89b7f5b123d125ccb329d66f0172ef0a46d3176d6e215cc1a884b0a2249ae4cd
5
5
  SHA512:
6
- metadata.gz: c8fc1e15bfb40407c0f3bcd31030defaf9af58be2c7c49d84efaa5b8ce3828cafd54d3c2a63d08920db4f2701934ac6c3ac9df52888c27fbfd8a05036da11bb5
7
- data.tar.gz: 1114e5142f8e8e358fa143fb143b0ea833c611bc2ab92bcbe0d04dc62d0965d46149651d7c3847f967c76a5997a3fba1d0d43a997aee2287268a48ac041e08c7
6
+ metadata.gz: a90b21dfcc3aeb50ac94fad6eafeec0141ba320bb638912b2e0091f80beb30b306f58cc104db8a55ab47cf8a5543edbabe9372dbda7c63dcbeb560c42b92a957
7
+ data.tar.gz: c0489e8f2b3c4d98cf40235e2b60fc5c8d129cd74aecc65f57bfd9adee7549db804fb0bcdf6b68c14933478fd3a0ea06124350208987a575c916a0992c28adb7
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.8.3 (2024 May 2)
7
+ -------------------
8
+ * Add support for IP2Location LITE lookup (thanks github.com/ip2location).
9
+ * Add support for PDOK NL lookup (thanks github.com/opensourceame).
10
+ * Remove support for Data Science Toolkit lookup (defunct).
11
+
6
12
  1.8.2 (2023 Jul 4)
7
13
  -------------------
8
14
  * Add support for PC Miler lookup (thanks github.com/alexdean).
data/README.md CHANGED
@@ -734,8 +734,34 @@ you should check your Gemfile to make sure the Mongoid gem is listed _before_ Ge
734
734
 
735
735
  A lot of debugging time can be saved by understanding how Geocoder works with ActiveRecord. When you use the `near` scope or the `nearbys` method of a geocoded object, Geocoder creates an ActiveModel::Relation object which adds some attributes (eg: distance, bearing) to the SELECT clause. It also adds a condition to the WHERE clause to check that distance is within the given radius. Because the SELECT clause is modified, anything else that modifies the SELECT clause may produce strange results, for example:
736
736
 
737
- * using the `pluck` method (selects only a single column)
738
- * specifying another model through `includes` (selects columns from other tables)
737
+ * using [`select` method (selects one or more columns)](https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-select)
738
+ * using the [`pluck` method (gets an array with selecting one or more columns)](https://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-pluck)
739
+ * The same problem will appear with [ActiveRecord's `ids` method](https://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-ids).
740
+ * specifying another model through [`includes` (selects columns from other tables)](https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-includes)
741
+ * See also Known Issues [using-near-with-includes](#using-near-with-select) section.
742
+
743
+ If you get an error in the above cases, try the following:
744
+
745
+ ```ruby
746
+ # Use the :select option with the near scope to get the columns you want.
747
+ # Instead of City.near(...).select(:id, :name), try:
748
+ City.near("Omaha, NE", 20, select: "id, name")
749
+
750
+ # Pass a :select option to the near scope to get the columns you want.
751
+ # Then, Ruby's built-in pluck method gets arrays you want.
752
+ # Instead of City.near(...).pluck(:id) or City.near(...).ids,, try:
753
+ City.near("Omaha, NE", 20, select: "id, name").to_a.pluck(:id, :name)
754
+ City.near("Omaha, NE", 20, select: "id").to_a.pluck(:id)
755
+
756
+ # Pass a :select option to the near scope to get the columns you want.
757
+ # Instead of City.near(...).includes(:venues), try:
758
+ City.near("Omaha, NE", 20, select: "cities.*, venues.*").joins(:venues)
759
+
760
+ # This preload call will normally trigger two queries regardless of the
761
+ # number of results; one query on hotels, and one query on administrators.
762
+ # Instead of Hotel.near(...).includes(:administrator), try:
763
+ Hotel.near("London, UK", 50).joins(:administrator).preload(:administrator)
764
+ ```
739
765
 
740
766
  ### Geocoding is Slow
741
767
 
@@ -23,7 +23,7 @@ module Geocoder
23
23
  # For example, Amazon Location Service uses the AWS gem, not HTTP REST requests, to fetch data.
24
24
  #
25
25
  def all_services_with_http_requests
26
- all_services_except_test - [:amazon_location_service]
26
+ all_services_except_test - [:amazon_location_service, :maxmind_local, :geoip2, :ip2location_lite]
27
27
  end
28
28
 
29
29
  ##
@@ -32,7 +32,6 @@ module Geocoder
32
32
  def street_services
33
33
  @street_services ||= [
34
34
  :location_iq,
35
- :dstk,
36
35
  :esri,
37
36
  :google,
38
37
  :google_premier,
@@ -48,6 +47,7 @@ module Geocoder
48
47
  :uk_ordnance_survey_names,
49
48
  :opencagedata,
50
49
  :pelias,
50
+ :pdok_nl,
51
51
  :pickpoint,
52
52
  :here,
53
53
  :baidu,
@@ -94,7 +94,9 @@ module Geocoder
94
94
  :ip2location,
95
95
  :ipgeolocation,
96
96
  :ipqualityscore,
97
- :ipbase
97
+ :ipbase,
98
+ :ip2location_io,
99
+ :ip2location_lite
98
100
  ]
99
101
  end
100
102
 
@@ -19,7 +19,7 @@ module Geocoder::Lookup
19
19
  client.search_place_index_for_text(params.merge(text: query.text))
20
20
  end
21
21
 
22
- resp.results.map(&:place)
22
+ resp.results
23
23
  end
24
24
 
25
25
  private
@@ -49,12 +49,11 @@ module Geocoder
49
49
  end
50
50
 
51
51
  def default_fields
52
- legacy = %w[id reference]
53
52
  basic = %w[business_status formatted_address geometry icon name
54
53
  photos place_id plus_code types]
55
54
  contact = %w[opening_hours]
56
55
  atmosphere = %W[price_level rating user_ratings_total]
57
- format_fields(legacy, basic, contact, atmosphere)
56
+ format_fields(basic, contact, atmosphere)
58
57
  end
59
58
 
60
59
  def format_fields(*fields)
@@ -0,0 +1,62 @@
1
+ require 'geocoder/lookups/base'
2
+ require 'geocoder/results/ip2location_io'
3
+
4
+ module Geocoder::Lookup
5
+ class Ip2locationIo < Base
6
+
7
+ def name
8
+ "IP2LocationIOApi"
9
+ end
10
+
11
+ def required_api_key_parts
12
+ ['key']
13
+ end
14
+
15
+ def supported_protocols
16
+ [:http, :https]
17
+ end
18
+
19
+ private # ----------------------------------------------------------------
20
+
21
+ def base_query_url(query)
22
+ "#{protocol}://api.ip2location.io/?"
23
+ end
24
+
25
+ def query_url_params(query)
26
+ super.merge(
27
+ key: configuration.api_key,
28
+ ip: query.sanitized_text,
29
+ )
30
+ end
31
+
32
+ def results(query)
33
+ # don't look up a loopback or private address, just return the stored result
34
+ return [reserved_result(query.text)] if query.internal_ip_address?
35
+ return [] unless doc = fetch_data(query)
36
+ if doc["response"] == "INVALID ACCOUNT"
37
+ raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "INVALID ACCOUNT")
38
+ return []
39
+ else
40
+ return [doc]
41
+ end
42
+ end
43
+
44
+ def reserved_result(query)
45
+ {
46
+ "ip" => "-",
47
+ "country_code" => "-",
48
+ "country_name" => "-",
49
+ "region_name" => "-",
50
+ "city_name" => "-",
51
+ "latitude" => null,
52
+ "longitude" => null,
53
+ "zip_code" => "-",
54
+ "time_zone" => "-",
55
+ "asn" => "-",
56
+ "as" => "-",
57
+ "is_proxy" => false
58
+ }
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,40 @@
1
+ require 'geocoder/lookups/base'
2
+ require 'geocoder/results/ip2location_lite'
3
+
4
+ module Geocoder
5
+ module Lookup
6
+ class Ip2locationLite < Base
7
+ attr_reader :gem_name
8
+
9
+ def initialize
10
+ unless configuration[:file].nil?
11
+ begin
12
+ @gem_name = 'ip2location_ruby'
13
+ require @gem_name
14
+ rescue LoadError
15
+ raise "Could not load IP2Location DB dependency. To use the IP2LocationLite lookup you must add the #{@gem_name} gem to your Gemfile or have it installed in your system."
16
+ end
17
+ end
18
+ super
19
+ end
20
+
21
+ def name
22
+ 'IP2LocationLite'
23
+ end
24
+
25
+ def required_api_key_parts
26
+ []
27
+ end
28
+
29
+ private
30
+
31
+ def results(query)
32
+ return [] unless configuration[:file]
33
+
34
+ i2l = Ip2location.new.open(configuration[:file].to_s)
35
+ result = i2l.get_all(query.to_s)
36
+ result.nil? ? [] : [result]
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,43 @@
1
+ require 'geocoder/lookups/base'
2
+ require "geocoder/results/pdok_nl"
3
+
4
+ module Geocoder::Lookup
5
+ class PdokNl < Base
6
+
7
+ def name
8
+ 'pdok NL'
9
+ end
10
+
11
+ def supported_protocols
12
+ [:https]
13
+ end
14
+
15
+ private # ---------------------------------------------------------------
16
+
17
+ def cache_key(query)
18
+ base_query_url(query) + hash_to_query(query_url_params(query))
19
+ end
20
+
21
+ def base_query_url(query)
22
+ "#{protocol}://api.pdok.nl/bzk/locatieserver/search/v3_1/free?"
23
+ end
24
+
25
+ def valid_response?(response)
26
+ json = parse_json(response.body)
27
+ super(response) if json
28
+ end
29
+
30
+ def results(query)
31
+ return [] unless doc = fetch_data(query)
32
+ return doc['response']['docs']
33
+ end
34
+
35
+ def query_url_params(query)
36
+ {
37
+ fl: '*',
38
+ q: query.text,
39
+ wt: 'json'
40
+ }.merge(super)
41
+ end
42
+ end
43
+ end
@@ -3,7 +3,8 @@ require 'geocoder/results/base'
3
3
  module Geocoder::Result
4
4
  class AmazonLocationService < Base
5
5
  def initialize(result)
6
- @place = result
6
+ @place = result.place
7
+ super
7
8
  end
8
9
 
9
10
  def coordinates
@@ -53,5 +54,9 @@ module Geocoder::Result
53
54
  def country_code
54
55
  @place.country
55
56
  end
57
+
58
+ def place_id
59
+ data.place_id if data.respond_to?(:place_id)
60
+ end
56
61
  end
57
62
  end
@@ -0,0 +1,21 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Ip2locationIo < Base
5
+
6
+ def address(format = :full)
7
+ "#{city_name} #{zip_code}, #{country_name}".sub(/^[ ,]*/, '')
8
+ end
9
+
10
+ def self.response_attributes
11
+ %w[ip country_code country_name region_name city_name latitude longitude
12
+ zip_code time_zone asn as is_proxy]
13
+ end
14
+
15
+ response_attributes.each do |attr|
16
+ define_method attr do
17
+ @data[attr] || ""
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,47 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Ip2locationLite < Base
5
+
6
+ def coordinates
7
+ [@data[:latitude], @data[:longitude]]
8
+ end
9
+
10
+ def city
11
+ @data[:city]
12
+ end
13
+
14
+ def state
15
+ @data[:region]
16
+ end
17
+
18
+ def state_code
19
+ "" # Not available in Maxmind's database
20
+ end
21
+
22
+ def country
23
+ @data[:country_long]
24
+ end
25
+
26
+ def country_code
27
+ @data[:country_short]
28
+ end
29
+
30
+ def postal_code
31
+ @data[:zipcode]
32
+ end
33
+
34
+ def self.response_attributes
35
+ %w[country_short country_long region latitude longitude isp
36
+ domain netspeed areacode iddcode timezone zipcode weatherstationname
37
+ weatherstationcode mcc mnc mobilebrand elevation usagetype addresstype
38
+ category district asn as]
39
+ end
40
+
41
+ response_attributes.each do |a|
42
+ define_method a do
43
+ @data[a] || ""
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,62 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class PdokNl < Base
5
+
6
+ def response_attributes
7
+ @data
8
+ end
9
+
10
+ def coordinates
11
+ @data['centroide_ll'][6..-2].split(' ').map(&:to_f).reverse
12
+ end
13
+
14
+ def formatted_address
15
+ @data['weergavenaam']
16
+ end
17
+
18
+ alias_method :address, :formatted_address
19
+
20
+ def province
21
+ @data['provincienaam']
22
+ end
23
+
24
+ alias_method :state, :province
25
+
26
+ def city
27
+ @data['woonplaatsnaam']
28
+ end
29
+
30
+ def district
31
+ @data['gemeentenaam']
32
+ end
33
+
34
+ def street
35
+ @data['straatnaam']
36
+ end
37
+
38
+ def street_number
39
+ @data['huis_nlt']
40
+ end
41
+
42
+ def address_components
43
+ @data
44
+ end
45
+
46
+ def state_code
47
+ @data['provinciecode']
48
+ end
49
+
50
+ def postal_code
51
+ @data['postcode']
52
+ end
53
+
54
+ def country
55
+ "Netherlands"
56
+ end
57
+
58
+ def country_code
59
+ "NL"
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.8.2"
2
+ VERSION = "1.8.3"
3
3
  end
@@ -35,6 +35,14 @@ module Geocoder
35
35
  p[s..-1]
36
36
  end
37
37
 
38
+ def archive_edition(package)
39
+ {
40
+ geolite_country_csv: "GeoLite2-Country-CSV",
41
+ geolite_city_csv: "GeoLite2-City-CSV",
42
+ geolite_asn_csv: "GeoLite2-ASN-CSV"
43
+ }[package]
44
+ end
45
+
38
46
  private # -------------------------------------------------------------
39
47
 
40
48
  def table_columns(table_name)
@@ -94,14 +102,6 @@ module Geocoder
94
102
  base_url + archive_url_path(package)
95
103
  end
96
104
 
97
- def archive_edition(package)
98
- {
99
- geolite_country_csv: "GeoLite2-Country-CSV",
100
- geolite_city_csv: "GeoLite2-City-CSV",
101
- geolite_asn_csv: "GeoLite2-ASN-CSV"
102
- }[package]
103
- end
104
-
105
105
  def base_url(edition)
106
106
  "https://download.maxmind.com/app/geoip_download?edition_id=#{edition}&license_key=#{ENV['LICENSE_KEY']}&suffix=zip"
107
107
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geocoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-04 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: base64
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: csv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
13
41
  description: Object geocoding (by street or IP address), reverse geocoding (coordinates
14
42
  to street address), distance queries for ActiveRecord and Mongoid, result caching,
15
43
  and more. Designed for Rails but works with Sinatra and other Rack frameworks too.
@@ -60,7 +88,6 @@ files:
60
88
  - lib/geocoder/lookups/base.rb
61
89
  - lib/geocoder/lookups/bing.rb
62
90
  - lib/geocoder/lookups/db_ip_com.rb
63
- - lib/geocoder/lookups/dstk.rb
64
91
  - lib/geocoder/lookups/esri.rb
65
92
  - lib/geocoder/lookups/freegeoip.rb
66
93
  - lib/geocoder/lookups/geoapify.rb
@@ -74,6 +101,8 @@ files:
74
101
  - lib/geocoder/lookups/google_premier.rb
75
102
  - lib/geocoder/lookups/here.rb
76
103
  - lib/geocoder/lookups/ip2location.rb
104
+ - lib/geocoder/lookups/ip2location_io.rb
105
+ - lib/geocoder/lookups/ip2location_lite.rb
77
106
  - lib/geocoder/lookups/ipapi_com.rb
78
107
  - lib/geocoder/lookups/ipbase.rb
79
108
  - lib/geocoder/lookups/ipdata_co.rb
@@ -95,6 +124,7 @@ files:
95
124
  - lib/geocoder/lookups/opencagedata.rb
96
125
  - lib/geocoder/lookups/osmnames.rb
97
126
  - lib/geocoder/lookups/pc_miler.rb
127
+ - lib/geocoder/lookups/pdok_nl.rb
98
128
  - lib/geocoder/lookups/pelias.rb
99
129
  - lib/geocoder/lookups/photon.rb
100
130
  - lib/geocoder/lookups/pickpoint.rb
@@ -125,7 +155,6 @@ files:
125
155
  - lib/geocoder/results/base.rb
126
156
  - lib/geocoder/results/bing.rb
127
157
  - lib/geocoder/results/db_ip_com.rb
128
- - lib/geocoder/results/dstk.rb
129
158
  - lib/geocoder/results/esri.rb
130
159
  - lib/geocoder/results/freegeoip.rb
131
160
  - lib/geocoder/results/geoapify.rb
@@ -139,6 +168,8 @@ files:
139
168
  - lib/geocoder/results/google_premier.rb
140
169
  - lib/geocoder/results/here.rb
141
170
  - lib/geocoder/results/ip2location.rb
171
+ - lib/geocoder/results/ip2location_io.rb
172
+ - lib/geocoder/results/ip2location_lite.rb
142
173
  - lib/geocoder/results/ipapi_com.rb
143
174
  - lib/geocoder/results/ipbase.rb
144
175
  - lib/geocoder/results/ipdata_co.rb
@@ -160,6 +191,7 @@ files:
160
191
  - lib/geocoder/results/opencagedata.rb
161
192
  - lib/geocoder/results/osmnames.rb
162
193
  - lib/geocoder/results/pc_miler.rb
194
+ - lib/geocoder/results/pdok_nl.rb
163
195
  - lib/geocoder/results/pelias.rb
164
196
  - lib/geocoder/results/photon.rb
165
197
  - lib/geocoder/results/pickpoint.rb
@@ -1,22 +0,0 @@
1
- # More information about the Data Science Toolkit can be found at:
2
- # http://www.datasciencetoolkit.org/. The provided APIs mimic the
3
- # Google geocoding api.
4
-
5
- require 'geocoder/lookups/google'
6
- require 'geocoder/results/dstk'
7
-
8
- module Geocoder::Lookup
9
- class Dstk < Google
10
-
11
- def name
12
- "Data Science Toolkit"
13
- end
14
-
15
- private # ----------------------------------------------------------------
16
-
17
- def base_query_url(query)
18
- host = configuration[:host] || "www.datasciencetoolkit.org"
19
- "#{protocol}://#{host}/maps/api/geocode/json?"
20
- end
21
- end
22
- end
@@ -1,6 +0,0 @@
1
- require 'geocoder/results/google'
2
-
3
- module Geocoder::Result
4
- class Dstk < Google
5
- end
6
- end