geocoder 1.8.6 → 1.8.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b8e84b8e86854f7aadc62c7b2a5258af91c7a24e80e99755e3f96629bb501f3
4
- data.tar.gz: 5f2ddd4bb79edb7a05539f8bd58108a5b84359a46f6fea711770b575428c628f
3
+ metadata.gz: 82e2dc20fcf436852ca1ddd96dec78fa6dbe34f4ea10b26dfdefd73df2f111a7
4
+ data.tar.gz: 168e22b16884788bf2d7a0ddb656a20669786c423852e496254b84e9b9e6c11b
5
5
  SHA512:
6
- metadata.gz: a42721f88ac240ccf70e58d3ff9556e413727ce385c28b40aef5a9a43819468b91a58c8543d3f267452fd1f5560dfd7cbf7d6e01f77d0d8d7cef23dbc1d5bf81
7
- data.tar.gz: eb50fe5f2852c809778ff329a11d189a6ac226d6b2c99404b530c75bae316211cf79cbc3d2d2ef391b73a1dd0dbba57fb6b9bfc8ec597a63e7027929bd0ad0e6
6
+ metadata.gz: f6c10115d958e26de1663f0a3c237588edc78001d47d5c237103c9073b3ead4252f5947c2ba52c52259cac725da6527a953ff2c867971b5eb26d3077f70745cb
7
+ data.tar.gz: 7153b887cee3335cfbc01a47c4e200736796bdd8b63ece5d8321c30294c3e2acd0d48dca8e47e7c59ae26aa763e86ae578b5369b9069e1910854e18de2834389
data/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@ 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.7 (2026 Nov 30)
7
+ -------------------
8
+ * Add support for IPWho lookup (@methogit).
9
+ * Add support for InternetData IP lookup (@UmanShahzad).
10
+ * Update support for Mapbox v6 lookup (@takatea).
11
+ * Drop support for Ruby <2.5.
12
+ * Fix configuration options merging bug (@ihamzatarar).
13
+
6
14
  1.8.6 (2025 Sep 21)
7
15
  -------------------
8
16
  * Add support for IPInfo Lite lookup (thanks github.com/iltempo).
data/README.md CHANGED
@@ -4,7 +4,6 @@ Geocoder
4
4
  **Complete geocoding solution for Ruby.**
5
5
 
6
6
  [![Gem Version](https://badge.fury.io/rb/geocoder.svg)](http://badge.fury.io/rb/geocoder)
7
- [![Code Climate](https://codeclimate.com/github/alexreisner/geocoder/badges/gpa.svg)](https://codeclimate.com/github/alexreisner/geocoder)
8
7
 
9
8
  Key features:
10
9
 
@@ -17,9 +16,9 @@ Key features:
17
16
 
18
17
  Compatibility:
19
18
 
20
- * Ruby versions: 2.1+, and JRuby.
19
+ * Ruby versions: 2.5+ and JRuby.
21
20
  * Databases: MySQL, PostgreSQL, SQLite, and MongoDB.
22
- * Rails: 5.x, 6.x, and 7.x.
21
+ * Rails: 5.x, 6.x, 7.x and 8.x.
23
22
  * Works outside of Rails with the `json` (for MRI) or `json_pure` (for JRuby) gem.
24
23
 
25
24
 
@@ -348,6 +347,16 @@ This example uses Redis, but the cache store can be any object that supports the
348
347
 
349
348
  Even a plain Ruby hash will work, though it's not a great choice (cleared out when app is restarted, not shared between app instances, etc).
350
349
 
350
+ Geocoder chooses a cache store adapter based on the class name of the configured object: a `Redis` instance is handled by `Geocoder::CacheStore::Redis` (which applies the `expiration` given in `cache_options`), while any other object falls back to `Geocoder::CacheStore::Generic`, which does **not** apply `expiration`. If your store's class name is not recognized -- for example a Redis client wrapped in a custom namespacing class -- pass a cache store instance directly to bypass the class name lookup:
351
+
352
+ ```ruby
353
+ Geocoder.configure(
354
+ cache: Geocoder::CacheStore::Redis.new(MyRedisWrapper.new, {prefix: "geocoder:", expiration: 2.days})
355
+ )
356
+ ```
357
+
358
+ When a `Geocoder::CacheStore::Base` instance is given, `cache_options` is ignored: pass the options to the store constructor instead, as in the example above.
359
+
351
360
  When using Rails use the Generic cache store as an adapter around `Rails.cache`:
352
361
 
353
362
  ```ruby
@@ -4,8 +4,12 @@ module Geocoder
4
4
  class Cache
5
5
 
6
6
  def initialize(store, config)
7
- @class = (Geocoder::CacheStore.const_get("#{store.class}", false) rescue Geocoder::CacheStore::Generic)
8
- @store_service = @class.new(store, config)
7
+ if store.is_a?(Geocoder::CacheStore::Base)
8
+ @store_service = store
9
+ else
10
+ @class = (Geocoder::CacheStore.const_get("#{store.class}", false) rescue Geocoder::CacheStore::Generic)
11
+ @store_service = @class.new(store, config)
12
+ end
9
13
  end
10
14
 
11
15
  ##
data/lib/geocoder/cli.rb CHANGED
@@ -65,7 +65,7 @@ module Geocoder
65
65
  out << "Look up geographic information about a location.\n\n"
66
66
  out << opts
67
67
  out << "\nCreated and maintained by Alex Reisner, available under the MIT License.\n"
68
- out << "Report bugs and contribute at http://github.com/alexreisner/geocoder\n"
68
+ out << "Report bugs and contribute at https://github.com/alexreisner/geocoder\n"
69
69
  exit
70
70
  end
71
71
  }.parse!(args)
@@ -106,12 +106,15 @@ module Geocoder
106
106
  @data[:lookup] = :nominatim # name of street address geocoding service (symbol)
107
107
  @data[:ip_lookup] = :ipinfo_io # name of IP address geocoding service (symbol)
108
108
  @data[:language] = :en # ISO-639 language code
109
- @data[:http_headers] = {} # HTTP headers for lookup
110
- @data[:use_https] = false # use HTTPS for lookup requests? (if supported)
109
+ # The hash options below are ConfigurationHashes so that Geocoder.configure
110
+ # merges into their defaults instead of replacing them, which would silently
111
+ # drop any key the caller did not repeat.
112
+ @data[:http_headers] = ConfigurationHash[] # HTTP headers for lookup
113
+ @data[:use_https] = true # use HTTPS for lookup requests? (if supported)
111
114
  @data[:http_proxy] = nil # HTTP proxy server (user:pass@host:port)
112
115
  @data[:https_proxy] = nil # HTTPS proxy server (user:pass@host:port)
113
116
  @data[:api_key] = nil # API key for geocoding service
114
- @data[:basic_auth] = {} # user and password for basic auth ({:user => "user", :password => "password"})
117
+ @data[:basic_auth] = ConfigurationHash[] # user and password for basic auth ({:user => "user", :password => "password"})
115
118
  @data[:logger] = :kernel # :kernel or Logger instance
116
119
  @data[:kernel_logger_level] = ::Logger::WARN # log level, if kernel logger is used
117
120
 
@@ -129,10 +132,10 @@ module Geocoder
129
132
  # addresses will rarely change.
130
133
  @data[:cache] = nil # cache object (must respond to #[], #[]=, and optionally #keys)
131
134
  @data[:cache_prefix] = nil # - DEPRECATED - prefix (string) to use for all cache keys
132
- @data[:cache_options] = {
135
+ @data[:cache_options] = ConfigurationHash[
133
136
  prefix: 'geocoder:',
134
137
  expiration: nil
135
- }
138
+ ]
136
139
  end
137
140
 
138
141
  instance_eval(OPTIONS.map do |option|
@@ -98,7 +98,9 @@ module Geocoder
98
98
  :ipqualityscore,
99
99
  :ipbase,
100
100
  :ip2location_io,
101
- :ip2location_lite
101
+ :ip2location_lite,
102
+ :internetdata,
103
+ :ipwho
102
104
  ]
103
105
  end
104
106
 
@@ -14,6 +14,10 @@ module Geocoder::Lookup
14
14
  "https://www.openstreetmap.org/#map=19/#{coordinates.join('/')}"
15
15
  end
16
16
 
17
+ def supported_protocols
18
+ [:https]
19
+ end
20
+
17
21
  private # ---------------------------------------------------------------
18
22
 
19
23
  def base_query_url(query)
@@ -19,6 +19,7 @@ module Geocoder::Lookup
19
19
  private # ---------------------------------------------------------------
20
20
 
21
21
  def base_query_url(query)
22
+ require 'erb' unless defined?(ERB) && defined?(ERB::Util.url_encode)
22
23
  text = ERB::Util.url_encode(query.sanitized_text.strip)
23
24
  url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations/"
24
25
  if query.reverse_geocode?
@@ -0,0 +1,47 @@
1
+ require 'geocoder/lookups/base'
2
+ require 'geocoder/results/internetdata'
3
+
4
+ module Geocoder::Lookup
5
+ class Internetdata < Base
6
+ def name
7
+ 'InternetData'
8
+ end
9
+
10
+ # The API refuses a key sent over plain HTTP.
11
+ def supported_protocols
12
+ [:https]
13
+ end
14
+
15
+ private # ---------------------------------------------------------------
16
+
17
+ def base_query_url(query)
18
+ url = "#{protocol}://api.internetdata.io/#{query.sanitized_text}"
19
+ url << '?' if configuration.api_key
20
+ url
21
+ end
22
+
23
+ def results(query)
24
+ # don't look up a loopback or private address, just return the stored result
25
+ return [reserved_result(query.text)] if query.internal_ip_address?
26
+
27
+ if !(doc = fetch_data(query)).is_a?(Hash) or doc['error']
28
+ []
29
+ else
30
+ [doc]
31
+ end
32
+ end
33
+
34
+ def reserved_result(ip)
35
+ {
36
+ 'ip' => ip,
37
+ 'is_bogon' => true
38
+ }
39
+ end
40
+
41
+ def query_url_params(query)
42
+ {
43
+ apikey: configuration.api_key
44
+ }.merge(super)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,67 @@
1
+ require 'geocoder/lookups/base'
2
+ require 'geocoder/results/ipwho'
3
+
4
+ module Geocoder::Lookup
5
+ class Ipwho < Base
6
+
7
+ def name
8
+ 'IPWho'
9
+ end
10
+
11
+ def required_api_key_parts
12
+ ['key']
13
+ end
14
+
15
+ # an API key is required, so don't offer plain HTTP
16
+ def supported_protocols
17
+ [:https]
18
+ end
19
+
20
+ private # ---------------------------------------------------------------
21
+
22
+ def base_query_url(query)
23
+ "#{protocol}://api.ipwho.org/ip/#{query.sanitized_text}?"
24
+ end
25
+
26
+ def query_url_params(query)
27
+ # "api_key" contains "key", so the base class leaves it out of cache keys
28
+ {
29
+ api_key: configuration.api_key
30
+ }.merge(super)
31
+ end
32
+
33
+ def results(query)
34
+ # don't look up a loopback or private address, just return the stored result
35
+ return [reserved_result(query.text)] if query.internal_ip_address?
36
+
37
+ doc = fetch_data(query)
38
+ return [] unless doc.is_a?(Hash) and doc['success'] == true and doc['data'].is_a?(Hash)
39
+
40
+ [doc['data']]
41
+ end
42
+
43
+ def reserved_result(ip)
44
+ {
45
+ 'ip' => ip,
46
+ 'geoLocation' => {
47
+ 'country' => 'Reserved',
48
+ 'countryCode' => 'RD'
49
+ }
50
+ }
51
+ end
52
+
53
+ # authentication errors are 401 or 403 with a body such as {"error": "invalid_api_key"}
54
+ def check_response_for_errors!(response)
55
+ case response.code.to_i
56
+ when 401
57
+ raise_error(Geocoder::InvalidApiKey) ||
58
+ Geocoder.log(:warn, 'IPWho API error: 401 missing or invalid API key')
59
+ when 403
60
+ raise_error(Geocoder::RequestDenied) ||
61
+ Geocoder.log(:warn, 'IPWho API error: 403 request denied, check the plan of your API key')
62
+ else
63
+ super(response)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -14,6 +14,10 @@ module Geocoder::Lookup
14
14
 
15
15
  private # ---------------------------------------------------------------
16
16
 
17
+ def supported_protocols
18
+ [:https]
19
+ end
20
+
17
21
  def base_query_url(query)
18
22
  method = query.reverse_geocode? ? "reverse" : "search"
19
23
  "#{protocol}://#{configured_host}/#{method}?"
@@ -10,7 +10,7 @@ module Geocoder::Lookup
10
10
  private # ---------------------------------------------------------------
11
11
 
12
12
  def supported_protocols
13
- [:http, :https]
13
+ [:https]
14
14
  end
15
15
 
16
16
  def base_query_url(query)
@@ -50,9 +50,10 @@ module Geocoder
50
50
  properties['state']
51
51
  end
52
52
 
53
- # Not currently available in the API
54
53
  def state_code
55
- ''
54
+ return '' unless properties['state_code']
55
+
56
+ properties['state_code'].upcase
56
57
  end
57
58
 
58
59
  def country
@@ -0,0 +1,94 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Internetdata < Base
5
+
6
+ def coordinates
7
+ [location['latitude'], location['longitude']]
8
+ end
9
+
10
+ def address(format = :full)
11
+ [city, state, country].reject { |s| s.to_s.empty? }.join(', ')
12
+ end
13
+
14
+ def city
15
+ location['city']
16
+ end
17
+
18
+ def state
19
+ location['region']
20
+ end
21
+
22
+ def state_code
23
+ location['region_code']
24
+ end
25
+
26
+ def postal_code
27
+ location['postal_code']
28
+ end
29
+
30
+ def country
31
+ location['country_name']
32
+ end
33
+
34
+ def country_code
35
+ location['country']
36
+ end
37
+
38
+ # methods for fields specific to InternetData
39
+
40
+ def ip
41
+ @data['ip']
42
+ end
43
+
44
+ def time_zone
45
+ location['timezone']
46
+ end
47
+
48
+ def continent_code
49
+ location['continent']
50
+ end
51
+
52
+ def hostname
53
+ @data['hostname']
54
+ end
55
+
56
+ def asn
57
+ section('asn')['asn']
58
+ end
59
+
60
+ def as_name
61
+ section('asn')['name']
62
+ end
63
+
64
+ def company_name
65
+ section('company')['name']
66
+ end
67
+
68
+ def company_domain
69
+ section('company')['domain']
70
+ end
71
+
72
+ def abuse_email
73
+ section('abuse')['email']
74
+ end
75
+
76
+ def bogon?
77
+ @data['is_bogon'] == true
78
+ end
79
+
80
+ def tor?
81
+ @data['is_tor'] == true
82
+ end
83
+
84
+ private
85
+
86
+ def location
87
+ section('location')
88
+ end
89
+
90
+ def section(key)
91
+ @data[key].is_a?(Hash) ? @data[key] : {}
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,93 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Ipwho < Base
5
+
6
+ # any location field can be null in the response, so nil is kept as nil
7
+ # rather than turned into 0.0
8
+ def coordinates
9
+ [location['latitude'], location['longitude']].map { |value| value && value.to_f }
10
+ end
11
+
12
+ def address(format = :full)
13
+ [city, state, country].reject { |s| s.to_s.empty? }.join(', ')
14
+ end
15
+
16
+ def city
17
+ location['city']
18
+ end
19
+
20
+ def state
21
+ location['region']
22
+ end
23
+
24
+ def state_code
25
+ location['regionCode']
26
+ end
27
+
28
+ def postal_code
29
+ location['postal_Code']
30
+ end
31
+
32
+ def country
33
+ location['country']
34
+ end
35
+
36
+ def country_code
37
+ location['countryCode']
38
+ end
39
+
40
+ # methods for fields specific to IPWho
41
+
42
+ def ip
43
+ @data['ip']
44
+ end
45
+
46
+ def continent
47
+ location['continent']
48
+ end
49
+
50
+ def continent_code
51
+ location['continentCode']
52
+ end
53
+
54
+ # radius in kilometres around the coordinates
55
+ def accuracy_radius
56
+ location['accuracy_radius']
57
+ end
58
+
59
+ def time_zone
60
+ timezone['time_zone']
61
+ end
62
+
63
+ def timezone
64
+ section('timezone')
65
+ end
66
+
67
+ def flag
68
+ section('flag')
69
+ end
70
+
71
+ def currency
72
+ section('currency')
73
+ end
74
+
75
+ def connection
76
+ section('connection')
77
+ end
78
+
79
+ def security
80
+ section('security')
81
+ end
82
+
83
+ private
84
+
85
+ def location
86
+ section('geoLocation')
87
+ end
88
+
89
+ def section(key)
90
+ @data[key].is_a?(Hash) ? @data[key] : {}
91
+ end
92
+ end
93
+ end
@@ -19,6 +19,10 @@ module Geocoder::Result
19
19
  data_part('place') || context_part('place')
20
20
  end
21
21
 
22
+ def county
23
+ data_part('district') || context_part('district')
24
+ end
25
+
22
26
  def state
23
27
  data_part('region') || context_part('region')
24
28
  end
@@ -16,6 +16,10 @@ module Geocoder::Result
16
16
  @data['display_name']
17
17
  end
18
18
 
19
+ def street_address
20
+ [house_number, street].compact.join(' ')
21
+ end
22
+
19
23
  def street
20
24
  %w[road pedestrian highway].each do |key|
21
25
  return address_data[key] if address_data.key?(key)
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.8.6"
2
+ VERSION = "1.8.7"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geocoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.6
4
+ version: 1.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-09-21 00:00:00.000000000 Z
10
+ date: 2026-11-30 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: base64
@@ -100,6 +100,7 @@ files:
100
100
  - lib/geocoder/lookups/google_places_search.rb
101
101
  - lib/geocoder/lookups/google_premier.rb
102
102
  - lib/geocoder/lookups/here.rb
103
+ - lib/geocoder/lookups/internetdata.rb
103
104
  - lib/geocoder/lookups/ip2location.rb
104
105
  - lib/geocoder/lookups/ip2location_io.rb
105
106
  - lib/geocoder/lookups/ip2location_lite.rb
@@ -112,6 +113,7 @@ files:
112
113
  - lib/geocoder/lookups/ipqualityscore.rb
113
114
  - lib/geocoder/lookups/ipregistry.rb
114
115
  - lib/geocoder/lookups/ipstack.rb
116
+ - lib/geocoder/lookups/ipwho.rb
115
117
  - lib/geocoder/lookups/latlon.rb
116
118
  - lib/geocoder/lookups/location_iq.rb
117
119
  - lib/geocoder/lookups/mapbox.rb
@@ -169,6 +171,7 @@ files:
169
171
  - lib/geocoder/results/google_places_search.rb
170
172
  - lib/geocoder/results/google_premier.rb
171
173
  - lib/geocoder/results/here.rb
174
+ - lib/geocoder/results/internetdata.rb
172
175
  - lib/geocoder/results/ip2location.rb
173
176
  - lib/geocoder/results/ip2location_io.rb
174
177
  - lib/geocoder/results/ip2location_lite.rb
@@ -181,6 +184,7 @@ files:
181
184
  - lib/geocoder/results/ipqualityscore.rb
182
185
  - lib/geocoder/results/ipregistry.rb
183
186
  - lib/geocoder/results/ipstack.rb
187
+ - lib/geocoder/results/ipwho.rb
184
188
  - lib/geocoder/results/latlon.rb
185
189
  - lib/geocoder/results/location_iq.rb
186
190
  - lib/geocoder/results/mapbox.rb
@@ -232,14 +236,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
232
236
  requirements:
233
237
  - - ">="
234
238
  - !ruby/object:Gem::Version
235
- version: 2.0.0
239
+ version: 2.5.0
236
240
  required_rubygems_version: !ruby/object:Gem::Requirement
237
241
  requirements:
238
242
  - - ">="
239
243
  - !ruby/object:Gem::Version
240
244
  version: '0'
241
245
  requirements: []
242
- rubygems_version: 3.6.3
246
+ rubygems_version: 3.6.9
243
247
  specification_version: 4
244
248
  summary: Complete geocoding solution for Ruby.
245
249
  test_files: []