geocoder 1.6.2 → 1.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/LICENSE +1 -1
- data/README.md +9 -30
- data/bin/console +6 -0
- data/lib/geocoder/cache.rb +4 -0
- data/lib/geocoder/configuration.rb +2 -1
- data/lib/geocoder/configuration_hash.rb +4 -4
- data/lib/geocoder/ip_address.rb +2 -1
- data/lib/geocoder/lookup.rb +1 -0
- data/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +1 -1
- data/lib/geocoder/lookups/esri.rb +6 -0
- data/lib/geocoder/lookups/geocodio.rb +1 -1
- data/lib/geocoder/lookups/google.rb +7 -2
- data/lib/geocoder/lookups/google_places_details.rb +8 -14
- data/lib/geocoder/lookups/google_places_search.rb +28 -2
- data/lib/geocoder/lookups/google_premier.rb +4 -0
- data/lib/geocoder/lookups/latlon.rb +1 -2
- data/lib/geocoder/lookups/maxmind_local.rb +7 -1
- data/lib/geocoder/lookups/smarty_streets.rb +6 -1
- data/lib/geocoder/lookups/telize.rb +1 -1
- data/lib/geocoder/lookups/test.rb +4 -0
- data/lib/geocoder/lookups/uk_ordnance_survey_names.rb +1 -1
- data/lib/geocoder/lookups/yandex.rb +1 -2
- data/lib/geocoder/results/abstract_api.rb +146 -0
- data/lib/geocoder/results/ban_data_gouv_fr.rb +26 -1
- data/lib/geocoder/results/db_ip_com.rb +1 -1
- data/lib/geocoder/results/ipregistry.rb +4 -8
- data/lib/geocoder/results/nationaal_georegister_nl.rb +1 -1
- data/lib/geocoder/results/nominatim.rb +4 -0
- data/lib/geocoder/util.rb +29 -0
- data/lib/geocoder/version.rb +1 -1
- metadata +9 -8
- data/lib/hash_recursive_merge.rb +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17d8f44da8b584b65c5546df089f0c16e6d20045676d4a1fe3fef38cdf3c3c59
|
4
|
+
data.tar.gz: c527329b8d1f28a326092e3b3f6d2c9c143dacc2da2397fab5b4109ae7387f09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 918ed290277a1aa7e57a102ad06b0cf733e1908e9f31ead6cd59c5d08e5cc5b7d2f581a9958961781e013b535763c92701ad02f2bd8268374e339a36fd75eb25
|
7
|
+
data.tar.gz: 14416b59a9f34890d9a466aad87a883651f13f58a1f0a972c7d48370daed0f70923b9534b13e489673dbbc19543c82fb9017dd274529ce3a587bebe1f230649d
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,30 @@ 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.6.7 (2021 Apr 17)
|
7
|
+
-------------------
|
8
|
+
* Add support for Abstract API lookup (thanks github.com/randoum).
|
9
|
+
|
10
|
+
1.6.6 (2021 Mar 4)
|
11
|
+
-------------------
|
12
|
+
* Rescue from exception on cache read/write error. Issue warning instead.
|
13
|
+
|
14
|
+
1.6.5 (2021 Feb 10)
|
15
|
+
-------------------
|
16
|
+
* Fix backward coordinates bug in NationaalregisterNl lookup (thanks github.com/Marthyn).
|
17
|
+
* Allow removal of single stubs in test mode (thanks github.com/jmmastey).
|
18
|
+
* Improve results for :ban_data_gouv_fr lookup (thanks github.com/Intrepidd).
|
19
|
+
|
20
|
+
1.6.4 (2020 Oct 6)
|
21
|
+
-------------------
|
22
|
+
* Various updates in response to geocoding API changes.
|
23
|
+
* Refactor of Google Places Search lookup (thanks github.com/maximilientyc).
|
24
|
+
|
25
|
+
1.6.3 (2020 Apr 30)
|
26
|
+
-------------------
|
27
|
+
* Update URL for :telize lookup (thanks github.com/alexwalling).
|
28
|
+
* Fix bug parsing IPv6 with port (thanks github.com/gdomingu).
|
29
|
+
|
6
30
|
1.6.2 (2020 Mar 16)
|
7
31
|
-------------------
|
8
32
|
* Add support for :nationaal_georegister_nl lookup (thanks github.com/opensourceame).
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -51,8 +51,8 @@ The Rest:
|
|
51
51
|
* [Technical Discussions](#technical-discussions)
|
52
52
|
* [Troubleshooting](#troubleshooting)
|
53
53
|
* [Known Issues](#known-issues)
|
54
|
-
* [Reporting Issues](#reporting-
|
55
|
-
* [Contributing](#
|
54
|
+
* [Reporting Issues](https://github.com/alexreisner/geocoder/blob/master/CONTRIBUTING.md#reporting-bugs)
|
55
|
+
* [Contributing](https://github.com/alexreisner/geocoder/blob/master/CONTRIBUTING.md#making-changes)
|
56
56
|
|
57
57
|
See Also:
|
58
58
|
|
@@ -213,7 +213,7 @@ Some common options are:
|
|
213
213
|
# set default units to kilometers:
|
214
214
|
units: :km,
|
215
215
|
|
216
|
-
# caching (see
|
216
|
+
# caching (see Caching section below for details):
|
217
217
|
cache: Redis.new,
|
218
218
|
cache_prefix: "..."
|
219
219
|
|
@@ -532,10 +532,14 @@ With the above stub defined, any query for "New York, NY" will return the result
|
|
532
532
|
]
|
533
533
|
)
|
534
534
|
|
535
|
+
You may also delete a single stub, or reset all stubs _including the default stub_:
|
536
|
+
|
537
|
+
Geocoder::Lookup::Test.delete_stub('New York, NY')
|
538
|
+
Geocoder::Lookup::Test.reset
|
539
|
+
|
535
540
|
Notes:
|
536
541
|
|
537
542
|
- Keys must be strings (not symbols) when calling `add_stub` or `set_default_stub`. For example `'country' =>` not `:country =>`.
|
538
|
-
- To clear stubs (e.g. prior to another spec), use `Geocoder::Lookup::Test.reset`. This will clear all stubs _including the default stub_.
|
539
543
|
- 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.
|
540
544
|
|
541
545
|
|
@@ -676,29 +680,4 @@ If anyone has a more elegant solution to this problem I am very interested in se
|
|
676
680
|
The `near` method will not look across the 180th meridian to find objects close to a given point. In practice this is rarely an issue outside of New Zealand and certain surrounding islands. This problem does not exist with the zero-meridian. The problem is due to a shortcoming of the Haversine formula which Geocoder uses to calculate distances.
|
677
681
|
|
678
682
|
|
679
|
-
|
680
|
-
----------------
|
681
|
-
|
682
|
-
When reporting an issue, please list the version of Geocoder you are using and any relevant information about your application (Rails version, database type and version, etc). Please describe as specifically as you can what behavior you are seeing (eg: an error message? a nil return value?).
|
683
|
-
|
684
|
-
Please DO NOT use GitHub issues to ask questions about how to use Geocoder. Sites like [StackOverflow](http://www.stackoverflow.com/) are a better forum for such discussions.
|
685
|
-
|
686
|
-
|
687
|
-
Contributing
|
688
|
-
------------
|
689
|
-
|
690
|
-
Contributions are welcome via Github pull requests. If you are new to the project and looking for a way to get involved, try picking up an issue with a "beginner-task" label. Hints about what needs to be done are usually provided.
|
691
|
-
|
692
|
-
For all contributions, please respect the following guidelines:
|
693
|
-
|
694
|
-
* Each pull request should implement ONE feature or bugfix. If you want to add or fix more than one thing, submit more than one pull request.
|
695
|
-
* Do not commit changes to files that are irrelevant to your feature or bugfix (eg: `.gitignore`).
|
696
|
-
* Do not add dependencies on other gems.
|
697
|
-
* Do not add unnecessary `require` statements which could cause LoadErrors on certain systems.
|
698
|
-
* Remember: Geocoder needs to run outside of Rails. Don't assume things like ActiveSupport are available.
|
699
|
-
* Be willing to accept criticism and work on improving your code; Geocoder is used by thousands of developers and care must be taken not to introduce bugs.
|
700
|
-
* Be aware that the pull request review process is not immediate, and is generally proportional to the size of the pull request.
|
701
|
-
* If your pull request is merged, please do not ask for an immediate release of the gem. There are many factors contributing to when releases occur (remember that they affect thousands of apps with Geocoder in their Gemfiles). If necessary, please install from the Github source until the next official release.
|
702
|
-
|
703
|
-
|
704
|
-
Copyright :copyright: 2009-2020 Alex Reisner, released under the MIT license.
|
683
|
+
Copyright :copyright: 2009-2021 Alex Reisner, released under the MIT license.
|
data/bin/console
CHANGED
data/lib/geocoder/cache.rb
CHANGED
@@ -18,6 +18,8 @@ module Geocoder
|
|
18
18
|
when store.respond_to?(:read)
|
19
19
|
store.read key_for(url)
|
20
20
|
end
|
21
|
+
rescue => e
|
22
|
+
warn "Geocoder cache read error: #{e}"
|
21
23
|
end
|
22
24
|
|
23
25
|
##
|
@@ -32,6 +34,8 @@ module Geocoder
|
|
32
34
|
when store.respond_to?(:write)
|
33
35
|
store.write key_for(url), value
|
34
36
|
end
|
37
|
+
rescue => e
|
38
|
+
warn "Geocoder cache write error: #{e}"
|
35
39
|
end
|
36
40
|
|
37
41
|
##
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require 'geocoder/configuration_hash'
|
3
|
+
require 'geocoder/util'
|
3
4
|
|
4
5
|
module Geocoder
|
5
6
|
|
@@ -85,7 +86,7 @@ module Geocoder
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def configure(options)
|
88
|
-
@data
|
89
|
+
Util.recursive_hash_merge(@data, options)
|
89
90
|
end
|
90
91
|
|
91
92
|
def initialize # :nodoc
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'hash_recursive_merge'
|
2
|
-
|
3
1
|
module Geocoder
|
4
2
|
class ConfigurationHash < Hash
|
5
|
-
include HashRecursiveMerge
|
6
|
-
|
7
3
|
def method_missing(meth, *args, &block)
|
8
4
|
has_key?(meth) ? self[meth] : super
|
9
5
|
end
|
6
|
+
|
7
|
+
def respond_to_missing?(meth, include_private = false)
|
8
|
+
has_key?(meth) || super
|
9
|
+
end
|
10
10
|
end
|
11
11
|
end
|
data/lib/geocoder/ip_address.rb
CHANGED
data/lib/geocoder/lookup.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'geocoder/lookups/base'
|
4
|
+
require 'geocoder/results/abstract_api'
|
5
|
+
|
6
|
+
module Geocoder::Lookup
|
7
|
+
class AbstractApi < Base
|
8
|
+
|
9
|
+
def name
|
10
|
+
"Abstract API"
|
11
|
+
end
|
12
|
+
|
13
|
+
def required_api_key_parts
|
14
|
+
['api_key']
|
15
|
+
end
|
16
|
+
|
17
|
+
def supported_protocols
|
18
|
+
[:https]
|
19
|
+
end
|
20
|
+
|
21
|
+
private # ---------------------------------------------------------------
|
22
|
+
|
23
|
+
def base_query_url(query)
|
24
|
+
"#{protocol}://ipgeolocation.abstractapi.com/v1/?"
|
25
|
+
end
|
26
|
+
|
27
|
+
def query_url_params(query)
|
28
|
+
params = {api_key: configuration.api_key}
|
29
|
+
|
30
|
+
ip_address = query.sanitized_text
|
31
|
+
if ip_address.is_a?(String) && ip_address.length > 0
|
32
|
+
params[:ip_address] = ip_address
|
33
|
+
end
|
34
|
+
|
35
|
+
params.merge(super)
|
36
|
+
end
|
37
|
+
|
38
|
+
def results(query, reverse = false)
|
39
|
+
if doc = fetch_data(query)
|
40
|
+
[doc]
|
41
|
+
else
|
42
|
+
[]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -9,6 +9,10 @@ module Geocoder::Lookup
|
|
9
9
|
"Esri"
|
10
10
|
end
|
11
11
|
|
12
|
+
def supported_protocols
|
13
|
+
[:https]
|
14
|
+
end
|
15
|
+
|
12
16
|
private # ---------------------------------------------------------------
|
13
17
|
|
14
18
|
def base_query_url(query)
|
@@ -47,6 +51,8 @@ module Geocoder::Lookup
|
|
47
51
|
params[:forStorage] = for_storage_value
|
48
52
|
end
|
49
53
|
params[:sourceCountry] = configuration[:source_country] if configuration[:source_country]
|
54
|
+
params[:preferredLabelValues] = configuration[:preferred_label_values] if configuration[:preferred_label_values]
|
55
|
+
|
50
56
|
params.merge(super)
|
51
57
|
end
|
52
58
|
|
@@ -44,10 +44,15 @@ module Geocoder::Lookup
|
|
44
44
|
super(response) and ['OK', 'ZERO_RESULTS'].include?(status)
|
45
45
|
end
|
46
46
|
|
47
|
+
def result_root_attr
|
48
|
+
'results'
|
49
|
+
end
|
50
|
+
|
47
51
|
def results(query)
|
48
52
|
return [] unless doc = fetch_data(query)
|
49
|
-
case doc['status']
|
50
|
-
|
53
|
+
case doc['status']
|
54
|
+
when "OK" # OK status implies >0 results
|
55
|
+
return doc[result_root_attr]
|
51
56
|
when "OVER_QUERY_LIMIT"
|
52
57
|
raise_error(Geocoder::OverQueryLimitError) ||
|
53
58
|
Geocoder.log(:warn, "#{name} API error: over query limit.")
|
@@ -22,21 +22,15 @@ module Geocoder
|
|
22
22
|
"#{protocol}://maps.googleapis.com/maps/api/place/details/json?"
|
23
23
|
end
|
24
24
|
|
25
|
+
def result_root_attr
|
26
|
+
'result'
|
27
|
+
end
|
28
|
+
|
25
29
|
def results(query)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
return [doc["result"]]
|
31
|
-
when "OVER_QUERY_LIMIT"
|
32
|
-
raise_error(Geocoder::OverQueryLimitError) || Geocoder.log(:warn, "Google Places Details API error: over query limit.")
|
33
|
-
when "REQUEST_DENIED"
|
34
|
-
raise_error(Geocoder::RequestDenied) || Geocoder.log(:warn, "Google Places Details API error: request denied.")
|
35
|
-
when "INVALID_REQUEST"
|
36
|
-
raise_error(Geocoder::InvalidRequest) || Geocoder.log(:warn, "Google Places Details API error: invalid request.")
|
37
|
-
end
|
38
|
-
|
39
|
-
[]
|
30
|
+
result = super(query)
|
31
|
+
return [result] unless result.is_a? Array
|
32
|
+
|
33
|
+
result
|
40
34
|
end
|
41
35
|
|
42
36
|
def query_url_google_params(query)
|
@@ -18,16 +18,42 @@ module Geocoder
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
+
def result_root_attr
|
22
|
+
'candidates'
|
23
|
+
end
|
24
|
+
|
21
25
|
def base_query_url(query)
|
22
|
-
"#{protocol}://maps.googleapis.com/maps/api/place/
|
26
|
+
"#{protocol}://maps.googleapis.com/maps/api/place/findplacefromtext/json?"
|
23
27
|
end
|
24
28
|
|
25
29
|
def query_url_google_params(query)
|
26
30
|
{
|
27
|
-
|
31
|
+
input: query.text,
|
32
|
+
inputtype: 'textquery',
|
33
|
+
fields: fields(query),
|
28
34
|
language: query.language || configuration.language
|
29
35
|
}
|
30
36
|
end
|
37
|
+
|
38
|
+
def fields(query)
|
39
|
+
query_fields = query.options[:fields]
|
40
|
+
return format_fields(query_fields) if query_fields
|
41
|
+
|
42
|
+
default_fields
|
43
|
+
end
|
44
|
+
|
45
|
+
def default_fields
|
46
|
+
legacy = %w[id reference]
|
47
|
+
basic = %w[business_status formatted_address geometry icon name
|
48
|
+
photos place_id plus_code types]
|
49
|
+
contact = %w[opening_hours]
|
50
|
+
atmosphere = %W[price_level rating user_ratings_total]
|
51
|
+
format_fields(legacy, basic, contact, atmosphere)
|
52
|
+
end
|
53
|
+
|
54
|
+
def format_fields(*fields)
|
55
|
+
fields.flatten.join(',')
|
56
|
+
end
|
31
57
|
end
|
32
58
|
end
|
33
59
|
end
|
@@ -21,6 +21,10 @@ module Geocoder::Lookup
|
|
21
21
|
|
22
22
|
private # ---------------------------------------------------------------
|
23
23
|
|
24
|
+
def result_root_attr
|
25
|
+
'results'
|
26
|
+
end
|
27
|
+
|
24
28
|
def cache_key(query)
|
25
29
|
"#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + hash_to_query(cache_key_params(query))
|
26
30
|
end
|
@@ -25,8 +25,7 @@ module Geocoder::Lookup
|
|
25
25
|
# The API returned a 404 response, which indicates no results found
|
26
26
|
elsif doc['error']['type'] == 'api_error'
|
27
27
|
[]
|
28
|
-
elsif
|
29
|
-
doc['error']['type'] == 'authentication_error'
|
28
|
+
elsif doc['error']['type'] == 'authentication_error'
|
30
29
|
raise_error(Geocoder::InvalidApiKey) ||
|
31
30
|
Geocoder.log(:warn, "LatLon.io service error: invalid API key.")
|
32
31
|
else
|
@@ -30,7 +30,13 @@ module Geocoder::Lookup
|
|
30
30
|
def results(query)
|
31
31
|
if configuration[:file]
|
32
32
|
geoip_class = RUBY_PLATFORM == "java" ? JGeoIP : GeoIP
|
33
|
-
|
33
|
+
geoip_instance = geoip_class.new(configuration[:file])
|
34
|
+
result =
|
35
|
+
if configuration[:package] == :country
|
36
|
+
geoip_instance.country(query.to_s)
|
37
|
+
else
|
38
|
+
geoip_instance.city(query.to_s)
|
39
|
+
end
|
34
40
|
result.nil? ? [] : [encode_hash(result.to_hash)]
|
35
41
|
elsif configuration[:package] == :city
|
36
42
|
addr = IPAddr.new(query.text).to_i
|
@@ -57,7 +57,12 @@ module Geocoder::Lookup
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def results(query)
|
60
|
-
fetch_data(query) || []
|
60
|
+
doc = fetch_data(query) || []
|
61
|
+
if doc.is_a?(Hash) and doc.key?('status') # implies there's an error
|
62
|
+
return []
|
63
|
+
else
|
64
|
+
return doc
|
65
|
+
end
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
@@ -16,7 +16,7 @@ module Geocoder::Lookup
|
|
16
16
|
if configuration[:host]
|
17
17
|
"#{protocol}://#{configuration[:host]}/location/#{query.sanitized_text}"
|
18
18
|
else
|
19
|
-
"#{protocol}://telize-v1.p.
|
19
|
+
"#{protocol}://telize-v1.p.rapidapi.com/location/#{query.sanitized_text}?rapidapi-key=#{api_key}"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -33,8 +33,7 @@ module Geocoder::Lookup
|
|
33
33
|
return []
|
34
34
|
end
|
35
35
|
if doc = doc['response']['GeoObjectCollection']
|
36
|
-
|
37
|
-
return meta['found'].to_i > 0 ? doc['featureMember'] : []
|
36
|
+
return doc['featureMember'].to_a
|
38
37
|
else
|
39
38
|
Geocoder.log(:warn, "Yandex Geocoding API error: unexpected response format.")
|
40
39
|
return []
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder
|
4
|
+
module Result
|
5
|
+
class AbstractApi < Base
|
6
|
+
|
7
|
+
##
|
8
|
+
# Geolocation
|
9
|
+
|
10
|
+
def state
|
11
|
+
@data['region']
|
12
|
+
end
|
13
|
+
|
14
|
+
def state_code
|
15
|
+
@data['region_iso_code']
|
16
|
+
end
|
17
|
+
|
18
|
+
def city
|
19
|
+
@data["city"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def city_geoname_id
|
23
|
+
@data["city_geoname_id"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def region_geoname_id
|
27
|
+
@data["region_geoname_id"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def postal_code
|
31
|
+
@data["postal_code"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def country
|
35
|
+
@data["country"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def country_code
|
39
|
+
@data["country_code"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def country_geoname_id
|
43
|
+
@data["country_geoname_id"]
|
44
|
+
end
|
45
|
+
|
46
|
+
def country_is_eu
|
47
|
+
@data["country_is_eu"]
|
48
|
+
end
|
49
|
+
|
50
|
+
def continent
|
51
|
+
@data["continent"]
|
52
|
+
end
|
53
|
+
|
54
|
+
def continent_code
|
55
|
+
@data["continent_code"]
|
56
|
+
end
|
57
|
+
|
58
|
+
def continent_geoname_id
|
59
|
+
@data["continent_geoname_id"]
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Security
|
64
|
+
|
65
|
+
def is_vpn?
|
66
|
+
@data.dig "security", "is_vpn"
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Timezone
|
71
|
+
|
72
|
+
def timezone_name
|
73
|
+
@data.dig "timezone", "name"
|
74
|
+
end
|
75
|
+
|
76
|
+
def timezone_abbreviation
|
77
|
+
@data.dig "timezone", "abbreviation"
|
78
|
+
end
|
79
|
+
|
80
|
+
def timezone_gmt_offset
|
81
|
+
@data.dig "timezone", "gmt_offset"
|
82
|
+
end
|
83
|
+
|
84
|
+
def timezone_current_time
|
85
|
+
@data.dig "timezone", "current_time"
|
86
|
+
end
|
87
|
+
|
88
|
+
def timezone_is_dst
|
89
|
+
@data.dig "timezone", "is_dst"
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# Flag
|
94
|
+
|
95
|
+
def flag_emoji
|
96
|
+
@data.dig "flag", "emoji"
|
97
|
+
end
|
98
|
+
|
99
|
+
def flag_unicode
|
100
|
+
@data.dig "flag", "unicode"
|
101
|
+
end
|
102
|
+
|
103
|
+
def flag_png
|
104
|
+
@data.dig "flag", "png"
|
105
|
+
end
|
106
|
+
|
107
|
+
def flag_svg
|
108
|
+
@data.dig "flag", "svg"
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Currency
|
113
|
+
|
114
|
+
def currency_currency_name
|
115
|
+
@data.dig "currency", "currency_name"
|
116
|
+
end
|
117
|
+
|
118
|
+
def currency_currency_code
|
119
|
+
@data.dig "currency", "currency_code"
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
# Connection
|
124
|
+
|
125
|
+
def connection_autonomous_system_number
|
126
|
+
@data.dig "connection", "autonomous_system_number"
|
127
|
+
end
|
128
|
+
|
129
|
+
def connection_autonomous_system_organization
|
130
|
+
@data.dig "connection", "autonomous_system_organization"
|
131
|
+
end
|
132
|
+
|
133
|
+
def connection_connection_type
|
134
|
+
@data.dig "connection", "connection_type"
|
135
|
+
end
|
136
|
+
|
137
|
+
def connection_isp_name
|
138
|
+
@data.dig "connection", "isp_name"
|
139
|
+
end
|
140
|
+
|
141
|
+
def connection_organization_name
|
142
|
+
@data.dig "connection", "organization_name"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -4,6 +4,27 @@ require 'geocoder/results/base'
|
|
4
4
|
module Geocoder::Result
|
5
5
|
class BanDataGouvFr < Base
|
6
6
|
|
7
|
+
STATE_CODE_MAPPINGS = {
|
8
|
+
"Guadeloupe" => "01",
|
9
|
+
"Martinique" => "02",
|
10
|
+
"Guyane" => "03",
|
11
|
+
"La Réunion" => "04",
|
12
|
+
"Mayotte" => "06",
|
13
|
+
"Île-de-France" => "11",
|
14
|
+
"Centre-Val de Loire" => "24",
|
15
|
+
"Bourgogne-Franche-Comté" => "27",
|
16
|
+
"Normandie" => "28",
|
17
|
+
"Hauts-de-France" => "32",
|
18
|
+
"Grand Est" => "44",
|
19
|
+
"Pays de la Loire" => "52",
|
20
|
+
"Bretagne" => "53",
|
21
|
+
"Nouvelle-Aquitaine" => "75",
|
22
|
+
"Occitanie" => "76",
|
23
|
+
"Auvergne-Rhône-Alpes" => "84",
|
24
|
+
"Provence-Alpes-Côte d'Azur" => "93",
|
25
|
+
"Corse" => "94"
|
26
|
+
}.freeze
|
27
|
+
|
7
28
|
#### BASE METHODS ####
|
8
29
|
|
9
30
|
def self.response_attributes
|
@@ -209,6 +230,10 @@ module Geocoder::Result
|
|
209
230
|
end
|
210
231
|
end
|
211
232
|
|
233
|
+
def region_code
|
234
|
+
STATE_CODE_MAPPINGS[region_name]
|
235
|
+
end
|
236
|
+
|
212
237
|
def country
|
213
238
|
"France"
|
214
239
|
end
|
@@ -235,7 +260,7 @@ module Geocoder::Result
|
|
235
260
|
alias_method :street, :street_name
|
236
261
|
alias_method :city, :city_name
|
237
262
|
alias_method :state, :region_name
|
238
|
-
alias_method :state_code, :
|
263
|
+
alias_method :state_code, :region_code
|
239
264
|
|
240
265
|
#### CITIES' METHODS ####
|
241
266
|
|
@@ -9,6 +9,10 @@ module Geocoder::Result
|
|
9
9
|
@data = flatten_hash(data)
|
10
10
|
end
|
11
11
|
|
12
|
+
def coordinates
|
13
|
+
[@data['location_latitude'], @data['location_longitude']]
|
14
|
+
end
|
15
|
+
|
12
16
|
def flatten_hash(hash)
|
13
17
|
hash.each_with_object({}) do |(k, v), h|
|
14
18
|
if v.is_a? Hash
|
@@ -35,14 +39,6 @@ module Geocoder::Result
|
|
35
39
|
@data['location_country_code']
|
36
40
|
end
|
37
41
|
|
38
|
-
def latitude
|
39
|
-
@data['location_latitude']
|
40
|
-
end
|
41
|
-
|
42
|
-
def longitude
|
43
|
-
@data['location_longitude']
|
44
|
-
end
|
45
|
-
|
46
42
|
def postal_code
|
47
43
|
@data['location_postal']
|
48
44
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Geocoder
|
4
|
+
module Util
|
5
|
+
#
|
6
|
+
# Recursive version of Hash#merge!
|
7
|
+
#
|
8
|
+
# Adds the contents of +h2+ to +h1+,
|
9
|
+
# merging entries in +h1+ with duplicate keys with those from +h2+.
|
10
|
+
#
|
11
|
+
# Compared with Hash#merge!, this method supports nested hashes.
|
12
|
+
# When both +h1+ and +h2+ contains an entry with the same key,
|
13
|
+
# it merges and returns the values from both hashes.
|
14
|
+
#
|
15
|
+
# h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
|
16
|
+
# h2 = {"b" => 254, "c" => {"c1" => 16, "c3" => 94}}
|
17
|
+
# recursive_hash_merge(h1, h2) #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
|
18
|
+
#
|
19
|
+
# Simply using Hash#merge! would return
|
20
|
+
#
|
21
|
+
# h1.merge!(h2) #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
|
22
|
+
#
|
23
|
+
def self.recursive_hash_merge(h1, h2)
|
24
|
+
h1.merge!(h2) do |_key, oldval, newval|
|
25
|
+
oldval.class == h1.class ? self.recursive_hash_merge(oldval, newval) : newval
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/geocoder/version.rb
CHANGED
metadata
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geocoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.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:
|
11
|
+
date: 2021-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
15
|
-
|
16
|
-
frameworks too.
|
13
|
+
description: Object geocoding (by street or IP address), reverse geocoding (coordinates
|
14
|
+
to street address), distance queries for ActiveRecord and Mongoid, result caching,
|
15
|
+
and more. Designed for Rails but works with Sinatra and other Rack frameworks too.
|
17
16
|
email:
|
18
17
|
- alex@alexreisner.com
|
19
18
|
executables:
|
@@ -50,6 +49,7 @@ files:
|
|
50
49
|
- lib/geocoder/kernel_logger.rb
|
51
50
|
- lib/geocoder/logger.rb
|
52
51
|
- lib/geocoder/lookup.rb
|
52
|
+
- lib/geocoder/lookups/abstract_api.rb
|
53
53
|
- lib/geocoder/lookups/amap.rb
|
54
54
|
- lib/geocoder/lookups/baidu.rb
|
55
55
|
- lib/geocoder/lookups/baidu_ip.rb
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/geocoder/query.rb
|
107
107
|
- lib/geocoder/railtie.rb
|
108
108
|
- lib/geocoder/request.rb
|
109
|
+
- lib/geocoder/results/abstract_api.rb
|
109
110
|
- lib/geocoder/results/amap.rb
|
110
111
|
- lib/geocoder/results/baidu.rb
|
111
112
|
- lib/geocoder/results/baidu_ip.rb
|
@@ -160,8 +161,8 @@ files:
|
|
160
161
|
- lib/geocoder/stores/mongo_base.rb
|
161
162
|
- lib/geocoder/stores/mongo_mapper.rb
|
162
163
|
- lib/geocoder/stores/mongoid.rb
|
164
|
+
- lib/geocoder/util.rb
|
163
165
|
- lib/geocoder/version.rb
|
164
|
-
- lib/hash_recursive_merge.rb
|
165
166
|
- lib/maxmind_database.rb
|
166
167
|
- lib/tasks/geocoder.rake
|
167
168
|
- lib/tasks/maxmind.rake
|
@@ -186,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
187
|
- !ruby/object:Gem::Version
|
187
188
|
version: '0'
|
188
189
|
requirements: []
|
189
|
-
rubygems_version: 3.
|
190
|
+
rubygems_version: 3.1.2
|
190
191
|
signing_key:
|
191
192
|
specification_version: 4
|
192
193
|
summary: Complete geocoding solution for Ruby.
|
data/lib/hash_recursive_merge.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = Hash Recursive Merge
|
3
|
-
#
|
4
|
-
# Merges a Ruby Hash recursively, Also known as deep merge.
|
5
|
-
# Recursive version of Hash#merge and Hash#merge!.
|
6
|
-
#
|
7
|
-
# Category:: Ruby
|
8
|
-
# Package:: Hash
|
9
|
-
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
-
# Copyright:: 2007-2008 The Authors
|
11
|
-
# License:: MIT License
|
12
|
-
# Link:: http://www.simonecarletti.com/
|
13
|
-
# Source:: http://gist.github.com/gists/6391/
|
14
|
-
#
|
15
|
-
module HashRecursiveMerge
|
16
|
-
|
17
|
-
#
|
18
|
-
# Recursive version of Hash#merge!
|
19
|
-
#
|
20
|
-
# Adds the contents of +other_hash+ to +hsh+,
|
21
|
-
# merging entries in +hsh+ with duplicate keys with those from +other_hash+.
|
22
|
-
#
|
23
|
-
# Compared with Hash#merge!, this method supports nested hashes.
|
24
|
-
# When both +hsh+ and +other_hash+ contains an entry with the same key,
|
25
|
-
# it merges and returns the values from both arrays.
|
26
|
-
#
|
27
|
-
# h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
|
28
|
-
# h2 = {"b" => 254, "c" => {"c1" => 16, "c3" => 94}}
|
29
|
-
# h1.rmerge!(h2) #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
|
30
|
-
#
|
31
|
-
# Simply using Hash#merge! would return
|
32
|
-
#
|
33
|
-
# h1.merge!(h2) #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
|
34
|
-
#
|
35
|
-
def rmerge!(other_hash)
|
36
|
-
merge!(other_hash) do |key, oldval, newval|
|
37
|
-
oldval.class == self.class ? oldval.rmerge!(newval) : newval
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Recursive version of Hash#merge
|
43
|
-
#
|
44
|
-
# Compared with Hash#merge!, this method supports nested hashes.
|
45
|
-
# When both +hsh+ and +other_hash+ contains an entry with the same key,
|
46
|
-
# it merges and returns the values from both arrays.
|
47
|
-
#
|
48
|
-
# Compared with Hash#merge, this method provides a different approch
|
49
|
-
# for merging nasted hashes.
|
50
|
-
# If the value of a given key is an Hash and both +other_hash+ abd +hsh
|
51
|
-
# includes the same key, the value is merged instead replaced with
|
52
|
-
# +other_hash+ value.
|
53
|
-
#
|
54
|
-
# h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
|
55
|
-
# h2 = {"b" => 254, "c" => {"c1" => 16, "c3" => 94}}
|
56
|
-
# h1.rmerge(h2) #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
|
57
|
-
#
|
58
|
-
# Simply using Hash#merge would return
|
59
|
-
#
|
60
|
-
# h1.merge(h2) #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
|
61
|
-
#
|
62
|
-
def rmerge(other_hash)
|
63
|
-
merge(other_hash) do |key, oldval, newval|
|
64
|
-
oldval.class == self.class ? oldval.rmerge(newval) : newval
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
class Hash
|
72
|
-
include HashRecursiveMerge
|
73
|
-
end
|