geocoder 1.2.2 → 1.2.3

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
2
  SHA1:
3
- metadata.gz: 83f0267dc6d6f5b13f1a3a26f1c901e88618e9cc
4
- data.tar.gz: d571a2205694b66dac921798eb8ae8c6d497a92e
3
+ metadata.gz: 29ab290c8d6f4d7604e92add7c07f37b47b9f7c1
4
+ data.tar.gz: 6cbd84ac0eac3f768f68e69024232c3ab489ee48
5
5
  SHA512:
6
- metadata.gz: 78e3b5fe48c4f6827e71345e85a6edfddbb14efcaa05ebdb57ad63f7f0f4b8bf4a653e9ab75da333ebec94eb9e14745b62181cf3f77e4b958dc2840549888017
7
- data.tar.gz: 389bd66826e1f2878ff49d55cf6f6445b5b122ac99761cc9f5d6bdba29cfb4d4ee23cb77974972ab911a44ecbfc43ee1d913f3e8c01b6d15cd903e55e94529f4
6
+ metadata.gz: 29cebb43ee5215ccf28154c5e8f41985f5079cc6f765fedfae222e17379ecad604977ec5fc92f1f5ba9dd17c7d26f60c96df9a6b8372eced7d5a7814dc4b1c0b
7
+ data.tar.gz: 07e490262d72393456d1915dfb054b16448e454a6f14f1e910a21758547b73c6e03abd2dfa66a7b8966ec6758e91bd0ea3d1d00ee1a077b0202071ed59155acb
@@ -2,7 +2,7 @@ rvm:
2
2
  - 1.9.2
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.0
5
+ - 2.1.2
6
6
  - jruby-19mode
7
7
  - rbx-2
8
8
  gemfile:
@@ -20,7 +20,7 @@ matrix:
20
20
  - rvm: 2.0.0
21
21
  gemfile: gemfiles/Gemfile.mongoid-2.4.x
22
22
  env: SSL_CERT_DIR=/etc/ssl/certs
23
- - rvm: 2.1.0
23
+ - rvm: 2.1.2
24
24
  gemfile: gemfiles/Gemfile.mongoid-2.4.x
25
25
  env: SSL_CERT_DIR=/etc/ssl/certs
26
26
  - rvm: jruby-19mode
@@ -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.2.3 (2014 June 11)
7
+
8
+ * Add Telize IP address lookup (thanks github.com/lukeroberts1990).
9
+ * Fix bug in Bing reverse geocoding (thanks github.com/nickelser).
10
+
6
11
  1.2.2 (2014 Jun 12)
7
12
 
8
13
  * Add ability to specify language per query (thanks github.com/mkristian).
data/README.md CHANGED
@@ -306,7 +306,13 @@ If you're familiar with the results returned by the geocoding service you're usi
306
306
  Geocoding Service ("Lookup") Configuration
307
307
  ------------------------------------------
308
308
 
309
- Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:freegeoip` for IP addresses. Please see the listing and comparison below for details on specific geocoding services (not all settings are supported by all services). Some common configuration options are:
309
+ Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:freegeoip` for IP addresses. Please see the listing and comparison below for details on specific geocoding services (not all settings are supported by all services).
310
+
311
+ To create a Rails initializer with an example configuration:
312
+
313
+ rails generate geocoder:config
314
+
315
+ Some common configuration options are:
310
316
 
311
317
  # config/initializers/geocoder.rb
312
318
  Geocoder.configure(
@@ -576,7 +582,18 @@ Data Science Toolkit provides an API whose reponse format is like Google's but w
576
582
  * **Documentation**: http://github.com/fiorix/freegeoip/blob/master/README.md
577
583
  * **Terms of Service**: ?
578
584
  * **Limitations**: ?
579
- * **Notes**: If you are running your own local instance of the FreeGeoIP service you can configure the host like this: `Geocoder.configure(freegeoip: {host: "..."})`.
585
+ * **Notes**: If you are [running your own local instance of the FreeGeoIP service](https://github.com/fiorix/freegeoip) you can configure the host like this: `Geocoder.configure(freegeoip: {host: "..."})`.
586
+
587
+ #### Telize (`:telize`)
588
+
589
+ * **API key**: none
590
+ * **Quota**: none
591
+ * **Region**: world
592
+ * **SSL support**: no
593
+ * **Languages**: English
594
+ * **Documentation**: http://www.telize.com/
595
+ * **Terms of Service**: ?
596
+ * **Limitations**: ?
580
597
 
581
598
  #### MaxMind Web Services (`:maxmind`)
582
599
 
@@ -614,12 +631,12 @@ This lookup provides methods for geocoding IP addresses without making a call to
614
631
 
615
632
  You can generate ActiveRecord migrations and download and import data via provided rake tasks:
616
633
 
617
- rails generate geocoder:maxmind:geolite_city
634
+ rails generate geocoder:maxmind:geolite PACKAGE=city
618
635
 
619
- rake geocoder:maxmind:geolite_city:download
620
- rake geocoder:maxmind:geolite_city:extract
621
- rake geocoder:maxmind:geolite_city:insert
622
- rake geocoder:maxmind:geolite_city:load # runs the above three in sequence
636
+ rake geocoder:maxmind:geolite:download PACKAGE=city
637
+ rake geocoder:maxmind:geolite:extract PACKAGE=city
638
+ rake geocoder:maxmind:geolite:insert PACKAGE=city
639
+ rake geocoder:maxmind:geolite:load PACKAGE=city # runs the above three in sequence
623
640
 
624
641
  You can replace `city` with `country` in any of the above tasks, generators, and configurations.
625
642
 
@@ -47,10 +47,11 @@ module Geocoder
47
47
  #
48
48
  def ip_services
49
49
  [
50
+ :baidu_ip,
50
51
  :freegeoip,
51
52
  :maxmind,
52
53
  :maxmind_local,
53
- :baidu_ip
54
+ :telize
54
55
  ]
55
56
  end
56
57
 
@@ -24,12 +24,17 @@ module Geocoder::Lookup
24
24
 
25
25
  def base_url(query)
26
26
  url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations"
27
- if !query.reverse_geocode? and r = query.options[:region]
28
- url << "/#{r}"
27
+
28
+ if !query.reverse_geocode?
29
+ if r = query.options[:region]
30
+ url << "/#{r}"
31
+ end
32
+ # use the more forgiving 'unstructured' query format to allow special
33
+ # chars, newlines, brackets, typos.
34
+ url + "?q=" + URI.escape(query.sanitized_text.strip) + "&"
35
+ else
36
+ url + "/#{URI.escape(query.sanitized_text.strip)}?"
29
37
  end
30
- # use the more forgiving 'unstructured' query format to allow special
31
- # chars, newlines, brackets, typos.
32
- url + "?q=" + URI.escape(query.sanitized_text.strip) + "&"
33
38
  end
34
39
 
35
40
  def results(query)
@@ -0,0 +1,36 @@
1
+ require 'geocoder/lookups/base'
2
+ require 'geocoder/results/telize'
3
+
4
+ module Geocoder::Lookup
5
+ class Telize < Base
6
+
7
+ def name
8
+ "Telize"
9
+ end
10
+
11
+ def query_url(query)
12
+ #currently doesn't support HTTPS
13
+ "http://www.telize.com/geoip/#{query.sanitized_text}"
14
+ end
15
+
16
+ private # ---------------------------------------------------------------
17
+
18
+ def results(query)
19
+ # don't look up a loopback address, just return the stored result
20
+ return [reserved_result(query.text)] if query.loopback_ip_address?
21
+ if (doc = fetch_data(query)).nil? or doc['code'] == 401 or empty_result?(doc)
22
+ []
23
+ else
24
+ [doc]
25
+ end
26
+ end
27
+
28
+ def empty_result?(doc)
29
+ !doc.is_a?(Hash) or doc.keys == ["ip"]
30
+ end
31
+
32
+ def reserved_result(ip)
33
+ {"message" => "Input string is not a valid IP address", "code" => 401}
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,45 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Telize < Base
5
+
6
+ def address(format = :full)
7
+ s = state_code.to_s == "" ? "" : ", #{state_code}"
8
+ "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
9
+ end
10
+
11
+ def city
12
+ @data['city']
13
+ end
14
+
15
+ def state
16
+ @data['region']
17
+ end
18
+
19
+ def state_code
20
+ @data['region_code']
21
+ end
22
+
23
+ def country
24
+ @data['country']
25
+ end
26
+
27
+ def country_code
28
+ @data['country_code']
29
+ end
30
+
31
+ def postal_code
32
+ @data['postal_code']
33
+ end
34
+
35
+ def self.response_attributes
36
+ %w[timezone isp dma_code area_code ip asn continent_code country_code3]
37
+ end
38
+
39
+ response_attributes.each do |a|
40
+ define_method a do
41
+ @data[a]
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
@@ -0,0 +1 @@
1
+ {"ip":"10.10.10.10"}
@@ -0,0 +1,4 @@
1
+ {
2
+ "message": "Input string is not a valid IP address",
3
+ "code": 401
4
+ }
@@ -0,0 +1 @@
1
+ {"timezone":"America\/Chicago","isp":"Layered Technologies, Inc.","region_code":"TX","country":"United States","dma_code":"0","area_code":"0","region":"Texas","ip":"74.200.247.59","asn":"AS22576","continent_code":"NA","city":"Plano","postal_code":"75093","longitude":-96.8134,"latitude":33.0347,"country_code":"US","country_code3":"USA"}
@@ -0,0 +1 @@
1
+ {"ip":"10.10.10.10"}
@@ -143,6 +143,13 @@ module Geocoder
143
143
  end
144
144
  end
145
145
 
146
+ class Telize
147
+ private
148
+ def default_fixture_filename
149
+ "telize_74_200_247_59"
150
+ end
151
+ end
152
+
146
153
  class Maxmind
147
154
  private
148
155
  def default_fixture_filename
@@ -23,7 +23,7 @@ class LookupTest < GeocoderTestCase
23
23
 
24
24
  def test_query_url_contains_values_in_params_hash
25
25
  Geocoder::Lookup.all_services_except_test.each do |l|
26
- next if l == :freegeoip || l == :maxmind_local # does not use query string
26
+ next if [:freegeoip, :maxmind_local, :telize].include? l # does not use query string
27
27
  set_api_key!(l)
28
28
  url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new(
29
29
  "test", :params => {:one_in_the_hand => "two in the bush"}
@@ -12,7 +12,7 @@ class BingTest < GeocoderTestCase
12
12
  def test_query_for_reverse_geocode
13
13
  lookup = Geocoder::Lookup::Bing.new
14
14
  url = lookup.query_url(Geocoder::Query.new([45.423733, -75.676333]))
15
- assert_match(/Locations\?q=45.423733/, url)
15
+ assert_match(/Locations\/45.423733/, url)
16
16
  end
17
17
 
18
18
  def test_result_components
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ $: << File.join(File.dirname(__FILE__), "..", "..")
3
+ require 'test_helper'
4
+
5
+ class TelizeTest < GeocoderTestCase
6
+
7
+ def setup
8
+ Geocoder.configure(ip_lookup: :telize)
9
+ end
10
+
11
+ def test_result_on_ip_address_search
12
+ result = Geocoder.search("74.200.247.59").first
13
+ assert result.is_a?(Geocoder::Result::Telize)
14
+ end
15
+
16
+ def test_result_components
17
+ result = Geocoder.search("74.200.247.59").first
18
+ assert_equal "Plano, TX 75093, United States", result.address
19
+ end
20
+
21
+ def test_no_results
22
+ results = Geocoder.search("10.10.10.10")
23
+ assert_equal 0, results.length
24
+ end
25
+
26
+ def test_invalid_address
27
+ results = Geocoder.search("555.555.555.555")
28
+ assert_equal 0, results.length
29
+ end
30
+ 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.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-12 00:00:00.000000000 Z
11
+ date: 2014-07-11 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,
@@ -67,6 +67,7 @@ files:
67
67
  - lib/geocoder/lookups/nominatim.rb
68
68
  - lib/geocoder/lookups/ovi.rb
69
69
  - lib/geocoder/lookups/smarty_streets.rb
70
+ - lib/geocoder/lookups/telize.rb
70
71
  - lib/geocoder/lookups/test.rb
71
72
  - lib/geocoder/lookups/yahoo.rb
72
73
  - lib/geocoder/lookups/yandex.rb
@@ -98,6 +99,7 @@ files:
98
99
  - lib/geocoder/results/nominatim.rb
99
100
  - lib/geocoder/results/ovi.rb
100
101
  - lib/geocoder/results/smarty_streets.rb
102
+ - lib/geocoder/results/telize.rb
101
103
  - lib/geocoder/results/test.rb
102
104
  - lib/geocoder/results/yahoo.rb
103
105
  - lib/geocoder/results/yandex.rb
@@ -170,6 +172,10 @@ files:
170
172
  - test/fixtures/smarty_streets_11211
171
173
  - test/fixtures/smarty_streets_madison_square_garden
172
174
  - test/fixtures/smarty_streets_no_results
175
+ - test/fixtures/telize_10_10_10_10
176
+ - test/fixtures/telize_555_555_555_555
177
+ - test/fixtures/telize_74_200_247_59
178
+ - test/fixtures/telize_no_results
173
179
  - test/fixtures/yahoo_error
174
180
  - test/fixtures/yahoo_invalid_key
175
181
  - test/fixtures/yahoo_madison_square_garden
@@ -206,6 +212,7 @@ files:
206
212
  - test/unit/lookups/maxmind_test.rb
207
213
  - test/unit/lookups/nominatim_test.rb
208
214
  - test/unit/lookups/smarty_streets_test.rb
215
+ - test/unit/lookups/telize_test.rb
209
216
  - test/unit/lookups/yahoo_test.rb
210
217
  - test/unit/method_aliases_test.rb
211
218
  - test/unit/model_test.rb