geokit 1.11.0 → 1.12.0

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
  SHA1:
3
- metadata.gz: a65b885be9e9d49c301e1c027f0b67ed5b6c0cf5
4
- data.tar.gz: 0a3f1ef269758d9647be947192d2137bc9239503
3
+ metadata.gz: 45cd130b831e467dddf0f1ee196ad1a9c454709d
4
+ data.tar.gz: abc3aae596ba4407b204936be4f5af7b7cc07ff6
5
5
  SHA512:
6
- metadata.gz: 4435c54ff2edb3ba749b2d8a2d5ed3a8a45fab5e22df8d3e1fd8a2da39a9ae30e6054f0c8f1a012d9dfe7cfd5677b02f9650234d3af708067766727a7e9dc94d
7
- data.tar.gz: b87976064a7e40f5d65e9fe7dc4afa36677449d390b41f3f63ed403b99c8404e4e6599700e12a956175f5e35db599d15a443456448864b1efd12dadcbc16e499
6
+ metadata.gz: f38b92f2a28271fe715528a4508af36f388b7303f54f1fd9423e939e36771912dadbbe84b88ff40a5a69f20596b9e14e12bd95bb1479cc450636c583796b6d0b
7
+ data.tar.gz: 6713c52093f575b38576a426586447f4b921d5df80f53f277145d82de36e8e1ad7f126bfdadf328d5772f4cbb450988036701753f9e69796ecd392376cb58e57
@@ -214,7 +214,7 @@ Style/Lambda:
214
214
 
215
215
  # Offense count: 4
216
216
  # Cop supports --auto-correct.
217
- Style/MethodCallParentheses:
217
+ Style/MethodCallWithoutArgsParentheses:
218
218
  Exclude:
219
219
  - 'test/test_maxmind_geocoder.rb'
220
220
 
@@ -1,3 +1,11 @@
1
+ ## 1.12.0
2
+
3
+ **Existing Geocoder Changes**
4
+ * FreegeoIp: Deprecated
5
+
6
+ **Other Changes**
7
+ * Added Ipstack which replaces Freegeoip
8
+
1
9
  ## 1.11.0
2
10
 
3
11
  **Existing Geocoder Changes**
@@ -62,7 +62,9 @@ Combine this gem with the [geokit-rails](http://github.com/geokit/geokit-rails)
62
62
  * Geobytes
63
63
  * RIPE
64
64
  * MaxMind
65
- * freegeoip.net
65
+ * Ipstack
66
+ * freegeoip.net (deprecated, now Ipstack)
67
+ * IP-API.com
66
68
 
67
69
  ### HTTPS-supporting geocoders
68
70
  * Google
@@ -169,6 +171,11 @@ If you're using this gem by itself, here are the configuration options:
169
171
  # See http://www.geonames.org
170
172
  Geokit::Geocoders::GeonamesGeocoder.key = 'KEY'
171
173
 
174
+ # This is your access key for ipstack.
175
+ # To use this service either free or premium, you must register a key.
176
+ # See https://ipstack.com
177
+ Geokit::Geocoders::IpstackGeocoder.api_key = 'API_KEY'
178
+
172
179
  # Most other geocoders need either no setup or a key
173
180
  Geokit::Geocoders::BingGeocoder.key = ''
174
181
  Geokit::Geocoders::MapQuestGeocoder.key = ''
@@ -187,13 +194,19 @@ If you're using this gem by itself, here are the configuration options:
187
194
 
188
195
  # This is the order in which the geocoders are called in a failover scenario
189
196
  # If you only want to use a single geocoder, put a single symbol in the array.
190
- # Valid symbols are :google, :yahoo, :us, and :ca.
197
+ #
198
+ # Valid symbols are: :bing, :ca, :fcc, :geocodio, :geonames, :google,
199
+ # :map_quest, :mapbox, :maxmind, :opencage, :osm, :us, :yahoo, and :yandex.
200
+ #
191
201
  # Be aware that there are Terms of Use restrictions on how you can use the
192
202
  # various geocoders. Make sure you read up on relevant Terms of Use for each
193
203
  # geocoder you are going to use.
194
204
  Geokit::Geocoders::provider_order = [:google,:us]
195
205
 
196
- # The IP provider order. Valid symbols are :ip,:geo_plugin.
206
+ # The IP provider order.
207
+ #
208
+ # Valid symbols are :ipstack, :geo_plugin, :geobytes, :ip, and :ripe.
209
+ #
197
210
  # As before, make sure you read up on relevant Terms of Use for each.
198
211
  # Geokit::Geocoders::ip_provider_order = [:external,:geo_plugin,:ip]
199
212
 
@@ -0,0 +1,35 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://ip-api.com/json/74.125.237.209
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Access-Control-Allow-Origin:
22
+ - "*"
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Date:
26
+ - Sat, 23 Sep 2017 04:40:17 GMT
27
+ Content-Length:
28
+ - '287'
29
+ body:
30
+ encoding: UTF-8
31
+ string: '{"as":"AS15169 Google Inc.","city":"Mountain View","country":"United
32
+ States","countryCode":"US","isp":"Google","lat":37.4192,"lon":-122.0574,"org":"Google","query":"74.125.237.209","region":"CA","regionName":"California","status":"success","timezone":"America/Los_Angeles","zip":"94043"}'
33
+ http_version:
34
+ recorded_at: Sat, 23 Sep 2017 04:34:33 GMT
35
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.ipstack.com/68.194.36.44?access_key=some_api_key
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Tue, 08 May 2018 13:21:13 GMT
25
+ Content-Type:
26
+ - application/json; Charset=UTF-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ X-Apilayer-Transaction-Id:
30
+ - 595071a3-1531-41eb-8697-1143f21a78cb
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ X-Request-Time:
34
+ - '0.026'
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"ip":"68.194.36.44","type":"ipv4","continent_code":"NA","continent_name":"North
38
+ America","country_code":"US","country_name":"United States","region_code":"NY","region_name":"New
39
+ York","city":"The Bronx","zip":"10466","latitude":40.8913,"longitude":-73.8448,"location":{"geoname_id":5110266,"capital":"Washington
40
+ D.C.","languages":[{"code":"en","name":"English","native":"English"}],"country_flag":"http:\/\/assets.ipstack.com\/flags\/us.svg","country_flag_emoji":"\ud83c\uddfa\ud83c\uddf8","country_flag_emoji_unicode":"U+1F1FA
41
+ U+1F1F8","calling_code":"1","is_eu":false}}'
42
+ http_version:
43
+ recorded_at: Tue, 08 May 2018 13:21:13 GMT
44
+ recorded_with: VCR 4.0.0
@@ -26,6 +26,7 @@ module Geokit
26
26
  # ### IP address geocoders
27
27
  # * IP Geocoder - geocodes an IP address using hostip.info's web service.
28
28
  # * Geoplugin.net -- another IP address geocoder
29
+ # * IP-API.com -- another IP address geocoder
29
30
  #
30
31
  # ### The Multigeocoder
31
32
  # * Multi Geocoder - provides failover for the physical location geocoders.
@@ -39,6 +40,7 @@ module Geokit
39
40
  @@ip_provider_order = [:geo_plugin, :ip]
40
41
  @@logger = Logger.new(STDOUT)
41
42
  @@logger.level = Logger::INFO
43
+ @@host = nil
42
44
  @@domain = nil
43
45
  @@net_adapter = Geokit::NetAdapter::NetHttp
44
46
  @@secure = true
@@ -5,6 +5,10 @@ module Geokit
5
5
  private
6
6
 
7
7
  def self.do_geocode(ip, _=nil)
8
+ warn '[DEPRECATION] `freegeoip` is deprecated. Please use `ipstack`'\
9
+ ' instead. You can find more at'\
10
+ ' https://github.com/apilayer/freegeoip#readme'
11
+
8
12
  process :xml, ip
9
13
  end
10
14
 
@@ -1,7 +1,7 @@
1
1
  module Geokit
2
2
  module Geocoders
3
3
  class GoogleGeocoder < Geocoder
4
- config :client_id, :cryptographic_key, :channel, :api_key
4
+ config :client_id, :cryptographic_key, :channel, :api_key, :host
5
5
  self.secure = true
6
6
 
7
7
  private
@@ -89,7 +89,8 @@ module Geokit
89
89
  url_with_key = query_string + "&key=#{api_key}"
90
90
  "#{protocol}://maps.googleapis.com" + url_with_key
91
91
  else
92
- "#{protocol}://maps.google.com" + query_string
92
+ request_host = host || 'maps.google.com'
93
+ "#{protocol}://#{request_host}#{query_string}"
93
94
  end
94
95
  end
95
96
 
@@ -0,0 +1,31 @@
1
+ module Geokit
2
+ module Geocoders
3
+ # Provides geocoding based upon an IP address. The underlying web service is ip-api.com
4
+ class IpApiGeocoder < BaseIpGeocoder
5
+ private
6
+
7
+ def self.do_geocode(ip, _=nil)
8
+ process :json, ip
9
+ end
10
+
11
+ def self.submit_url(ip)
12
+ "http://ip-api.com/json/#{ip}"
13
+ end
14
+
15
+ def self.parse_json(result)
16
+ loc = new_loc
17
+ return loc unless result['status'] == 'success'
18
+
19
+ loc.success = true
20
+ loc.city = result['city']
21
+ loc.state = result['region']
22
+ loc.state_name = result['regionName']
23
+ loc.zip = result['zip']
24
+ loc.lat = result['lat']
25
+ loc.lng = result['lon']
26
+ loc.country_code = result['countryCode']
27
+ loc
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ module Geokit
2
+ module Geocoders
3
+ # Provides geocoding based upon an IP address. The underlying web service is
4
+ # ipstack, old freegeoip.net
5
+ class IpstackGeocoder < BaseIpGeocoder
6
+ config :api_key
7
+
8
+ private
9
+
10
+ def self.do_geocode(ip, _options = nil)
11
+ process :json, ip
12
+ end
13
+
14
+ def self.submit_url(ip)
15
+ "http://api.ipstack.com/#{ip}?access_key=#{api_key}"
16
+ end
17
+
18
+ def self.parse_json(result)
19
+ loc = new_loc
20
+ return loc if result['success'] == false
21
+
22
+ loc.city = result['city']
23
+ loc.state_code = result['region_code']
24
+ loc.state_name = result['region_name']
25
+ loc.zip = result['zip']
26
+ loc.lat = result['latitude']
27
+ loc.lng = result['longitude']
28
+ loc.country_code = result['country_code']
29
+ loc.country = result['country_name']
30
+ loc.success = !loc.city.nil?
31
+
32
+ loc
33
+ end
34
+ end
35
+ end
36
+ end
@@ -118,7 +118,7 @@ module Geokit
118
118
  end
119
119
 
120
120
  def self.from_string(thing)
121
- thing.strip!
121
+ thing = thing.strip
122
122
  match = thing.match(/(\-?\d+\.?\d*)[, ] ?(\-?\d+\.?\d*)$/)
123
123
  if match
124
124
  Geokit::LatLng.new(match[1], match[2])
@@ -1,3 +1,3 @@
1
1
  module Geokit
2
- VERSION = '1.11.0'
2
+ VERSION = '1.12.0'
3
3
  end
@@ -50,6 +50,19 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
50
50
  assert_equal 'http://maps.google.com/maps/api/geocode/json?sensor=false&address=New+York', url
51
51
  end
52
52
 
53
+ def test_google_cn
54
+ Geokit::Geocoders.host = 'maps.google.cn'
55
+ url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
56
+ TestHelper.expects(:last_url).with(url)
57
+ res = geocode(@address, :google_full_short)
58
+ assert_equal 'CA', res.state
59
+ assert_equal 'San Francisco', res.city
60
+ assert_array_in_delta [37.7749295, -122.4194155], res.to_a # slightly dif from yahoo
61
+ assert res.is_us?
62
+ assert_equal 'San Francisco, CA, USA', res.full_address # slightly different from yahoo
63
+ assert_equal 'google', res.provider
64
+ end
65
+
53
66
  def test_google_full_address
54
67
  url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
55
68
  TestHelper.expects(:last_url).with(url)
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class IpApiGeocoderTest < BaseGeocoderTest #:nodoc: all
4
+ def setup
5
+ super
6
+ @ip = '74.125.237.209'
7
+ end
8
+
9
+ def assert_url(expected_url)
10
+ assert_equal expected_url, TestHelper.last_url
11
+ end
12
+
13
+ def test_free_geo_ip_geocode
14
+ url = "http://ip-api.com/json/#{@ip}"
15
+ res = geocode(@ip, :ip_api_geocode)
16
+ assert_url url
17
+ assert_equal res.city, 'Mountain View'
18
+ assert_equal res.state, 'CA'
19
+ assert_equal res.state_name, 'California'
20
+ assert_equal res.zip, '94043'
21
+ assert_equal res.country_code, 'US'
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class IpstackGeocoderTest < BaseGeocoderTest #:nodoc: all
4
+ def setup
5
+ super
6
+ @ip = '68.194.36.44'
7
+ geocoder_class.api_key = 'some_api_key'
8
+ end
9
+
10
+ def assert_url(expected_url)
11
+ assert_equal expected_url, TestHelper.last_url
12
+ end
13
+
14
+ def test_free_geo_ip_geocode
15
+ url = "http://api.ipstack.com/#{@ip}?access_key=some_api_key"
16
+ res = geocode(@ip, :ipstack_geocode)
17
+
18
+ assert_url url
19
+ assert_equal res.city, 'The Bronx'
20
+ assert_equal res.state, 'NY'
21
+ assert_equal res.state_name, 'New York'
22
+ assert_equal res.zip, '10466'
23
+ assert_equal res.country_code, 'US'
24
+ assert_equal res.country, 'United States'
25
+ assert_equal res.success?, true
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Noack
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-03-26 00:00:00.000000000 Z
14
+ date: 2018-05-10 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -226,6 +226,8 @@ files:
226
226
  - fixtures/vcr_cassettes/google_reverse_madrid.yml
227
227
  - fixtures/vcr_cassettes/google_reverse_madrid_es.yml
228
228
  - fixtures/vcr_cassettes/google_sublocality.yml
229
+ - fixtures/vcr_cassettes/ip_api_geocode.yml
230
+ - fixtures/vcr_cassettes/ipstack_geocode.yml
229
231
  - fixtures/vcr_cassettes/map_quest_full.yml
230
232
  - fixtures/vcr_cassettes/map_quest_reverse_madrid.yml
231
233
  - fixtures/vcr_cassettes/mapbox_forward_geocode.yml
@@ -263,6 +265,8 @@ files:
263
265
  - lib/geokit/geocoders/geonames.rb
264
266
  - lib/geokit/geocoders/google.rb
265
267
  - lib/geokit/geocoders/ip.rb
268
+ - lib/geokit/geocoders/ip_api_geocoder.rb
269
+ - lib/geokit/geocoders/ipstack.rb
266
270
  - lib/geokit/geocoders/mapbox.rb
267
271
  - lib/geokit/geocoders/mapquest.rb
268
272
  - lib/geokit/geocoders/maxmind.rb
@@ -295,7 +299,9 @@ files:
295
299
  - test/test_geonames_geocoder.rb
296
300
  - test/test_google_geocoder.rb
297
301
  - test/test_inflector.rb
302
+ - test/test_ip_api_geocoder.rb
298
303
  - test/test_ipgeocoder.rb
304
+ - test/test_ipstack_geocoder.rb
299
305
  - test/test_latlng.rb
300
306
  - test/test_map_quest.rb
301
307
  - test/test_mapbox_geocoder.rb
@@ -335,7 +341,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
335
341
  version: '0'
336
342
  requirements: []
337
343
  rubyforge_project:
338
- rubygems_version: 2.4.8
344
+ rubygems_version: 2.6.14.1
339
345
  signing_key:
340
346
  specification_version: 4
341
347
  summary: 'Geokit: encoding and distance calculation gem'
@@ -355,7 +361,9 @@ test_files:
355
361
  - test/test_geonames_geocoder.rb
356
362
  - test/test_google_geocoder.rb
357
363
  - test/test_inflector.rb
364
+ - test/test_ip_api_geocoder.rb
358
365
  - test/test_ipgeocoder.rb
366
+ - test/test_ipstack_geocoder.rb
359
367
  - test/test_latlng.rb
360
368
  - test/test_map_quest.rb
361
369
  - test/test_mapbox_geocoder.rb