geocoder 1.4.7 → 1.5.0

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.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/README.md +352 -935
  4. data/examples/autoexpire_cache_redis.rb +3 -3
  5. data/lib/generators/geocoder/config/templates/initializer.rb +2 -2
  6. data/lib/geocoder/cache.rb +1 -1
  7. data/lib/geocoder/cli.rb +2 -2
  8. data/lib/geocoder/configuration.rb +2 -2
  9. data/lib/geocoder/exceptions.rb +1 -1
  10. data/lib/geocoder/ip_address.rb +1 -1
  11. data/lib/geocoder/lookup.rb +4 -3
  12. data/lib/geocoder/lookups/amap.rb +7 -3
  13. data/lib/geocoder/lookups/baidu.rb +14 -10
  14. data/lib/geocoder/lookups/baidu_ip.rb +6 -35
  15. data/lib/geocoder/lookups/ban_data_gouv_fr.rb +4 -4
  16. data/lib/geocoder/lookups/base.rb +21 -3
  17. data/lib/geocoder/lookups/bing.rb +8 -12
  18. data/lib/geocoder/lookups/db_ip_com.rb +9 -6
  19. data/lib/geocoder/lookups/dstk.rb +4 -2
  20. data/lib/geocoder/lookups/esri.rb +1 -16
  21. data/lib/geocoder/lookups/freegeoip.rb +4 -0
  22. data/lib/geocoder/lookups/geocoder_ca.rb +4 -4
  23. data/lib/geocoder/lookups/geocoder_us.rb +17 -9
  24. data/lib/geocoder/lookups/geocodio.rb +5 -5
  25. data/lib/geocoder/lookups/geoportail_lu.rb +7 -7
  26. data/lib/geocoder/lookups/google.rb +8 -8
  27. data/lib/geocoder/lookups/google_places_details.rb +4 -4
  28. data/lib/geocoder/lookups/google_places_search.rb +4 -4
  29. data/lib/geocoder/lookups/google_premier.rb +10 -0
  30. data/lib/geocoder/lookups/here.rb +4 -4
  31. data/lib/geocoder/lookups/ip2location.rb +74 -0
  32. data/lib/geocoder/lookups/ipapi_com.rb +7 -12
  33. data/lib/geocoder/lookups/ipdata_co.rb +4 -0
  34. data/lib/geocoder/lookups/ipinfo_io.rb +10 -19
  35. data/lib/geocoder/lookups/ipstack.rb +63 -0
  36. data/lib/geocoder/lookups/latlon.rb +4 -4
  37. data/lib/geocoder/lookups/location_iq.rb +10 -4
  38. data/lib/geocoder/lookups/mapbox.rb +7 -6
  39. data/lib/geocoder/lookups/mapquest.rb +4 -5
  40. data/lib/geocoder/lookups/maxmind.rb +4 -4
  41. data/lib/geocoder/lookups/maxmind_geoip2.rb +4 -0
  42. data/lib/geocoder/lookups/nominatim.rb +4 -4
  43. data/lib/geocoder/lookups/opencagedata.rb +6 -5
  44. data/lib/geocoder/lookups/pelias.rb +6 -6
  45. data/lib/geocoder/lookups/pickpoint.rb +9 -3
  46. data/lib/geocoder/lookups/pointpin.rb +7 -6
  47. data/lib/geocoder/lookups/postcode_anywhere_uk.rb +4 -5
  48. data/lib/geocoder/lookups/postcodes_io.rb +31 -0
  49. data/lib/geocoder/lookups/smarty_streets.rb +8 -8
  50. data/lib/geocoder/lookups/telize.rb +24 -4
  51. data/lib/geocoder/lookups/yandex.rb +4 -4
  52. data/lib/geocoder/results/baidu.rb +10 -10
  53. data/lib/geocoder/results/base.rb +13 -1
  54. data/lib/geocoder/results/bing.rb +1 -1
  55. data/lib/geocoder/results/db_ip_com.rb +0 -5
  56. data/lib/geocoder/results/freegeoip.rb +0 -5
  57. data/lib/geocoder/results/geocoder_ca.rb +3 -3
  58. data/lib/geocoder/results/geoip2.rb +2 -6
  59. data/lib/geocoder/results/geoportail_lu.rb +5 -3
  60. data/lib/geocoder/results/ip2location.rb +22 -0
  61. data/lib/geocoder/results/ipdata_co.rb +0 -5
  62. data/lib/geocoder/results/ipstack.rb +60 -0
  63. data/lib/geocoder/results/maxmind.rb +0 -5
  64. data/lib/geocoder/results/maxmind_local.rb +0 -5
  65. data/lib/geocoder/results/postcodes_io.rb +40 -0
  66. data/lib/geocoder/results/telize.rb +0 -5
  67. data/lib/geocoder/results/test.rb +1 -1
  68. data/lib/geocoder/stores/active_record.rb +0 -2
  69. data/lib/geocoder/stores/base.rb +1 -1
  70. data/lib/geocoder/version.rb +1 -1
  71. metadata +14 -8
  72. data/lib/geocoder/lookups/okf.rb +0 -44
  73. data/lib/geocoder/lookups/ovi.rb +0 -62
  74. data/lib/geocoder/results/okf.rb +0 -106
  75. data/lib/geocoder/results/ovi.rb +0 -71
@@ -0,0 +1,74 @@
1
+ require 'geocoder/lookups/base'
2
+ require 'geocoder/results/ip2location'
3
+
4
+ module Geocoder::Lookup
5
+ class Ip2location < Base
6
+
7
+ def name
8
+ "IP2LocationApi"
9
+ end
10
+
11
+ def supported_protocols
12
+ [:http, :https]
13
+ end
14
+
15
+ private # ----------------------------------------------------------------
16
+
17
+ def base_query_url(query)
18
+ "#{protocol}://api.ip2location.com/?"
19
+ end
20
+
21
+ def query_url_params(query)
22
+ {
23
+ key: configuration.api_key ? configuration.api_key : "demo",
24
+ format: "json",
25
+ ip: query.sanitized_text
26
+ }.merge(super)
27
+ end
28
+
29
+ def results(query)
30
+ return [reserved_result(query.text)] if query.loopback_ip_address?
31
+ return [] unless doc = fetch_data(query)
32
+ if doc["response"] == "INVALID ACCOUNT"
33
+ raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "INVALID ACCOUNT")
34
+ return []
35
+ else
36
+ return [doc]
37
+ end
38
+ end
39
+
40
+ def reserved_result(query)
41
+ {
42
+ "country_code" => "INVALID IP ADDRESS",
43
+ "country_name" => "INVALID IP ADDRESS",
44
+ "region_name" => "INVALID IP ADDRESS",
45
+ "city_name" => "INVALID IP ADDRESS",
46
+ "latitude" => "INVALID IP ADDRESS",
47
+ "longitude" => "INVALID IP ADDRESS",
48
+ "zip_code" => "INVALID IP ADDRESS",
49
+ "time_zone" => "INVALID IP ADDRESS",
50
+ "isp" => "INVALID IP ADDRESS",
51
+ "domain" => "INVALID IP ADDRESS",
52
+ "net_speed" => "INVALID IP ADDRESS",
53
+ "idd_code" => "INVALID IP ADDRESS",
54
+ "area_code" => "INVALID IP ADDRESS",
55
+ "weather_station_code" => "INVALID IP ADDRESS",
56
+ "weather_station_name" => "INVALID IP ADDRESS",
57
+ "mcc" => "INVALID IP ADDRESS",
58
+ "mnc" => "INVALID IP ADDRESS",
59
+ "mobile_brand" => "INVALID IP ADDRESS",
60
+ "elevation" => "INVALID IP ADDRESS",
61
+ "usage_type" => "INVALID IP ADDRESS"
62
+ }
63
+ end
64
+
65
+ def query_url_params(query)
66
+ params = super
67
+ if configuration.has_key?(:package)
68
+ params.merge!(package: configuration[:package])
69
+ end
70
+ params
71
+ end
72
+
73
+ end
74
+ end
@@ -8,17 +8,6 @@ module Geocoder::Lookup
8
8
  "ip-api.com"
9
9
  end
10
10
 
11
- def query_url(query)
12
- domain = configuration.api_key ? "pro.ip-api.com" : "ip-api.com"
13
- url_ = "#{protocol}://#{domain}/json/#{query.sanitized_text}"
14
-
15
- if (params = url_query_string(query)) && !params.empty?
16
- url_ + "?" + params
17
- else
18
- url_
19
- end
20
- end
21
-
22
11
  def supported_protocols
23
12
  if configuration.api_key
24
13
  [:http, :https]
@@ -27,8 +16,14 @@ module Geocoder::Lookup
27
16
  end
28
17
  end
29
18
 
19
+ private # ----------------------------------------------------------------
30
20
 
31
- private
21
+ def base_query_url(query)
22
+ domain = configuration.api_key ? "pro.ip-api.com" : "ip-api.com"
23
+ url = "#{protocol}://#{domain}/json/#{query.sanitized_text}"
24
+ url << "?" if not url_query_string(query).empty?
25
+ url
26
+ end
32
27
 
33
28
  def parse_raw_data(raw_data)
34
29
  if raw_data.chomp == "invalid key"
@@ -18,6 +18,10 @@ module Geocoder::Lookup
18
18
 
19
19
  private # ---------------------------------------------------------------
20
20
 
21
+ def cache_key(query)
22
+ query_url(query)
23
+ end
24
+
21
25
  def results(query)
22
26
  Geocoder.configure(:ipdata_co => {:http_headers => { "api-key" => configuration.api_key }}) if configuration.api_key
23
27
  # don't look up a loopback address, just return the stored result
@@ -8,14 +8,6 @@ module Geocoder::Lookup
8
8
  "Ipinfo.io"
9
9
  end
10
10
 
11
- def query_url(query)
12
- if configuration.api_key
13
- "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo?" + url_query_string(query)
14
- else
15
- "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo"
16
- end
17
- end
18
-
19
11
  # HTTPS available only for paid plans
20
12
  def supported_protocols
21
13
  if configuration.api_key
@@ -27,28 +19,27 @@ module Geocoder::Lookup
27
19
 
28
20
  private # ---------------------------------------------------------------
29
21
 
22
+ def base_query_url(query)
23
+ url = "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo"
24
+ url << "?" if configuration.api_key
25
+ url
26
+ end
27
+
30
28
  def results(query)
31
29
  # don't look up a loopback address, just return the stored result
32
30
  return [reserved_result(query.text)] if query.loopback_ip_address?
33
- if (doc = fetch_data(query)).nil? or doc['code'] == 401 or empty_result?(doc)
31
+
32
+ if !(doc = fetch_data(query)).is_a?(Hash) or doc['error']
34
33
  []
35
34
  else
36
35
  [doc]
37
36
  end
38
37
  end
39
38
 
40
- def empty_result?(doc)
41
- !doc.is_a?(Hash) or doc.keys == ["ip"]
42
- end
43
-
44
39
  def reserved_result(ip)
45
40
  {
46
- "ip" => ip,
47
- "city" => "",
48
- "region" => "",
49
- "country" => "",
50
- "loc" => "0,0",
51
- "postal" => ""
41
+ "ip" => ip,
42
+ "bogon" => true
52
43
  }
53
44
  end
54
45
 
@@ -0,0 +1,63 @@
1
+ require 'geocoder/lookups/base'
2
+ require 'geocoder/results/ipstack'
3
+
4
+ module Geocoder::Lookup
5
+ class Ipstack < Base
6
+
7
+ ERROR_CODES = {
8
+ 404 => Geocoder::InvalidRequest,
9
+ 101 => Geocoder::InvalidApiKey,
10
+ 102 => Geocoder::Error,
11
+ 103 => Geocoder::InvalidRequest,
12
+ 104 => Geocoder::OverQueryLimitError,
13
+ 105 => Geocoder::RequestDenied,
14
+ 301 => Geocoder::InvalidRequest,
15
+ 302 => Geocoder::InvalidRequest,
16
+ 303 => Geocoder::RequestDenied,
17
+ }
18
+ ERROR_CODES.default = Geocoder::Error
19
+
20
+ def name
21
+ "Ipstack"
22
+ end
23
+
24
+ private # ----------------------------------------------------------------
25
+
26
+ def base_query_url(query)
27
+ "#{protocol}://#{host}/#{query.sanitized_text}?"
28
+ end
29
+
30
+ def query_url_params(query)
31
+ {
32
+ access_key: configuration.api_key
33
+ }.merge(super)
34
+ end
35
+
36
+ def results(query)
37
+ # don't look up a loopback address, just return the stored result
38
+ return [reserved_result(query.text)] if query.loopback_ip_address?
39
+
40
+ return [] unless doc = fetch_data(query)
41
+
42
+ if error = doc['error']
43
+ code = error['code']
44
+ msg = error['info']
45
+ raise_error(ERROR_CODES[code], msg ) || Geocoder.log(:warn, "Ipstack Geocoding API error: #{msg}")
46
+ return []
47
+ end
48
+ [doc]
49
+ end
50
+
51
+ def reserved_result(ip)
52
+ {
53
+ "ip" => ip,
54
+ "country_name" => "Reserved",
55
+ "country_code" => "RD"
56
+ }
57
+ end
58
+
59
+ def host
60
+ configuration[:host] || "api.ipstack.com"
61
+ end
62
+ end
63
+ end
@@ -12,12 +12,12 @@ module Geocoder::Lookup
12
12
  ["api_key"]
13
13
  end
14
14
 
15
- def query_url(query)
16
- "#{protocol}://latlon.io/api/v1/#{'reverse_' if query.reverse_geocode?}geocode?#{url_query_string(query)}"
17
- end
18
-
19
15
  private # ---------------------------------------------------------------
20
16
 
17
+ def base_query_url(query)
18
+ "#{protocol}://latlon.io/api/v1/#{'reverse_' if query.reverse_geocode?}geocode?"
19
+ end
20
+
21
21
  def results(query)
22
22
  return [] unless doc = fetch_data(query)
23
23
  if doc['error'].nil?
@@ -10,13 +10,19 @@ module Geocoder::Lookup
10
10
  def required_api_key_parts
11
11
  ["api_key"]
12
12
  end
13
-
14
- def query_url(query)
13
+
14
+ private # ----------------------------------------------------------------
15
+
16
+ def base_query_url(query)
15
17
  method = query.reverse_geocode? ? "reverse" : "search"
16
- "#{protocol}://#{configured_host}/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query)
18
+ "#{protocol}://#{configured_host}/v1/#{method}.php?"
17
19
  end
18
20
 
19
- private
21
+ def query_url_params(query)
22
+ {
23
+ key: configuration.api_key
24
+ }.merge(super)
25
+ end
20
26
 
21
27
  def configured_host
22
28
  configuration[:host] || "locationiq.org"
@@ -8,13 +8,12 @@ module Geocoder::Lookup
8
8
  "Mapbox"
9
9
  end
10
10
 
11
- def query_url(query)
12
- path = "#{mapbox_search_term(query)}.json?#{url_query_string(query)}"
13
- "#{protocol}://api.mapbox.com/geocoding/v5/#{dataset}/#{path}"
14
- end
15
-
16
11
  private # ---------------------------------------------------------------
17
12
 
13
+ def base_query_url(query)
14
+ "#{protocol}://api.mapbox.com/geocoding/v5/#{dataset}/#{mapbox_search_term(query)}.json?"
15
+ end
16
+
18
17
  def results(query)
19
18
  return [] unless data = fetch_data(query)
20
19
  if data['features']
@@ -36,7 +35,9 @@ module Geocoder::Lookup
36
35
  lat,lon = query.coordinates
37
36
  "#{CGI.escape lon},#{CGI.escape lat}"
38
37
  else
39
- CGI.escape query.text.to_s
38
+ # truncate at first semicolon so Mapbox doesn't go into batch mode
39
+ # (see Github issue #1299)
40
+ CGI.escape query.text.to_s.split(';').first.to_s
40
41
  end
41
42
  end
42
43
 
@@ -13,14 +13,13 @@ module Geocoder::Lookup
13
13
  ["key"]
14
14
  end
15
15
 
16
- def query_url(query)
16
+ private # ---------------------------------------------------------------
17
+
18
+ def base_query_url(query)
17
19
  domain = configuration[:open] ? "open" : "www"
18
- url = "#{protocol}://#{domain}.mapquestapi.com/geocoding/v1/#{search_type(query)}?"
19
- url + url_query_string(query)
20
+ "#{protocol}://#{domain}.mapquestapi.com/geocoding/v1/#{search_type(query)}?"
20
21
  end
21
22
 
22
- private # ---------------------------------------------------------------
23
-
24
23
  def search_type(query)
25
24
  query.reverse_geocode? ? "reverse" : "address"
26
25
  end
@@ -9,12 +9,12 @@ module Geocoder::Lookup
9
9
  "MaxMind"
10
10
  end
11
11
 
12
- def query_url(query)
13
- "#{protocol}://geoip.maxmind.com/#{service_code}?" + url_query_string(query)
14
- end
15
-
16
12
  private # ---------------------------------------------------------------
17
13
 
14
+ def base_query_url(query)
15
+ "#{protocol}://geoip.maxmind.com/#{service_code}?"
16
+ end
17
+
18
18
  ##
19
19
  # Return the name of the configured service, or raise an exception.
20
20
  #
@@ -20,6 +20,10 @@ module Geocoder::Lookup
20
20
 
21
21
  private # ---------------------------------------------------------------
22
22
 
23
+ def cache_key(query)
24
+ query_url(query)
25
+ end
26
+
23
27
  ##
24
28
  # Return the name of the configured service, or raise an exception.
25
29
  #
@@ -12,13 +12,13 @@ module Geocoder::Lookup
12
12
  "https://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M"
13
13
  end
14
14
 
15
- def query_url(query)
15
+ private # ---------------------------------------------------------------
16
+
17
+ def base_query_url(query)
16
18
  method = query.reverse_geocode? ? "reverse" : "search"
17
- "#{protocol}://#{configured_host}/#{method}?" + url_query_string(query)
19
+ "#{protocol}://#{configured_host}/#{method}?"
18
20
  end
19
21
 
20
- private # ---------------------------------------------------------------
21
-
22
22
  def configured_host
23
23
  configuration[:host] || "nominatim.openstreetmap.org"
24
24
  end
@@ -8,15 +8,15 @@ module Geocoder::Lookup
8
8
  "OpenCageData"
9
9
  end
10
10
 
11
- def query_url(query)
12
- "#{protocol}://api.opencagedata.com/geocode/v1/json?key=#{configuration.api_key}&#{url_query_string(query)}"
13
- end
14
-
15
11
  def required_api_key_parts
16
12
  ["key"]
17
13
  end
18
14
 
19
- private
15
+ private # ----------------------------------------------------------------
16
+
17
+ def base_query_url(query)
18
+ "#{protocol}://api.opencagedata.com/geocode/v1/json?"
19
+ end
20
20
 
21
21
  def results(query)
22
22
  return [] unless doc = fetch_data(query)
@@ -44,6 +44,7 @@ module Geocoder::Lookup
44
44
  def query_url_params(query)
45
45
  params = {
46
46
  :q => query.sanitized_text,
47
+ :key => configuration.api_key,
47
48
  :language => (query.language || configuration.language)
48
49
  }.merge(super)
49
50
 
@@ -11,16 +11,16 @@ module Geocoder::Lookup
11
11
  configuration[:endpoint] || 'localhost'
12
12
  end
13
13
 
14
- def query_url(query)
15
- query_type = query.reverse_geocode? ? 'reverse' : 'search'
16
- "#{protocol}://#{endpoint}/v1/#{query_type}?" + url_query_string(query)
17
- end
18
-
19
14
  def required_api_key_parts
20
15
  ['search-XXXX']
21
16
  end
22
17
 
23
- private
18
+ private # ----------------------------------------------------------------
19
+
20
+ def base_query_url(query)
21
+ query_type = query.reverse_geocode? ? 'reverse' : 'search'
22
+ "#{protocol}://#{endpoint}/v1/#{query_type}?"
23
+ end
24
24
 
25
25
  def query_url_params(query)
26
26
  params = {
@@ -15,12 +15,18 @@ module Geocoder::Lookup
15
15
  ["api_key"]
16
16
  end
17
17
 
18
- def query_url(query)
18
+ private # ----------------------------------------------------------------
19
+
20
+ def base_query_url(query)
19
21
  method = query.reverse_geocode? ? "reverse" : "forward"
20
- "#{protocol}://api.pickpoint.io/v1/#{method}?key=#{configuration.api_key}&" + url_query_string(query)
22
+ "#{protocol}://api.pickpoint.io/v1/#{method}?"
21
23
  end
22
24
 
23
- private
25
+ def query_url_params(query)
26
+ params = {
27
+ key: configuration.api_key
28
+ }.merge(super)
29
+ end
24
30
 
25
31
  def results(query)
26
32
  return [] unless doc = fetch_data(query)
@@ -13,10 +13,14 @@ module Geocoder::Lookup
13
13
  end
14
14
 
15
15
  def query_url(query)
16
- "#{ protocol }://geo.pointp.in/#{ api_key }/json/#{ query.sanitized_text }"
16
+ "#{protocol}://geo.pointp.in/#{configuration.api_key}/json/#{query.sanitized_text}"
17
17
  end
18
18
 
19
- private
19
+ private # ----------------------------------------------------------------
20
+
21
+ def cache_key(query)
22
+ "#{protocol}://geo.pointp.in/json/#{query.sanitized_text}"
23
+ end
20
24
 
21
25
  def results(query)
22
26
  # don't look up a loopback address, just return the stored result
@@ -46,6 +50,7 @@ module Geocoder::Lookup
46
50
  parsed_data.keys.include?('error')
47
51
  end
48
52
 
53
+ # TODO: replace this hash with what's actually returned by Pointpin
49
54
  def reserved_result(ip)
50
55
  {
51
56
  "ip" => ip,
@@ -60,9 +65,5 @@ module Geocoder::Lookup
60
65
  "country_code" => "RD"
61
66
  }
62
67
  end
63
-
64
- def api_key
65
- configuration.api_key
66
- end
67
68
  end
68
69
  end
@@ -4,7 +4,6 @@ require 'geocoder/results/postcode_anywhere_uk'
4
4
  module Geocoder::Lookup
5
5
  class PostcodeAnywhereUk < Base
6
6
  # API documentation: http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/
7
- BASE_URL_GEOCODE_V2_00 = 'services.postcodeanywhere.co.uk/Geocoding/UK/Geocode/v2.00/json.ws'
8
7
  DAILY_LIMIT_EXEEDED_ERROR_CODES = ['8', '17'] # api docs say these two codes are the same error
9
8
  INVALID_API_KEY_ERROR_CODE = '2'
10
9
 
@@ -16,11 +15,11 @@ module Geocoder::Lookup
16
15
  %w(key)
17
16
  end
18
17
 
19
- def query_url(query)
20
- format('%s://%s?%s', protocol, BASE_URL_GEOCODE_V2_00, url_query_string(query))
21
- end
18
+ private # ----------------------------------------------------------------
22
19
 
23
- private
20
+ def base_query_url(query)
21
+ "#{protocol}://services.postcodeanywhere.co.uk/Geocoding/UK/Geocode/v2.00/json.ws?"
22
+ end
24
23
 
25
24
  def results(query)
26
25
  response = fetch_data(query)
@@ -0,0 +1,31 @@
1
+ require 'geocoder/lookups/base'
2
+ require 'geocoder/results/postcodes_io'
3
+
4
+ module Geocoder::Lookup
5
+ class PostcodesIo < Base
6
+ def name
7
+ 'Postcodes.io'
8
+ end
9
+
10
+ def query_url(query)
11
+ "#{protocol}://api.postcodes.io/postcodes/#{query.sanitized_text.gsub(/\s/, '')}"
12
+ end
13
+
14
+ def supported_protocols
15
+ [:https]
16
+ end
17
+
18
+ private # ----------------------------------------------------------------
19
+
20
+ def cache_key(query)
21
+ query_url(query)
22
+ end
23
+
24
+ def results(query)
25
+ response = fetch_data(query)
26
+ return [] if response.nil? || response['status'] != 200 || response.empty?
27
+
28
+ [response['result']]
29
+ end
30
+ end
31
+ end
@@ -11,14 +11,6 @@ module Geocoder::Lookup
11
11
  %w(auti-id auth-token)
12
12
  end
13
13
 
14
- def query_url(query)
15
- if zipcode_only?(query)
16
- "#{protocol}://us-zipcode.api.smartystreets.com/lookup?#{url_query_string(query)}"
17
- else
18
- "#{protocol}://us-street.api.smartystreets.com/street-address?#{url_query_string(query)}"
19
- end
20
- end
21
-
22
14
  # required by API as of 26 March 2015
23
15
  def supported_protocols
24
16
  [:https]
@@ -26,6 +18,14 @@ module Geocoder::Lookup
26
18
 
27
19
  private # ---------------------------------------------------------------
28
20
 
21
+ def base_query_url(query)
22
+ if zipcode_only?(query)
23
+ "#{protocol}://us-zipcode.api.smartystreets.com/lookup?"
24
+ else
25
+ "#{protocol}://us-street.api.smartystreets.com/street-address?"
26
+ end
27
+ end
28
+
29
29
  def zipcode_only?(query)
30
30
  !query.text.is_a?(Array) and query.to_s.strip =~ /\A\d{5}(-\d{4})?\Z/
31
31
  end
@@ -14,9 +14,9 @@ module Geocoder::Lookup
14
14
 
15
15
  def query_url(query)
16
16
  if configuration[:host]
17
- "#{protocol}://#{configuration[:host]}/geoip/#{query.sanitized_text}"
17
+ "#{protocol}://#{configuration[:host]}/location/#{query.sanitized_text}"
18
18
  else
19
- "#{protocol}://telize-v1.p.mashape.com/geoip/#{query.sanitized_text}?mashape-key=#{api_key}"
19
+ "#{protocol}://telize-v1.p.mashape.com/location/#{query.sanitized_text}?mashape-key=#{api_key}"
20
20
  end
21
21
  end
22
22
 
@@ -29,6 +29,10 @@ module Geocoder::Lookup
29
29
 
30
30
  private # ---------------------------------------------------------------
31
31
 
32
+ def cache_key(query)
33
+ query_url(query)[/(.*)\?.*/, 1]
34
+ end
35
+
32
36
  def results(query)
33
37
  # don't look up a loopback address, just return the stored result
34
38
  return [reserved_result(query.text)] if query.loopback_ip_address?
@@ -44,12 +48,28 @@ module Geocoder::Lookup
44
48
  end
45
49
 
46
50
  def reserved_result(ip)
47
- {"message" => "Input string is not a valid IP address", "code" => 401}
51
+ {
52
+ "ip" => ip,
53
+ "latitude" => 0,
54
+ "longitude" => 0,
55
+ "city" => "",
56
+ "timezone" => "",
57
+ "asn" => 0,
58
+ "region" => "",
59
+ "offset" => 0,
60
+ "organization" => "",
61
+ "country_code" => "",
62
+ "country_code3" => "",
63
+ "postal_code" => "",
64
+ "continent_code" => "",
65
+ "country" => "",
66
+ "region_code" => ""
67
+ }
48
68
  end
49
69
 
50
70
  def api_key
51
71
  configuration.api_key
52
72
  end
53
-
73
+
54
74
  end
55
75
  end
@@ -12,16 +12,16 @@ module Geocoder::Lookup
12
12
  "http://maps.yandex.ru/?ll=#{coordinates.reverse.join(',')}"
13
13
  end
14
14
 
15
- def query_url(query)
16
- "#{protocol}://geocode-maps.yandex.ru/1.x/?" + url_query_string(query)
17
- end
18
-
19
15
  def supported_protocols
20
16
  [:https]
21
17
  end
22
18
 
23
19
  private # ---------------------------------------------------------------
24
20
 
21
+ def base_query_url(query)
22
+ "#{protocol}://geocode-maps.yandex.ru/1.x/?"
23
+ end
24
+
25
25
  def results(query)
26
26
  return [] unless doc = fetch_data(query)
27
27
  if err = doc['error']