geocoder 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of geocoder might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e556ddf944bdad35735def9028fafebcf61ee294
4
- data.tar.gz: a64476b63f73c13f24e385bc090193422bb92faa
2
+ SHA256:
3
+ metadata.gz: b6e1ac31854d2fcd30eb9cecb552d2b148b17355da7b15a71130cee3a432c335
4
+ data.tar.gz: 8cebc67335e4d3fd263249cc441673353cf0487415ccc8a855e2b457c6631e42
5
5
  SHA512:
6
- metadata.gz: '08394b88099374e31e32306a418865b2ffecc4df707044e277072b99d9cadc6f92e1acd70fc18884128f381e28c2c42571f66eb3968a983e214a5a1ca89cf839'
7
- data.tar.gz: 87dadf53fe66e26c2f3eec8bfc671b9cebaf76f50bd08f815ae8b08592bd2c87aab8fa1812ef07b282805383b81e93f9777d5224b5c86ebe412f6261fb9fe943
6
+ metadata.gz: 826c1fb83145b010b610d34e42b0719673b4c51ce755b639425e3072bdb96dddcf373e605dce9f33c34aba46e95db71f64b50a84df71c67189a81fc8426f344b
7
+ data.tar.gz: 698ef9a7643854cb7ac2316e22a51aed4a1a2ee763a8b65c9d7ab722566bbdcb3a95ce685389d20ecc164b3f9ccf1626deef21515d662d1339e88d28152985f7
@@ -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.5.2 (2019 Oct 3)
7
+ -------------------
8
+ * Add support for :ipregistry lookup (thanks github.com/ipregistry).
9
+ * Various fixes for Yandex lookup.
10
+
6
11
  1.5.1 (2019 Jan 23)
7
12
  -------------------
8
13
  * Add support for :tencent lookup (thanks github.com/Anders-E).
@@ -69,6 +69,7 @@ module Geocoder
69
69
  :pointpin,
70
70
  :maxmind_geoip2,
71
71
  :ipinfo_io,
72
+ :ipregistry,
72
73
  :ipapi_com,
73
74
  :ipdata_co,
74
75
  :db_ip_com,
@@ -197,6 +197,8 @@ module Geocoder
197
197
  raise_error(err) or Geocoder.log(:warn, "Geocoding API connection cannot be established.")
198
198
  rescue Errno::ECONNREFUSED => err
199
199
  raise_error(err) or Geocoder.log(:warn, "Geocoding API connection refused.")
200
+ rescue Geocoder::NetworkError => err
201
+ raise_error(err) or Geocoder.log(:warn, "Geocoding API connection is either unreacheable or reset by the peer")
200
202
  rescue Timeout::Error => err
201
203
  raise_error(err) or Geocoder.log(:warn, "Geocoding API not responding fast enough " +
202
204
  "(use Geocoder.configure(:timeout => ...) to set limit).")
@@ -10,7 +10,7 @@ module Geocoder::Lookup
10
10
 
11
11
  def supported_protocols
12
12
  if configuration[:host]
13
- [:http, :https]
13
+ [:https]
14
14
  else
15
15
  # use https for default host
16
16
  [:https]
@@ -44,8 +44,8 @@ module Geocoder::Lookup
44
44
  "city" => "",
45
45
  "region_code" => "",
46
46
  "region_name" => "",
47
- "metrocode" => "",
48
- "zipcode" => "",
47
+ "metro_code" => "",
48
+ "zip_code" => "",
49
49
  "latitude" => "0",
50
50
  "longitude" => "0",
51
51
  "country_name" => "Reserved",
@@ -54,7 +54,7 @@ module Geocoder::Lookup
54
54
  end
55
55
 
56
56
  def host
57
- configuration[:host] || "freegeoip.net"
57
+ configuration[:host] || "freegeoip.app"
58
58
  end
59
59
  end
60
60
  end
@@ -0,0 +1,68 @@
1
+ require 'geocoder/lookups/base'
2
+ require 'geocoder/results/ipregistry'
3
+
4
+ module Geocoder::Lookup
5
+ class Ipregistry < Base
6
+
7
+ ERROR_CODES = {
8
+ 400 => Geocoder::InvalidRequest,
9
+ 401 => Geocoder::InvalidRequest,
10
+ 402 => Geocoder::OverQueryLimitError,
11
+ 403 => Geocoder::InvalidApiKey,
12
+ 451 => Geocoder::RequestDenied,
13
+ 500 => Geocoder::Error
14
+ }
15
+ ERROR_CODES.default = Geocoder::Error
16
+
17
+ def name
18
+ "Ipregistry"
19
+ end
20
+
21
+ def supported_protocols
22
+ [:https, :http]
23
+ end
24
+
25
+ private
26
+
27
+ def base_query_url(query)
28
+ "#{protocol}://#{host}/#{query.sanitized_text}?"
29
+ end
30
+
31
+ def cache_key(query)
32
+ query_url(query)
33
+ end
34
+
35
+ def host
36
+ configuration[:host] || "api.ipregistry.co"
37
+ end
38
+
39
+ def query_url_params(query)
40
+ {
41
+ key: configuration.api_key
42
+ }.merge(super)
43
+ end
44
+
45
+ def results(query)
46
+ # don't look up a loopback or private address, just return the stored result
47
+ return [reserved_result(query.text)] if query.internal_ip_address?
48
+
49
+ return [] unless (doc = fetch_data(query))
50
+
51
+ if (error = doc['error'])
52
+ code = error['code']
53
+ msg = error['message']
54
+ raise_error(ERROR_CODES[code], msg ) || Geocoder.log(:warn, "Ipregistry API error: #{msg}")
55
+ return []
56
+ end
57
+ [doc]
58
+ end
59
+
60
+ def reserved_result(ip)
61
+ {
62
+ "ip" => ip,
63
+ "country_name" => "Reserved",
64
+ "country_code" => "RD"
65
+ }
66
+ end
67
+ end
68
+ end
@@ -50,8 +50,8 @@ module Geocoder::Lookup
50
50
  params = {
51
51
  :geocode => q,
52
52
  :format => "json",
53
- :plng => "#{query.language || configuration.language}", # supports ru, uk, be
54
- :key => configuration.api_key
53
+ :lang => "#{query.language || configuration.language}", # supports ru, uk, be, default -> ru
54
+ :apikey => configuration.api_key
55
55
  }
56
56
  unless (bounds = query.options[:bounds]).nil?
57
57
  params[:bbox] = bounds.map{ |point| "%f,%f" % point }.join('~')
@@ -27,7 +27,10 @@ module Geocoder::Result
27
27
  end
28
28
 
29
29
  def state
30
- address_data['County']
30
+ fail unless d = address_data['AdditionalData']
31
+ if v = d.find{|ad| ad['key']=='StateName'}
32
+ return v['value']
33
+ end
31
34
  end
32
35
 
33
36
  def province
@@ -0,0 +1,308 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Ipregistry < Base
5
+
6
+ def initialize(data)
7
+ super
8
+
9
+ @data = flatten_hash(data)
10
+ end
11
+
12
+ def flatten_hash(hash)
13
+ hash.each_with_object({}) do |(k, v), h|
14
+ if v.is_a? Hash
15
+ flatten_hash(v).map do |h_k, h_v|
16
+ h["#{k}_#{h_k}".to_s] = h_v
17
+ end
18
+ else
19
+ h[k] = v
20
+ end
21
+ end
22
+ end
23
+
24
+ private :flatten_hash
25
+
26
+ def city
27
+ @data['location_city']
28
+ end
29
+
30
+ def country
31
+ @data['location_country_name']
32
+ end
33
+
34
+ def country_code
35
+ @data['location_country_code']
36
+ end
37
+
38
+ def latitude
39
+ @data['location_latitude']
40
+ end
41
+
42
+ def longitude
43
+ @data['location_longitude']
44
+ end
45
+
46
+ def postal_code
47
+ @data['location_postal']
48
+ end
49
+
50
+ def state
51
+ @data['location_region_name']
52
+ end
53
+
54
+ def state_code
55
+ @data['location_region_code']
56
+ end
57
+
58
+ # methods for fields specific to Ipregistry
59
+
60
+ def ip
61
+ @data["ip"]
62
+ end
63
+
64
+ def type
65
+ @data["type"]
66
+ end
67
+
68
+ def hostname
69
+ @data["hostname"]
70
+ end
71
+
72
+ def carrier_name
73
+ @data["carrier_name"]
74
+ end
75
+
76
+ def carrier_mcc
77
+ @data["carrier_mcc"]
78
+ end
79
+
80
+ def carrier_mnc
81
+ @data["carrier_mnc"]
82
+ end
83
+
84
+ def connection_asn
85
+ @data["connection_asn"]
86
+ end
87
+
88
+ def connection_domain
89
+ @data["connection_domain"]
90
+ end
91
+
92
+ def connection_organization
93
+ @data["connection_organization"]
94
+ end
95
+
96
+ def connection_type
97
+ @data["connection_type"]
98
+ end
99
+
100
+ def currency_code
101
+ @data["currency_code"]
102
+ end
103
+
104
+ def currency_name
105
+ @data["currency_name"]
106
+ end
107
+
108
+ def currency_plural
109
+ @data["currency_plural"]
110
+ end
111
+
112
+ def currency_symbol
113
+ @data["currency_symbol"]
114
+ end
115
+
116
+ def currency_symbol_native
117
+ @data["currency_symbol_native"]
118
+ end
119
+
120
+ def currency_format_negative_prefix
121
+ @data["currency_format_negative_prefix"]
122
+ end
123
+
124
+ def currency_format_negative_suffix
125
+ @data["currency_format_negative_suffix"]
126
+ end
127
+
128
+ def currency_format_positive_prefix
129
+ @data["currency_format_positive_prefix"]
130
+ end
131
+
132
+ def currency_format_positive_suffix
133
+ @data["currency_format_positive_suffix"]
134
+ end
135
+
136
+ def location_continent_code
137
+ @data["location_continent_code"]
138
+ end
139
+
140
+ def location_continent_name
141
+ @data["location_continent_name"]
142
+ end
143
+
144
+ def location_country_area
145
+ @data["location_country_area"]
146
+ end
147
+
148
+ def location_country_borders
149
+ @data["location_country_borders"]
150
+ end
151
+
152
+ def location_country_calling_code
153
+ @data["location_country_calling_code"]
154
+ end
155
+
156
+ def location_country_capital
157
+ @data["location_country_capital"]
158
+ end
159
+
160
+ def location_country_code
161
+ @data["location_country_code"]
162
+ end
163
+
164
+ def location_country_name
165
+ @data["location_country_name"]
166
+ end
167
+
168
+ def location_country_population
169
+ @data["location_country_population"]
170
+ end
171
+
172
+ def location_country_population_density
173
+ @data["location_country_population_density"]
174
+ end
175
+
176
+ def location_country_flag_emoji
177
+ @data["location_country_flag_emoji"]
178
+ end
179
+
180
+ def location_country_flag_emoji_unicode
181
+ @data["location_country_flag_emoji_unicode"]
182
+ end
183
+
184
+ def location_country_flag_emojitwo
185
+ @data["location_country_flag_emojitwo"]
186
+ end
187
+
188
+ def location_country_flag_noto
189
+ @data["location_country_flag_noto"]
190
+ end
191
+
192
+ def location_country_flag_twemoji
193
+ @data["location_country_flag_twemoji"]
194
+ end
195
+
196
+ def location_country_flag_wikimedia
197
+ @data["location_country_flag_wikimedia"]
198
+ end
199
+
200
+ def location_country_languages
201
+ @data["location_country_languages"]
202
+ end
203
+
204
+ def location_country_tld
205
+ @data["location_country_tld"]
206
+ end
207
+
208
+ def location_region_code
209
+ @data["location_region_code"]
210
+ end
211
+
212
+ def location_region_name
213
+ @data["location_region_name"]
214
+ end
215
+
216
+ def location_city
217
+ @data["location_city"]
218
+ end
219
+
220
+ def location_postal
221
+ @data["location_postal"]
222
+ end
223
+
224
+ def location_latitude
225
+ @data["location_latitude"]
226
+ end
227
+
228
+ def location_longitude
229
+ @data["location_longitude"]
230
+ end
231
+
232
+ def location_language_code
233
+ @data["location_language_code"]
234
+ end
235
+
236
+ def location_language_name
237
+ @data["location_language_name"]
238
+ end
239
+
240
+ def location_language_native
241
+ @data["location_language_native"]
242
+ end
243
+
244
+ def location_in_eu
245
+ @data["location_in_eu"]
246
+ end
247
+
248
+ def security_is_bogon
249
+ @data["security_is_bogon"]
250
+ end
251
+
252
+ def security_is_cloud_provider
253
+ @data["security_is_cloud_provider"]
254
+ end
255
+
256
+ def security_is_tor
257
+ @data["security_is_tor"]
258
+ end
259
+
260
+ def security_is_tor_exit
261
+ @data["security_is_tor_exit"]
262
+ end
263
+
264
+ def security_is_proxy
265
+ @data["security_is_proxy"]
266
+ end
267
+
268
+ def security_is_anonymous
269
+ @data["security_is_anonymous"]
270
+ end
271
+
272
+ def security_is_abuser
273
+ @data["security_is_abuser"]
274
+ end
275
+
276
+ def security_is_attacker
277
+ @data["security_is_attacker"]
278
+ end
279
+
280
+ def security_is_threat
281
+ @data["security_is_threat"]
282
+ end
283
+
284
+ def time_zone_id
285
+ @data["time_zone_id"]
286
+ end
287
+
288
+ def time_zone_abbreviation
289
+ @data["time_zone_abbreviation"]
290
+ end
291
+
292
+ def time_zone_current_time
293
+ @data["time_zone_current_time"]
294
+ end
295
+
296
+ def time_zone_name
297
+ @data["time_zone_name"]
298
+ end
299
+
300
+ def time_zone_offset
301
+ @data["time_zone_offset"]
302
+ end
303
+
304
+ def time_zone_in_daylight_saving
305
+ @data["time_zone_in_daylight_saving"]
306
+ end
307
+ end
308
+ end
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.5.1"
2
+ VERSION = "1.5.2"
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.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-23 00:00:00.000000000 Z
11
+ date: 2019-10-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides object geocoding (by street or IP address), reverse geocoding
14
14
  (coordinates to street address), distance queries for ActiveRecord and Mongoid,
@@ -72,6 +72,7 @@ files:
72
72
  - lib/geocoder/lookups/ipapi_com.rb
73
73
  - lib/geocoder/lookups/ipdata_co.rb
74
74
  - lib/geocoder/lookups/ipinfo_io.rb
75
+ - lib/geocoder/lookups/ipregistry.rb
75
76
  - lib/geocoder/lookups/ipstack.rb
76
77
  - lib/geocoder/lookups/latlon.rb
77
78
  - lib/geocoder/lookups/location_iq.rb
@@ -124,6 +125,7 @@ files:
124
125
  - lib/geocoder/results/ipapi_com.rb
125
126
  - lib/geocoder/results/ipdata_co.rb
126
127
  - lib/geocoder/results/ipinfo_io.rb
128
+ - lib/geocoder/results/ipregistry.rb
127
129
  - lib/geocoder/results/ipstack.rb
128
130
  - lib/geocoder/results/latlon.rb
129
131
  - lib/geocoder/results/location_iq.rb
@@ -161,11 +163,7 @@ licenses:
161
163
  metadata:
162
164
  source_code_uri: https://github.com/alexreisner/geocoder
163
165
  changelog_uri: https://github.com/alexreisner/geocoder/blob/master/CHANGELOG.md
164
- post_install_message: |2+
165
-
166
-
167
- NOTE: Geocoder's default IP address lookup has changed from FreeGeoIP.net to IPInfo.io. If you explicitly specify :freegeoip in your configuration you must choose a different IP lookup before FreeGeoIP is discontinued on July 1, 2018. If you do not explicitly specify :freegeoip you do not need to change anything.
168
-
166
+ post_install_message:
169
167
  rdoc_options: []
170
168
  require_paths:
171
169
  - lib
@@ -181,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
179
  version: '0'
182
180
  requirements: []
183
181
  rubyforge_project:
184
- rubygems_version: 2.5.2
182
+ rubygems_version: 2.7.6
185
183
  signing_key:
186
184
  specification_version: 4
187
185
  summary: Complete geocoding solution for Ruby.