geocoder 1.8.0 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +3 -5
- data/lib/geocoder/cache.rb +3 -3
- data/lib/geocoder/configuration.rb +4 -0
- data/lib/geocoder/ip_address.rb +5 -2
- data/lib/geocoder/lookup.rb +6 -4
- data/lib/geocoder/lookups/amap.rb +2 -2
- data/lib/geocoder/lookups/amazon_location_service.rb +4 -3
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +1 -1
- data/lib/geocoder/lookups/esri.rb +18 -5
- data/lib/geocoder/lookups/geoapify.rb +7 -1
- data/lib/geocoder/lookups/geoportail_lu.rb +1 -1
- data/lib/geocoder/lookups/ipbase.rb +49 -0
- data/lib/geocoder/lookups/pc_miler.rb +85 -0
- data/lib/geocoder/lookups/test.rb +1 -0
- data/lib/geocoder/lookups/yandex.rb +3 -3
- data/lib/geocoder/results/ban_data_gouv_fr.rb +1 -1
- data/lib/geocoder/results/ipbase.rb +40 -0
- data/lib/geocoder/results/pc_miler.rb +98 -0
- data/lib/geocoder/version.rb +1 -1
- data/lib/maxmind_database.rb +8 -8
- data/lib/tasks/maxmind.rake +1 -1
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26c7b5c88c38ee619a8fdc7452014b9601db83539334353758d451d2b300faf2
|
4
|
+
data.tar.gz: 873c8a8148b792c43302b921665880d2f4b54cdc8ad7e4698fafee4e2a24c8b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8fc1e15bfb40407c0f3bcd31030defaf9af58be2c7c49d84efaa5b8ce3828cafd54d3c2a63d08920db4f2701934ac6c3ac9df52888c27fbfd8a05036da11bb5
|
7
|
+
data.tar.gz: 1114e5142f8e8e358fa143fb143b0ea833c611bc2ab92bcbe0d04dc62d0965d46149651d7c3847f967c76a5997a3fba1d0d43a997aee2287268a48ac041e08c7
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,17 @@ 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.2 (2023 Jul 4)
|
7
|
+
-------------------
|
8
|
+
* Add support for PC Miler lookup (thanks github.com/alexdean).
|
9
|
+
* Minor fixes for :maxmind_local, :esri, and :ban_data_gouv_fr lookups.
|
10
|
+
|
11
|
+
1.8.1 (2022 Sep 23)
|
12
|
+
-------------------
|
13
|
+
* Add support for IPBase lookup (thanks github.com/jonallured).
|
14
|
+
* Test cleanup (thanks github.com/jonallured).
|
15
|
+
* Prevent errors when existing constant name shadows a lookup class (thanks github.com/avram-twitch).
|
16
|
+
|
6
17
|
1.8.0 (2022 May 17)
|
7
18
|
-------------------
|
8
19
|
* Add support for 2GIS lookup (thanks github.com/ggrikgg).
|
data/README.md
CHANGED
@@ -5,7 +5,6 @@ Geocoder
|
|
5
5
|
|
6
6
|
[](http://badge.fury.io/rb/geocoder)
|
7
7
|
[](https://codeclimate.com/github/alexreisner/geocoder)
|
8
|
-
[](https://travis-ci.com/alexreisner/geocoder)
|
9
8
|
|
10
9
|
Key features:
|
11
10
|
|
@@ -368,7 +367,7 @@ If you need to expire cached content:
|
|
368
367
|
```ruby
|
369
368
|
Geocoder::Lookup.get(Geocoder.config[:lookup]).cache.expire(:all) # expire cached results for current Lookup
|
370
369
|
Geocoder::Lookup.get(:nominatim).cache.expire("http://...") # expire cached result for a specific URL
|
371
|
-
Geocoder::Lookup.get(:nominatim).cache.expire(:all) # expire cached results for
|
370
|
+
Geocoder::Lookup.get(:nominatim).cache.expire(:all) # expire cached results for Nominatim
|
372
371
|
# expire all cached results for all Lookups.
|
373
372
|
# Be aware that this methods spawns a new Lookup object for each Service
|
374
373
|
Geocoder::Lookup.all_services.each{|service| Geocoder::Lookup.get(service).cache.expire(:all)}
|
@@ -376,10 +375,9 @@ Geocoder::Lookup.all_services.each{|service| Geocoder::Lookup.get(service).cache
|
|
376
375
|
|
377
376
|
Do *not* include the prefix when passing a URL to be expired. Expiring `:all` will only expire keys with the configured prefix -- it will *not* expire every entry in your key/value store.
|
378
377
|
|
379
|
-
For an example of a cache store with URL expiry, please see examples/autoexpire_cache.rb
|
380
|
-
|
381
378
|
_Before you implement caching in your app please be sure that doing so does not violate the Terms of Service for your geocoding service._
|
382
379
|
|
380
|
+
Not all services support caching, [check the service limitations in the API guide for more information](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md).
|
383
381
|
|
384
382
|
Advanced Model Configuration
|
385
383
|
----------------------------
|
@@ -747,7 +745,7 @@ If your application requires quick geocoding responses you will probably need to
|
|
747
745
|
|
748
746
|
For IP address lookups in Rails applications, it is generally NOT a good idea to run `request.location` during a synchronous page load without understanding the speed/behavior of your configured lookup. If the lookup becomes slow, so will your website.
|
749
747
|
|
750
|
-
For the most part, the speed of geocoding requests has little to do with the Geocoder gem. Please take the time to learn about your configured lookup
|
748
|
+
For the most part, the speed of geocoding requests has little to do with the Geocoder gem. Please take the time to learn about your configured lookup before posting performance-related issues.
|
751
749
|
|
752
750
|
### Unexpected Responses from Geocoding Services
|
753
751
|
|
data/lib/geocoder/cache.rb
CHANGED
@@ -4,7 +4,7 @@ module Geocoder
|
|
4
4
|
class Cache
|
5
5
|
|
6
6
|
def initialize(store, config)
|
7
|
-
@class = (
|
7
|
+
@class = (Geocoder::CacheStore.const_get("#{store.class}", false) rescue Geocoder::CacheStore::Generic)
|
8
8
|
@store_service = @class.new(store, config)
|
9
9
|
end
|
10
10
|
|
@@ -14,7 +14,7 @@ module Geocoder
|
|
14
14
|
def [](url)
|
15
15
|
interpret store_service.read(url)
|
16
16
|
rescue => e
|
17
|
-
warn "Geocoder cache read error: #{e}"
|
17
|
+
Geocoder.log(:warn, "Geocoder cache read error: #{e}")
|
18
18
|
end
|
19
19
|
|
20
20
|
##
|
@@ -23,7 +23,7 @@ module Geocoder
|
|
23
23
|
def []=(url, value)
|
24
24
|
store_service.write(url, value)
|
25
25
|
rescue => e
|
26
|
-
warn "Geocoder cache write error: #{e}"
|
26
|
+
Geocoder.log(:warn, "Geocoder cache write error: #{e}")
|
27
27
|
end
|
28
28
|
|
29
29
|
##
|
data/lib/geocoder/ip_address.rb
CHANGED
data/lib/geocoder/lookup.rb
CHANGED
@@ -66,7 +66,8 @@ module Geocoder
|
|
66
66
|
:amazon_location_service,
|
67
67
|
:geoapify,
|
68
68
|
:photon,
|
69
|
-
:twogis
|
69
|
+
:twogis,
|
70
|
+
:pc_miler
|
70
71
|
]
|
71
72
|
end
|
72
73
|
|
@@ -92,7 +93,8 @@ module Geocoder
|
|
92
93
|
:ipstack,
|
93
94
|
:ip2location,
|
94
95
|
:ipgeolocation,
|
95
|
-
:ipqualityscore
|
96
|
+
:ipqualityscore,
|
97
|
+
:ipbase
|
96
98
|
]
|
97
99
|
end
|
98
100
|
|
@@ -137,9 +139,9 @@ module Geocoder
|
|
137
139
|
# Safely instantiate Lookup
|
138
140
|
#
|
139
141
|
def instantiate_lookup(name)
|
140
|
-
class_name =
|
142
|
+
class_name = classify_name(name)
|
141
143
|
begin
|
142
|
-
Geocoder::Lookup.const_get(class_name)
|
144
|
+
Geocoder::Lookup.const_get(class_name, inherit=false)
|
143
145
|
rescue NameError
|
144
146
|
require "geocoder/lookups/#{name}"
|
145
147
|
end
|
@@ -32,10 +32,10 @@ module Geocoder::Lookup
|
|
32
32
|
return doc['geocodes'] unless doc['geocodes'].blank?
|
33
33
|
when ['0', 'INVALID_USER_KEY']
|
34
34
|
raise_error(Geocoder::InvalidApiKey, "invalid api key") ||
|
35
|
-
warn
|
35
|
+
Geocoder.log(:warn, "#{self.name} Geocoding API error: invalid api key.")
|
36
36
|
else
|
37
37
|
raise_error(Geocoder::Error, "server error.") ||
|
38
|
-
warn
|
38
|
+
Geocoder.log(:warn, "#{self.name} Geocoding API error: server error - [#{doc['info']}]")
|
39
39
|
end
|
40
40
|
return []
|
41
41
|
end
|
@@ -29,10 +29,11 @@ module Geocoder::Lookup
|
|
29
29
|
require_sdk
|
30
30
|
keys = configuration.api_key
|
31
31
|
if keys
|
32
|
-
@client = Aws::LocationService::Client.new(
|
32
|
+
@client = Aws::LocationService::Client.new(**{
|
33
|
+
region: keys[:region],
|
33
34
|
access_key_id: keys[:access_key_id],
|
34
|
-
secret_access_key: keys[:secret_access_key]
|
35
|
-
)
|
35
|
+
secret_access_key: keys[:secret_access_key]
|
36
|
+
}.compact)
|
36
37
|
else
|
37
38
|
@client = Aws::LocationService::Client.new
|
38
39
|
end
|
@@ -125,7 +125,7 @@ module Geocoder::Lookup
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def type_param_is_valid?(param)
|
128
|
-
%w(housenumber street locality
|
128
|
+
%w(housenumber street locality municipality).include?(param.downcase)
|
129
129
|
end
|
130
130
|
|
131
131
|
def code_param_is_valid?(param)
|
@@ -23,15 +23,28 @@ module Geocoder::Lookup
|
|
23
23
|
def results(query)
|
24
24
|
return [] unless doc = fetch_data(query)
|
25
25
|
|
26
|
-
if (!query.reverse_geocode?)
|
27
|
-
return [] if !doc['locations'] || doc['locations'].empty?
|
28
|
-
end
|
29
|
-
|
30
26
|
if (doc['error'].nil?)
|
27
|
+
if (!query.reverse_geocode?)
|
28
|
+
return [] if !doc['locations'] || doc['locations'].empty?
|
29
|
+
end
|
31
30
|
return [ doc ]
|
32
31
|
else
|
33
|
-
|
32
|
+
case [ doc['error']['code'] ]
|
33
|
+
when [498]
|
34
|
+
raise_error(Geocoder::InvalidApiKey, doc['error']['message']) ||
|
35
|
+
Geocoder.log(:warn, "#{self.name} Geocoding API error: #{doc['error']['message']}")
|
36
|
+
when [ 403 ]
|
37
|
+
raise_error(Geocoder::RequestDenied, 'ESRI request denied') ||
|
38
|
+
Geocoder.log(:warn, "#{self.name} ESRI request denied: #{doc['error']['message']}")
|
39
|
+
when [ 500 ], [501]
|
40
|
+
raise_error(Geocoder::ServiceUnavailable, 'ESRI service unavailable') ||
|
41
|
+
Geocoder.log(:warn, "#{self.name} ESRI service error: #{doc['error']['message']}")
|
42
|
+
else
|
43
|
+
raise_error(Geocoder::Error, doc['error']['message']) ||
|
44
|
+
Geocoder.log(:warn, "#{self.name} Geocoding error: #{doc['error']['message']}")
|
45
|
+
end
|
34
46
|
end
|
47
|
+
return []
|
35
48
|
end
|
36
49
|
|
37
50
|
def query_url_params(query)
|
@@ -22,7 +22,13 @@ module Geocoder
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def base_query_url(query)
|
25
|
-
method = query.reverse_geocode?
|
25
|
+
method = if query.reverse_geocode?
|
26
|
+
'reverse'
|
27
|
+
elsif query.options[:autocomplete]
|
28
|
+
'autocomplete'
|
29
|
+
else
|
30
|
+
'search'
|
31
|
+
end
|
26
32
|
"https://api.geoapify.com/v1/geocode/#{method}?"
|
27
33
|
end
|
28
34
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require 'geocoder/results/ipbase'
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class Ipbase < Base
|
6
|
+
|
7
|
+
def name
|
8
|
+
"ipbase.com"
|
9
|
+
end
|
10
|
+
|
11
|
+
def supported_protocols
|
12
|
+
[:https]
|
13
|
+
end
|
14
|
+
|
15
|
+
private # ---------------------------------------------------------------
|
16
|
+
|
17
|
+
def base_query_url(query)
|
18
|
+
"https://api.ipbase.com/v2/info?"
|
19
|
+
end
|
20
|
+
|
21
|
+
def query_url_params(query)
|
22
|
+
{
|
23
|
+
:ip => query.sanitized_text,
|
24
|
+
:apikey => configuration.api_key
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def results(query)
|
29
|
+
# don't look up a loopback or private address, just return the stored result
|
30
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
31
|
+
doc = fetch_data(query) || {}
|
32
|
+
doc.fetch("data", {})["location"] ? [doc] : []
|
33
|
+
end
|
34
|
+
|
35
|
+
def reserved_result(ip)
|
36
|
+
{
|
37
|
+
"data" => {
|
38
|
+
"ip" => ip,
|
39
|
+
"location" => {
|
40
|
+
"city" => { "name" => "" },
|
41
|
+
"country" => { "alpha2" => "RD", "name" => "Reserved" },
|
42
|
+
"region" => { "alpha2" => "", "name" => "" },
|
43
|
+
"zip" => ""
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require "geocoder/results/pc_miler"
|
3
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
|
4
|
+
|
5
|
+
module Geocoder::Lookup
|
6
|
+
class PcMiler < Base
|
7
|
+
|
8
|
+
# https://developer.trimblemaps.com/restful-apis/location/single-search/single-search-api/#test-the-api-now
|
9
|
+
def valid_region_codes
|
10
|
+
# AF: Africa
|
11
|
+
# AS: Asia
|
12
|
+
# EU: Europe
|
13
|
+
# NA: North America
|
14
|
+
# OC: Oceania
|
15
|
+
# SA: South America
|
16
|
+
%w[AF AS EU NA OC SA]
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
"PCMiler"
|
21
|
+
end
|
22
|
+
|
23
|
+
private # ---------------------------------------------------------------
|
24
|
+
|
25
|
+
def base_query_url(query)
|
26
|
+
region_code = region(query)
|
27
|
+
if !valid_region_codes.include?(region_code)
|
28
|
+
raise "region_code '#{region_code}' is invalid. use one of #{valid_region_codes}." \
|
29
|
+
"https://developer.trimblemaps.com/restful-apis/location/single-search/single-search-api/#test-the-api-now"
|
30
|
+
end
|
31
|
+
|
32
|
+
"#{protocol}://singlesearch.alk.com/#{region_code}/api/search?"
|
33
|
+
end
|
34
|
+
|
35
|
+
def results(query)
|
36
|
+
return [] unless data = fetch_data(query)
|
37
|
+
if data['Locations']
|
38
|
+
add_metadata_to_locations!(data)
|
39
|
+
data['Locations']
|
40
|
+
else
|
41
|
+
[]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_metadata_to_locations!(data)
|
46
|
+
confidence = data['QueryConfidence']
|
47
|
+
data['Locations'].each do |location|
|
48
|
+
location['QueryConfidence'] = confidence
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def query_url_params(query)
|
53
|
+
if query.reverse_geocode?
|
54
|
+
lat,lon = query.coordinates
|
55
|
+
formatted_query = "#{CGI.escape(lat)},#{CGI.escape(lon)}"
|
56
|
+
else
|
57
|
+
formatted_query = query.text.to_s
|
58
|
+
end
|
59
|
+
|
60
|
+
{
|
61
|
+
authToken: configuration.api_key,
|
62
|
+
query: formatted_query,
|
63
|
+
# to add additional metadata to response such as QueryConfidence
|
64
|
+
include: 'Meta'
|
65
|
+
}.merge(super(query))
|
66
|
+
end
|
67
|
+
|
68
|
+
def region(query)
|
69
|
+
query.options[:region] || query.options['region'] || configuration[:region] || "NA"
|
70
|
+
end
|
71
|
+
|
72
|
+
def check_response_for_errors!(response)
|
73
|
+
if response.code.to_i == 403
|
74
|
+
raise_error(Geocoder::RequestDenied) ||
|
75
|
+
Geocoder.log(:warn, "Geocoding API error: 403 API key does not exist")
|
76
|
+
else
|
77
|
+
super(response)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def supported_protocols
|
82
|
+
[:https]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -24,11 +24,11 @@ module Geocoder::Lookup
|
|
24
24
|
|
25
25
|
def results(query)
|
26
26
|
return [] unless doc = fetch_data(query)
|
27
|
-
if
|
28
|
-
if
|
27
|
+
if [400, 403].include? doc['statusCode']
|
28
|
+
if doc['statusCode'] == 403 and doc['message'] == 'Invalid key'
|
29
29
|
raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid API key.")
|
30
30
|
else
|
31
|
-
Geocoder.log(:warn, "Yandex Geocoding API error: #{
|
31
|
+
Geocoder.log(:warn, "Yandex Geocoding API error: #{doc['statusCode']} (#{doc['message']}).")
|
32
32
|
end
|
33
33
|
return []
|
34
34
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Ipbase < Base
|
5
|
+
def ip
|
6
|
+
@data["data"]['ip']
|
7
|
+
end
|
8
|
+
|
9
|
+
def country_code
|
10
|
+
@data["data"]["location"]["country"]["alpha2"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def country
|
14
|
+
@data["data"]["location"]["country"]["name"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def state_code
|
18
|
+
@data["data"]["location"]["region"]["alpha2"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def state
|
22
|
+
@data["data"]["location"]["region"]["name"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def city
|
26
|
+
@data["data"]["location"]["city"]["name"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def postal_code
|
30
|
+
@data["data"]["location"]["zip"]
|
31
|
+
end
|
32
|
+
|
33
|
+
def coordinates
|
34
|
+
[
|
35
|
+
@data["data"]["location"]["latitude"].to_f,
|
36
|
+
@data["data"]["location"]["longitude"].to_f
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class PcMiler < Base
|
5
|
+
# sample response:
|
6
|
+
# https://singlesearch.alk.com/na/api/search?authToken=<TOKEN>&include=Meta&query=Feasterville
|
7
|
+
#
|
8
|
+
# {
|
9
|
+
# "Err": 0,
|
10
|
+
# "ErrString": "OK",
|
11
|
+
# "QueryConfidence": 1,
|
12
|
+
# "TimeInMilliseconds": 93,
|
13
|
+
# "GridDataVersion": "GRD_ALK.NA.2023.01.18.29.1.1",
|
14
|
+
# "CommitID": "pcmws-22.08.11.0-1778-g586da49bd1b: 05/30/2023 20:14",
|
15
|
+
# "Locations": [
|
16
|
+
# {
|
17
|
+
# "Address": {
|
18
|
+
# "StreetAddress": "",
|
19
|
+
# "LocalArea": "",
|
20
|
+
# "City": "Feasterville",
|
21
|
+
# "State": "PA",
|
22
|
+
# "StateName": "Pennsylvania",
|
23
|
+
# "Zip": "19053",
|
24
|
+
# "County": "Bucks",
|
25
|
+
# "Country": "US",
|
26
|
+
# "CountryFullName": "United States",
|
27
|
+
# "SPLC": null
|
28
|
+
# },
|
29
|
+
# "Coords": {
|
30
|
+
# "Lat": "40.150025",
|
31
|
+
# "Lon": "-75.002511"
|
32
|
+
# },
|
33
|
+
# "StreetCoords": {
|
34
|
+
# "Lat": "40.150098",
|
35
|
+
# "Lon": "-75.002827"
|
36
|
+
# },
|
37
|
+
# "Region": 4,
|
38
|
+
# "POITypeID": 0,
|
39
|
+
# "PersistentPOIID": -1,
|
40
|
+
# "SiteID": -1,
|
41
|
+
# "ResultType": 4,
|
42
|
+
# "ShortString": "Feasterville",
|
43
|
+
# "GridID": 37172748,
|
44
|
+
# "LinkID": 188,
|
45
|
+
# "Percent": 6291,
|
46
|
+
# "TimeZone": "GMT-4:00 EDT"
|
47
|
+
# }
|
48
|
+
# ]
|
49
|
+
# }
|
50
|
+
|
51
|
+
def address(format=:unused)
|
52
|
+
[street, city, state, postal_code, country]
|
53
|
+
.map { |i| i == '' ? nil : i }
|
54
|
+
.compact
|
55
|
+
.join(', ')
|
56
|
+
end
|
57
|
+
|
58
|
+
def coordinates
|
59
|
+
coords = data["Coords"] || {}
|
60
|
+
[coords["Lat"].to_f, coords["Lon"].to_f]
|
61
|
+
end
|
62
|
+
|
63
|
+
def street
|
64
|
+
address_data["StreetAddress"]
|
65
|
+
end
|
66
|
+
|
67
|
+
def city
|
68
|
+
address_data["City"]
|
69
|
+
end
|
70
|
+
|
71
|
+
def state
|
72
|
+
address_data["StateName"]
|
73
|
+
end
|
74
|
+
|
75
|
+
def state_code
|
76
|
+
address_data["State"]
|
77
|
+
end
|
78
|
+
|
79
|
+
def postal_code
|
80
|
+
address_data["Zip"]
|
81
|
+
end
|
82
|
+
|
83
|
+
def country
|
84
|
+
address_data["CountryFullName"]
|
85
|
+
end
|
86
|
+
|
87
|
+
def country_code
|
88
|
+
address_data["Country"]
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def address_data
|
94
|
+
data["Address"] || {}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
data/lib/geocoder/version.rb
CHANGED
data/lib/maxmind_database.rb
CHANGED
@@ -6,9 +6,9 @@ module Geocoder
|
|
6
6
|
extend self
|
7
7
|
|
8
8
|
def download(package, dir = "tmp")
|
9
|
-
filepath = File.expand_path(File.join(dir,
|
9
|
+
filepath = File.expand_path(File.join(dir, "#{archive_edition(package)}.zip"))
|
10
10
|
open(filepath, 'wb') do |file|
|
11
|
-
uri = URI.parse(
|
11
|
+
uri = URI.parse(base_url(package))
|
12
12
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
13
13
|
http.request_get(uri.path) do |resp|
|
14
14
|
# TODO: show progress
|
@@ -94,16 +94,16 @@ module Geocoder
|
|
94
94
|
base_url + archive_url_path(package)
|
95
95
|
end
|
96
96
|
|
97
|
-
def
|
97
|
+
def archive_edition(package)
|
98
98
|
{
|
99
|
-
geolite_country_csv: "GeoLite2-Country-CSV
|
100
|
-
geolite_city_csv: "GeoLite2-City-CSV
|
101
|
-
geolite_asn_csv: "GeoLite2-ASN-CSV
|
99
|
+
geolite_country_csv: "GeoLite2-Country-CSV",
|
100
|
+
geolite_city_csv: "GeoLite2-City-CSV",
|
101
|
+
geolite_asn_csv: "GeoLite2-ASN-CSV"
|
102
102
|
}[package]
|
103
103
|
end
|
104
104
|
|
105
|
-
def base_url
|
106
|
-
"
|
105
|
+
def base_url(edition)
|
106
|
+
"https://download.maxmind.com/app/geoip_download?edition_id=#{edition}&license_key=#{ENV['LICENSE_KEY']}&suffix=zip"
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
data/lib/tasks/maxmind.rake
CHANGED
@@ -54,7 +54,7 @@ module MaxmindTask
|
|
54
54
|
end
|
55
55
|
require 'fileutils'
|
56
56
|
p = "geolite_#{package}_csv".intern
|
57
|
-
archive_filename = Geocoder::MaxmindDatabase.
|
57
|
+
archive_filename = "#{Geocoder::MaxmindDatabase.archive_edition(p)}.zip"
|
58
58
|
Zip::File.open(File.join(options[:dir], archive_filename)).each do |entry|
|
59
59
|
filepath = File.join(options[:dir], entry.name)
|
60
60
|
if File.exist? filepath
|
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.8.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Reisner
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Object geocoding (by street or IP address), reverse geocoding (coordinates
|
14
14
|
to street address), distance queries for ActiveRecord and Mongoid, result caching,
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/geocoder/lookups/here.rb
|
76
76
|
- lib/geocoder/lookups/ip2location.rb
|
77
77
|
- lib/geocoder/lookups/ipapi_com.rb
|
78
|
+
- lib/geocoder/lookups/ipbase.rb
|
78
79
|
- lib/geocoder/lookups/ipdata_co.rb
|
79
80
|
- lib/geocoder/lookups/ipgeolocation.rb
|
80
81
|
- lib/geocoder/lookups/ipinfo_io.rb
|
@@ -93,6 +94,7 @@ files:
|
|
93
94
|
- lib/geocoder/lookups/nominatim.rb
|
94
95
|
- lib/geocoder/lookups/opencagedata.rb
|
95
96
|
- lib/geocoder/lookups/osmnames.rb
|
97
|
+
- lib/geocoder/lookups/pc_miler.rb
|
96
98
|
- lib/geocoder/lookups/pelias.rb
|
97
99
|
- lib/geocoder/lookups/photon.rb
|
98
100
|
- lib/geocoder/lookups/pickpoint.rb
|
@@ -138,6 +140,7 @@ files:
|
|
138
140
|
- lib/geocoder/results/here.rb
|
139
141
|
- lib/geocoder/results/ip2location.rb
|
140
142
|
- lib/geocoder/results/ipapi_com.rb
|
143
|
+
- lib/geocoder/results/ipbase.rb
|
141
144
|
- lib/geocoder/results/ipdata_co.rb
|
142
145
|
- lib/geocoder/results/ipgeolocation.rb
|
143
146
|
- lib/geocoder/results/ipinfo_io.rb
|
@@ -156,6 +159,7 @@ files:
|
|
156
159
|
- lib/geocoder/results/nominatim.rb
|
157
160
|
- lib/geocoder/results/opencagedata.rb
|
158
161
|
- lib/geocoder/results/osmnames.rb
|
162
|
+
- lib/geocoder/results/pc_miler.rb
|
159
163
|
- lib/geocoder/results/pelias.rb
|
160
164
|
- lib/geocoder/results/photon.rb
|
161
165
|
- lib/geocoder/results/pickpoint.rb
|
@@ -186,7 +190,7 @@ licenses:
|
|
186
190
|
metadata:
|
187
191
|
source_code_uri: https://github.com/alexreisner/geocoder
|
188
192
|
changelog_uri: https://github.com/alexreisner/geocoder/blob/master/CHANGELOG.md
|
189
|
-
post_install_message:
|
193
|
+
post_install_message:
|
190
194
|
rdoc_options: []
|
191
195
|
require_paths:
|
192
196
|
- lib
|
@@ -201,8 +205,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
205
|
- !ruby/object:Gem::Version
|
202
206
|
version: '0'
|
203
207
|
requirements: []
|
204
|
-
rubygems_version: 3.
|
205
|
-
signing_key:
|
208
|
+
rubygems_version: 3.3.26
|
209
|
+
signing_key:
|
206
210
|
specification_version: 4
|
207
211
|
summary: Complete geocoding solution for Ruby.
|
208
212
|
test_files: []
|