geocoder 1.8.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -4
- data/lib/geocoder/cache.rb +1 -1
- data/lib/geocoder/ip_address.rb +5 -2
- data/lib/geocoder/lookup.rb +2 -1
- 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/pc_miler.rb +85 -0
- data/lib/geocoder/results/ban_data_gouv_fr.rb +1 -1
- 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 +8 -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,11 @@ 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
|
+
|
6
11
|
1.8.1 (2022 Sep 23)
|
7
12
|
-------------------
|
8
13
|
* Add support for IPBase lookup (thanks github.com/jonallured).
|
data/README.md
CHANGED
@@ -5,7 +5,6 @@ Geocoder
|
|
5
5
|
|
6
6
|
[![Gem Version](https://badge.fury.io/rb/geocoder.svg)](http://badge.fury.io/rb/geocoder)
|
7
7
|
[![Code Climate](https://codeclimate.com/github/alexreisner/geocoder/badges/gpa.svg)](https://codeclimate.com/github/alexreisner/geocoder)
|
8
|
-
[![Build Status](https://travis-ci.com/alexreisner/geocoder.svg?branch=master)](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
|
----------------------------
|
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
|
|
data/lib/geocoder/ip_address.rb
CHANGED
data/lib/geocoder/lookup.rb
CHANGED
@@ -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)
|
@@ -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
|
@@ -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,
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/geocoder/lookups/nominatim.rb
|
95
95
|
- lib/geocoder/lookups/opencagedata.rb
|
96
96
|
- lib/geocoder/lookups/osmnames.rb
|
97
|
+
- lib/geocoder/lookups/pc_miler.rb
|
97
98
|
- lib/geocoder/lookups/pelias.rb
|
98
99
|
- lib/geocoder/lookups/photon.rb
|
99
100
|
- lib/geocoder/lookups/pickpoint.rb
|
@@ -158,6 +159,7 @@ files:
|
|
158
159
|
- lib/geocoder/results/nominatim.rb
|
159
160
|
- lib/geocoder/results/opencagedata.rb
|
160
161
|
- lib/geocoder/results/osmnames.rb
|
162
|
+
- lib/geocoder/results/pc_miler.rb
|
161
163
|
- lib/geocoder/results/pelias.rb
|
162
164
|
- lib/geocoder/results/photon.rb
|
163
165
|
- lib/geocoder/results/pickpoint.rb
|
@@ -188,7 +190,7 @@ licenses:
|
|
188
190
|
metadata:
|
189
191
|
source_code_uri: https://github.com/alexreisner/geocoder
|
190
192
|
changelog_uri: https://github.com/alexreisner/geocoder/blob/master/CHANGELOG.md
|
191
|
-
post_install_message:
|
193
|
+
post_install_message:
|
192
194
|
rdoc_options: []
|
193
195
|
require_paths:
|
194
196
|
- lib
|
@@ -203,8 +205,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
205
|
- !ruby/object:Gem::Version
|
204
206
|
version: '0'
|
205
207
|
requirements: []
|
206
|
-
rubygems_version: 3.
|
207
|
-
signing_key:
|
208
|
+
rubygems_version: 3.3.26
|
209
|
+
signing_key:
|
208
210
|
specification_version: 4
|
209
211
|
summary: Complete geocoding solution for Ruby.
|
210
212
|
test_files: []
|