geocoder 1.6.4 → 1.6.7

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: 0e4c449a8a83ae4e05f107ca65e5b0c17330c775ee47e0015705cb5a557b37af
4
- data.tar.gz: 588192a50b794f6e953f46491b36680e0bd8629a05b236a049669a377ff12fde
3
+ metadata.gz: 17d8f44da8b584b65c5546df089f0c16e6d20045676d4a1fe3fef38cdf3c3c59
4
+ data.tar.gz: c527329b8d1f28a326092e3b3f6d2c9c143dacc2da2397fab5b4109ae7387f09
5
5
  SHA512:
6
- metadata.gz: 2afedac2b198f7cea780fe496178d1188dc4b79f4d845322dbb865da6e23681d145708d366db3c93aa88aa5a1736f3dc2a0ec04a022054d12ccb853d7ba03443
7
- data.tar.gz: 5926d851a342d3fad0cb993affba56d689d58d8c5584966b290e2e0da60d7bc597ed60bc23194e1c0fb6644310f0121a5ac157ccf0743182b15dffe733141656
6
+ metadata.gz: 918ed290277a1aa7e57a102ad06b0cf733e1908e9f31ead6cd59c5d08e5cc5b7d2f581a9958961781e013b535763c92701ad02f2bd8268374e339a36fd75eb25
7
+ data.tar.gz: 14416b59a9f34890d9a466aad87a883651f13f58a1f0a972c7d48370daed0f70923b9534b13e489673dbbc19543c82fb9017dd274529ce3a587bebe1f230649d
data/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@ 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
+
6
20
  1.6.4 (2020 Oct 6)
7
21
  -------------------
8
22
  * Various updates in response to geocoding API changes.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2020 Alex Reisner
1
+ Copyright (c) 2009-2021 Alex Reisner
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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-issues)
55
- * [Contributing](#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 [below](#caching) for details):
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
- Reporting Issues
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.
@@ -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
  ##
@@ -63,6 +63,7 @@ module Geocoder
63
63
  def ip_services
64
64
  @ip_services ||= [
65
65
  :baidu_ip,
66
+ :abstract_api,
66
67
  :freegeoip,
67
68
  :geoip2,
68
69
  :maxmind,
@@ -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
@@ -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
- result = geoip_class.new(configuration[:file]).city(query.to_s)
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
@@ -28,6 +28,10 @@ module Geocoder
28
28
  @stubs ||= {}
29
29
  end
30
30
 
31
+ def self.delete_stub(query_text)
32
+ stubs.delete(query_text)
33
+ end
34
+
31
35
  def self.reset
32
36
  @stubs = {}
33
37
  @default_stub = nil
@@ -13,7 +13,7 @@ module Geocoder::Lookup
13
13
  end
14
14
 
15
15
  def base_query_url(query)
16
- "#{protocol}://api.ordnancesurvey.co.uk/opennames/v1/find?"
16
+ "#{protocol}://api.os.uk/search/names/v1/find?"
17
17
  end
18
18
 
19
19
  def required_api_key_parts
@@ -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, :state
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
@@ -8,7 +8,7 @@ module Geocoder::Result
8
8
  end
9
9
 
10
10
  def coordinates
11
- @data['centroide_ll'][6..-2].split(' ').map(&:to_f)
11
+ @data['centroide_ll'][6..-2].split(' ').map(&:to_f).reverse
12
12
  end
13
13
 
14
14
  def formatted_address
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.6.4"
2
+ VERSION = "1.6.7"
3
3
  end
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.6.4
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: 2020-10-06 00:00:00.000000000 Z
11
+ date: 2021-04-17 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,
@@ -49,6 +49,7 @@ files:
49
49
  - lib/geocoder/kernel_logger.rb
50
50
  - lib/geocoder/logger.rb
51
51
  - lib/geocoder/lookup.rb
52
+ - lib/geocoder/lookups/abstract_api.rb
52
53
  - lib/geocoder/lookups/amap.rb
53
54
  - lib/geocoder/lookups/baidu.rb
54
55
  - lib/geocoder/lookups/baidu_ip.rb
@@ -105,6 +106,7 @@ files:
105
106
  - lib/geocoder/query.rb
106
107
  - lib/geocoder/railtie.rb
107
108
  - lib/geocoder/request.rb
109
+ - lib/geocoder/results/abstract_api.rb
108
110
  - lib/geocoder/results/amap.rb
109
111
  - lib/geocoder/results/baidu.rb
110
112
  - lib/geocoder/results/baidu_ip.rb