geocoder 1.8.3 → 1.8.5
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 +9 -0
- data/README.md +3 -0
- data/lib/geocoder/lookup.rb +1 -0
- data/lib/geocoder/lookups/amazon_location_service.rb +6 -3
- data/lib/geocoder/lookups/azure.rb +56 -0
- data/lib/geocoder/lookups/bing.rb +1 -1
- data/lib/geocoder/lookups/mapbox.rb +3 -3
- data/lib/geocoder/lookups/photon.rb +1 -1
- data/lib/geocoder/query.rb +1 -1
- data/lib/geocoder/results/azure.rb +65 -0
- data/lib/geocoder/results/mapbox.rb +27 -9
- data/lib/geocoder/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdb45130990fbb878a93ceb3e68729abce378f50a6bc5ebda0b77cbaae60156c
|
4
|
+
data.tar.gz: 1d65925f76418f4023db18f3422450b831f4501715e0ff8c645dba67820766dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 974c3eb6c880fdcdf316e1fb93dae18f5d6bf486f0a6ae3a7cba5629404e69cba64a5005bd0a7d86682be5d535fa4d772a7fab7a69b5e975bf9679c7d682a5aa
|
7
|
+
data.tar.gz: 80e8c1de0e969b7c8353bfb760cc807ec3469529e36bd388873d84f3d8a53c5a74e58bcbb9da07f1f014538c284fe012c36d6ada9930170d7d987a656dd95f3d
|
data/CHANGELOG.md
CHANGED
@@ -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.8.5 (2024 Dec 18)
|
7
|
+
-------------------
|
8
|
+
* Fix bug when working with IPAddr objects (thanks github.com/ledermann and github.com/mattlemx).
|
9
|
+
|
10
|
+
1.8.4 (2024 Dec 4)
|
11
|
+
-------------------
|
12
|
+
* Add support for Azure lookup (thanks github.com/AhlOct).
|
13
|
+
* Several fixes for Mapbox and Bing lookups (thanks github.com/tmh-dev and github.com/iBlackShadow).
|
14
|
+
|
6
15
|
1.8.3 (2024 May 2)
|
7
16
|
-------------------
|
8
17
|
* Add support for IP2Location LITE lookup (thanks github.com/ip2location).
|
data/README.md
CHANGED
@@ -375,6 +375,9 @@ Geocoder::Lookup.all_services.each{|service| Geocoder::Lookup.get(service).cache
|
|
375
375
|
|
376
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.
|
377
377
|
|
378
|
+
In addition to conventional cache stores like Redis, it's possible to keep your cache in the database using `ActiveRecord`. For example see [this gist](https://gist.github.com/shqear93/4b07153b4ca7e4e4a41da492679f6c0e).
|
379
|
+
|
380
|
+
|
378
381
|
_Before you implement caching in your app please be sure that doing so does not violate the Terms of Service for your geocoding service._
|
379
382
|
|
380
383
|
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).
|
data/lib/geocoder/lookup.rb
CHANGED
@@ -11,14 +11,17 @@ module Geocoder::Lookup
|
|
11
11
|
params.merge!(index_name: configuration[:index_name])
|
12
12
|
|
13
13
|
# Aws::ParamValidator raises ArgumentError on unexpected keys
|
14
|
-
params.delete(:lookup)
|
15
|
-
|
14
|
+
params.delete(:lookup)
|
15
|
+
|
16
|
+
# Inherit language from configuration
|
17
|
+
params.merge!(language: configuration[:language])
|
18
|
+
|
16
19
|
resp = if query.reverse_geocode?
|
17
20
|
client.search_place_index_for_position(params.merge(position: query.coordinates.reverse))
|
18
21
|
else
|
19
22
|
client.search_place_index_for_text(params.merge(text: query.text))
|
20
23
|
end
|
21
|
-
|
24
|
+
|
22
25
|
resp.results
|
23
26
|
end
|
24
27
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require 'geocoder/results/azure'
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class Azure < Base
|
6
|
+
def name
|
7
|
+
'Azure'
|
8
|
+
end
|
9
|
+
|
10
|
+
def required_api_key_parts
|
11
|
+
['api_key']
|
12
|
+
end
|
13
|
+
|
14
|
+
def supported_protocols
|
15
|
+
[:https]
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def base_query_url(query)
|
21
|
+
host = 'atlas.microsoft.com/search/address'
|
22
|
+
|
23
|
+
if query.reverse_geocode?
|
24
|
+
"#{protocol}://#{host}/reverse/json?"
|
25
|
+
else
|
26
|
+
"#{protocol}://#{host}/json?"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def query_url_params(query)
|
31
|
+
params = {
|
32
|
+
'api-version' => 1.0,
|
33
|
+
'language' => query.options[:language] || 'en',
|
34
|
+
'limit' => configuration[:limit] || 10,
|
35
|
+
'query' => query.sanitized_text,
|
36
|
+
'subscription-key' => configuration.api_key
|
37
|
+
}
|
38
|
+
|
39
|
+
params.merge(super)
|
40
|
+
end
|
41
|
+
|
42
|
+
def results(query)
|
43
|
+
return [] unless (doc = fetch_data(query))
|
44
|
+
|
45
|
+
return doc if doc['error']
|
46
|
+
|
47
|
+
if doc['results']&.any?
|
48
|
+
doc['results']
|
49
|
+
elsif doc['addresses']&.any?
|
50
|
+
doc['addresses']
|
51
|
+
else
|
52
|
+
[]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -19,7 +19,7 @@ module Geocoder::Lookup
|
|
19
19
|
private # ---------------------------------------------------------------
|
20
20
|
|
21
21
|
def base_query_url(query)
|
22
|
-
text =
|
22
|
+
text = ERB::Util.url_encode(query.sanitized_text.strip)
|
23
23
|
url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations/"
|
24
24
|
if query.reverse_geocode?
|
25
25
|
url + "#{text}?"
|
@@ -30,14 +30,14 @@ module Geocoder::Lookup
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def mapbox_search_term(query)
|
33
|
-
require '
|
33
|
+
require 'erb' unless defined?(ERB) && defined?(ERB::Util.url_encode)
|
34
34
|
if query.reverse_geocode?
|
35
35
|
lat,lon = query.coordinates
|
36
|
-
"#{
|
36
|
+
"#{ERB::Util.url_encode lon},#{ERB::Util.url_encode lat}"
|
37
37
|
else
|
38
38
|
# truncate at first semicolon so Mapbox doesn't go into batch mode
|
39
39
|
# (see Github issue #1299)
|
40
|
-
|
40
|
+
ERB::Util.url_encode query.text.to_s.split(';').first.to_s
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
data/lib/geocoder/query.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Azure < Base
|
5
|
+
def address
|
6
|
+
@data['address']['freeformAddress']
|
7
|
+
end
|
8
|
+
|
9
|
+
def building_number
|
10
|
+
@data['address']['buildingNumber']
|
11
|
+
end
|
12
|
+
|
13
|
+
def city
|
14
|
+
@data['address']['municipality']
|
15
|
+
end
|
16
|
+
|
17
|
+
def coordinates
|
18
|
+
if @data['position'].is_a?(String) # reverse geocoding result
|
19
|
+
@data['position'].split(',').map(&:to_f)
|
20
|
+
elsif @data['position'].is_a?(Hash) # forward geocoding result
|
21
|
+
[@data['position']['lat'], @data['position']['lon']]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def country
|
26
|
+
@data['address']['country']
|
27
|
+
end
|
28
|
+
|
29
|
+
def country_code
|
30
|
+
@data['address']['countryCode']
|
31
|
+
end
|
32
|
+
|
33
|
+
def district
|
34
|
+
@data['address']['municipalitySubdivision']
|
35
|
+
end
|
36
|
+
|
37
|
+
def postal_code
|
38
|
+
@data['address']['postalCode']
|
39
|
+
end
|
40
|
+
|
41
|
+
def province
|
42
|
+
@data['address']['countrySubdivision']
|
43
|
+
end
|
44
|
+
|
45
|
+
def state
|
46
|
+
@data['address']['countrySubdivision']
|
47
|
+
end
|
48
|
+
|
49
|
+
def state_code
|
50
|
+
@data['address']['countrySubdivisionCode']
|
51
|
+
end
|
52
|
+
|
53
|
+
def street_name
|
54
|
+
@data['address']['streetName']
|
55
|
+
end
|
56
|
+
|
57
|
+
def street_number
|
58
|
+
@data['address']['streetNumber']
|
59
|
+
end
|
60
|
+
|
61
|
+
def viewport
|
62
|
+
@data['viewport'] || {}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -16,43 +16,61 @@ module Geocoder::Result
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def city
|
19
|
-
context_part('place')
|
19
|
+
data_part('place') || context_part('place')
|
20
20
|
end
|
21
21
|
|
22
22
|
def state
|
23
|
-
context_part('region')
|
23
|
+
data_part('region') || context_part('region')
|
24
24
|
end
|
25
25
|
|
26
26
|
def state_code
|
27
|
-
|
27
|
+
if id_matches_name?(data['id'], 'region')
|
28
|
+
value = data['properties']['short_code']
|
29
|
+
else
|
30
|
+
value = context_part('region', 'short_code')
|
31
|
+
end
|
32
|
+
|
28
33
|
value.split('-').last unless value.nil?
|
29
34
|
end
|
30
35
|
|
31
36
|
def postal_code
|
32
|
-
context_part('postcode')
|
37
|
+
data_part('postcode') || context_part('postcode')
|
33
38
|
end
|
34
39
|
|
35
40
|
def country
|
36
|
-
context_part('country')
|
41
|
+
data_part('country') || context_part('country')
|
37
42
|
end
|
38
43
|
|
39
44
|
def country_code
|
40
|
-
|
45
|
+
if id_matches_name?(data['id'], 'country')
|
46
|
+
value = data['properties']['short_code']
|
47
|
+
else
|
48
|
+
value = context_part('country', 'short_code')
|
49
|
+
end
|
50
|
+
|
41
51
|
value.upcase unless value.nil?
|
42
52
|
end
|
43
53
|
|
44
54
|
def neighborhood
|
45
|
-
context_part('neighborhood')
|
55
|
+
data_part('neighborhood') || context_part('neighborhood')
|
46
56
|
end
|
47
57
|
|
48
58
|
def address
|
49
|
-
[place_name
|
59
|
+
data['place_name']
|
50
60
|
end
|
51
61
|
|
52
62
|
private
|
53
63
|
|
64
|
+
def id_matches_name?(id, name)
|
65
|
+
id =~ Regexp.new(name)
|
66
|
+
end
|
67
|
+
|
68
|
+
def data_part(name)
|
69
|
+
data['text'] if id_matches_name?(data['id'], name)
|
70
|
+
end
|
71
|
+
|
54
72
|
def context_part(name, key = 'text')
|
55
|
-
(context.detect { |c| c['id']
|
73
|
+
(context.detect { |c| id_matches_name?(c['id'], name) } || {})[key]
|
56
74
|
end
|
57
75
|
|
58
76
|
def context
|
data/lib/geocoder/version.rb
CHANGED
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Reisner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/geocoder/lookups/abstract_api.rb
|
83
83
|
- lib/geocoder/lookups/amap.rb
|
84
84
|
- lib/geocoder/lookups/amazon_location_service.rb
|
85
|
+
- lib/geocoder/lookups/azure.rb
|
85
86
|
- lib/geocoder/lookups/baidu.rb
|
86
87
|
- lib/geocoder/lookups/baidu_ip.rb
|
87
88
|
- lib/geocoder/lookups/ban_data_gouv_fr.rb
|
@@ -149,6 +150,7 @@ files:
|
|
149
150
|
- lib/geocoder/results/abstract_api.rb
|
150
151
|
- lib/geocoder/results/amap.rb
|
151
152
|
- lib/geocoder/results/amazon_location_service.rb
|
153
|
+
- lib/geocoder/results/azure.rb
|
152
154
|
- lib/geocoder/results/baidu.rb
|
153
155
|
- lib/geocoder/results/baidu_ip.rb
|
154
156
|
- lib/geocoder/results/ban_data_gouv_fr.rb
|