geocoder 1.4.7 → 1.5.2
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 +5 -5
- data/CHANGELOG.md +31 -0
- data/README.md +352 -935
- data/examples/autoexpire_cache_redis.rb +3 -3
- data/lib/generators/geocoder/config/templates/initializer.rb +2 -2
- data/lib/geocoder/cache.rb +1 -1
- data/lib/geocoder/calculations.rb +1 -1
- data/lib/geocoder/cli.rb +2 -2
- data/lib/geocoder/configuration.rb +2 -2
- data/lib/geocoder/exceptions.rb +1 -1
- data/lib/geocoder/ip_address.rb +14 -1
- data/lib/geocoder/lookup.rb +6 -4
- data/lib/geocoder/lookups/amap.rb +7 -3
- data/lib/geocoder/lookups/baidu.rb +14 -10
- data/lib/geocoder/lookups/baidu_ip.rb +7 -36
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +4 -4
- data/lib/geocoder/lookups/base.rb +27 -4
- data/lib/geocoder/lookups/bing.rb +10 -13
- data/lib/geocoder/lookups/db_ip_com.rb +9 -6
- data/lib/geocoder/lookups/dstk.rb +4 -2
- data/lib/geocoder/lookups/esri.rb +39 -29
- data/lib/geocoder/lookups/freegeoip.rb +11 -7
- data/lib/geocoder/lookups/geocoder_ca.rb +4 -4
- data/lib/geocoder/lookups/geocoder_us.rb +17 -9
- data/lib/geocoder/lookups/geocodio.rb +5 -5
- data/lib/geocoder/lookups/geoportail_lu.rb +7 -7
- data/lib/geocoder/lookups/google.rb +8 -8
- data/lib/geocoder/lookups/google_places_details.rb +4 -4
- data/lib/geocoder/lookups/google_places_search.rb +4 -4
- data/lib/geocoder/lookups/google_premier.rb +10 -0
- data/lib/geocoder/lookups/here.rb +30 -15
- data/lib/geocoder/lookups/ip2location.rb +75 -0
- data/lib/geocoder/lookups/ipapi_com.rb +9 -13
- data/lib/geocoder/lookups/ipdata_co.rb +9 -4
- data/lib/geocoder/lookups/ipinfo_io.rb +11 -29
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/ipstack.rb +63 -0
- data/lib/geocoder/lookups/latlon.rb +4 -4
- data/lib/geocoder/lookups/location_iq.rb +10 -4
- data/lib/geocoder/lookups/mapbox.rb +7 -6
- data/lib/geocoder/lookups/mapquest.rb +4 -5
- data/lib/geocoder/lookups/maxmind.rb +6 -6
- data/lib/geocoder/lookups/maxmind_geoip2.rb +8 -7
- data/lib/geocoder/lookups/nominatim.rb +4 -4
- data/lib/geocoder/lookups/opencagedata.rb +6 -5
- data/lib/geocoder/lookups/pelias.rb +8 -9
- data/lib/geocoder/lookups/pickpoint.rb +9 -3
- data/lib/geocoder/lookups/pointpin.rb +10 -9
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +4 -5
- data/lib/geocoder/lookups/postcodes_io.rb +31 -0
- data/lib/geocoder/lookups/smarty_streets.rb +20 -10
- data/lib/geocoder/lookups/telize.rb +26 -6
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +6 -6
- data/lib/geocoder/query.rb +14 -0
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/results/baidu.rb +10 -10
- data/lib/geocoder/results/base.rb +13 -1
- data/lib/geocoder/results/bing.rb +1 -1
- data/lib/geocoder/results/db_ip_com.rb +0 -5
- data/lib/geocoder/results/freegeoip.rb +0 -5
- data/lib/geocoder/results/geocoder_ca.rb +3 -3
- data/lib/geocoder/results/geoip2.rb +2 -6
- data/lib/geocoder/results/geoportail_lu.rb +5 -3
- data/lib/geocoder/results/here.rb +4 -1
- data/lib/geocoder/results/ip2location.rb +22 -0
- data/lib/geocoder/results/ipdata_co.rb +0 -5
- data/lib/geocoder/results/ipregistry.rb +308 -0
- data/lib/geocoder/results/ipstack.rb +60 -0
- data/lib/geocoder/results/maxmind.rb +0 -5
- data/lib/geocoder/results/maxmind_local.rb +0 -5
- data/lib/geocoder/results/postcodes_io.rb +40 -0
- data/lib/geocoder/results/smarty_streets.rb +48 -18
- data/lib/geocoder/results/telize.rb +0 -5
- data/lib/geocoder/results/tencent.rb +72 -0
- data/lib/geocoder/results/test.rb +1 -1
- data/lib/geocoder/stores/active_record.rb +1 -3
- data/lib/geocoder/stores/base.rb +1 -1
- data/lib/geocoder/version.rb +1 -1
- metadata +14 -10
- data/lib/geocoder/lookups/mapzen.rb +0 -15
- data/lib/geocoder/lookups/okf.rb +0 -44
- data/lib/geocoder/lookups/ovi.rb +0 -62
- data/lib/geocoder/results/mapzen.rb +0 -5
- data/lib/geocoder/results/okf.rb +0 -106
- data/lib/geocoder/results/ovi.rb +0 -71
|
@@ -11,25 +11,24 @@ 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 = {
|
|
27
|
-
api_key: configuration.api_key
|
|
28
|
-
size: 1
|
|
27
|
+
api_key: configuration.api_key
|
|
29
28
|
}.merge(super)
|
|
30
29
|
|
|
31
30
|
if query.reverse_geocode?
|
|
32
|
-
lat,lon = query.coordinates
|
|
31
|
+
lat, lon = query.coordinates
|
|
33
32
|
params[:'point.lat'] = lat
|
|
34
33
|
params[:'point.lon'] = lon
|
|
35
34
|
else
|
|
@@ -15,12 +15,18 @@ module Geocoder::Lookup
|
|
|
15
15
|
["api_key"]
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
private # ----------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
def base_query_url(query)
|
|
19
21
|
method = query.reverse_geocode? ? "reverse" : "forward"
|
|
20
|
-
"#{protocol}://api.pickpoint.io/v1/#{method}?
|
|
22
|
+
"#{protocol}://api.pickpoint.io/v1/#{method}?"
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
|
|
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,14 +13,18 @@ module Geocoder::Lookup
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def query_url(query)
|
|
16
|
-
"#{
|
|
16
|
+
"#{protocol}://geo.pointp.in/#{configuration.api_key}/json/#{query.sanitized_text}"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
|
|
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
|
-
# don't look up a loopback address, just return the stored result
|
|
23
|
-
return [] if query.
|
|
26
|
+
# don't look up a loopback or private address, just return the stored result
|
|
27
|
+
return [] if query.internal_ip_address?
|
|
24
28
|
doc = fetch_data(query)
|
|
25
29
|
if doc and doc.is_a?(Hash)
|
|
26
30
|
if !data_contains_error?(doc)
|
|
@@ -38,7 +42,7 @@ module Geocoder::Lookup
|
|
|
38
42
|
raise_error(Geocoder::Error) || Geocoder.log(:warn, "Pointpin server error")
|
|
39
43
|
end
|
|
40
44
|
end
|
|
41
|
-
|
|
45
|
+
|
|
42
46
|
return []
|
|
43
47
|
end
|
|
44
48
|
|
|
@@ -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
|
-
|
|
20
|
-
format('%s://%s?%s', protocol, BASE_URL_GEOCODE_V2_00, url_query_string(query))
|
|
21
|
-
end
|
|
18
|
+
private # ----------------------------------------------------------------
|
|
22
19
|
|
|
23
|
-
|
|
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
|
|
@@ -8,15 +8,7 @@ module Geocoder::Lookup
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def required_api_key_parts
|
|
11
|
-
%w(
|
|
12
|
-
end
|
|
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
|
|
11
|
+
%w(auth-id auth-token)
|
|
20
12
|
end
|
|
21
13
|
|
|
22
14
|
# required by API as of 26 March 2015
|
|
@@ -26,13 +18,31 @@ module Geocoder::Lookup
|
|
|
26
18
|
|
|
27
19
|
private # ---------------------------------------------------------------
|
|
28
20
|
|
|
21
|
+
def base_query_url(query)
|
|
22
|
+
if international?(query)
|
|
23
|
+
"#{protocol}://international-street.api.smartystreets.com/verify?"
|
|
24
|
+
elsif zipcode_only?(query)
|
|
25
|
+
"#{protocol}://us-zipcode.api.smartystreets.com/lookup?"
|
|
26
|
+
else
|
|
27
|
+
"#{protocol}://us-street.api.smartystreets.com/street-address?"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
29
31
|
def zipcode_only?(query)
|
|
30
32
|
!query.text.is_a?(Array) and query.to_s.strip =~ /\A\d{5}(-\d{4})?\Z/
|
|
31
33
|
end
|
|
32
34
|
|
|
35
|
+
def international?(query)
|
|
36
|
+
!query.options[:country].nil?
|
|
37
|
+
end
|
|
38
|
+
|
|
33
39
|
def query_url_params(query)
|
|
34
40
|
params = {}
|
|
35
|
-
if
|
|
41
|
+
if international?(query)
|
|
42
|
+
params[:freeform] = query.sanitized_text
|
|
43
|
+
params[:country] = query.options[:country]
|
|
44
|
+
params[:geocode] = true
|
|
45
|
+
elsif zipcode_only?(query)
|
|
36
46
|
params[:zipcode] = query.sanitized_text
|
|
37
47
|
else
|
|
38
48
|
params[:street] = query.sanitized_text
|
|
@@ -14,9 +14,9 @@ module Geocoder::Lookup
|
|
|
14
14
|
|
|
15
15
|
def query_url(query)
|
|
16
16
|
if configuration[:host]
|
|
17
|
-
"#{protocol}://#{configuration[:host]}/
|
|
17
|
+
"#{protocol}://#{configuration[:host]}/location/#{query.sanitized_text}"
|
|
18
18
|
else
|
|
19
|
-
"#{protocol}://telize-v1.p.mashape.com/
|
|
19
|
+
"#{protocol}://telize-v1.p.mashape.com/location/#{query.sanitized_text}?mashape-key=#{api_key}"
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -29,9 +29,13 @@ 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
|
-
# don't look up a loopback address, just return the stored result
|
|
34
|
-
return [reserved_result(query.text)] if query.
|
|
37
|
+
# don't look up a loopback or private address, just return the stored result
|
|
38
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
|
35
39
|
if (doc = fetch_data(query)).nil? or doc['code'] == 401 or empty_result?(doc)
|
|
36
40
|
[]
|
|
37
41
|
else
|
|
@@ -44,12 +48,28 @@ module Geocoder::Lookup
|
|
|
44
48
|
end
|
|
45
49
|
|
|
46
50
|
def reserved_result(ip)
|
|
47
|
-
{
|
|
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
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require "geocoder/results/tencent"
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Tencent < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"Tencent"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def required_api_key_parts
|
|
12
|
+
["key"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def supported_protocols
|
|
16
|
+
[:https]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private # ---------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
def base_query_url(query)
|
|
22
|
+
"#{protocol}://apis.map.qq.com/ws/geocoder/v1/?"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def content_key
|
|
26
|
+
'result'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def results(query, reverse = false)
|
|
30
|
+
return [] unless doc = fetch_data(query)
|
|
31
|
+
case doc['status']
|
|
32
|
+
when 0
|
|
33
|
+
return [doc[content_key]]
|
|
34
|
+
when 199
|
|
35
|
+
raise error(Geocoder::InvalidApiKey, "invalid api key") ||
|
|
36
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: key is not enabled for web service usage.")
|
|
37
|
+
when 311
|
|
38
|
+
raise_error(Geocoder::RequestDenied, "request denied") ||
|
|
39
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: request denied.")
|
|
40
|
+
when 310, 306
|
|
41
|
+
raise_error(Geocoder::InvalidRequest, "invalid request.") ||
|
|
42
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: invalid request.")
|
|
43
|
+
when 311
|
|
44
|
+
raise_error(Geocoder::InvalidApiKey, "invalid api key") ||
|
|
45
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: invalid api key.")
|
|
46
|
+
end
|
|
47
|
+
return []
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def query_url_params(query)
|
|
51
|
+
{
|
|
52
|
+
(query.reverse_geocode? ? :location : :address) => query.sanitized_text,
|
|
53
|
+
:key => configuration.api_key,
|
|
54
|
+
:output => "json"
|
|
55
|
+
}.merge(super)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
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']
|
|
@@ -50,8 +50,8 @@ module Geocoder::Lookup
|
|
|
50
50
|
params = {
|
|
51
51
|
:geocode => q,
|
|
52
52
|
:format => "json",
|
|
53
|
-
:
|
|
54
|
-
:
|
|
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('~')
|
data/lib/geocoder/query.rb
CHANGED
|
@@ -66,6 +66,13 @@ module Geocoder
|
|
|
66
66
|
IpAddress.new(text).valid? rescue false
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
+
##
|
|
70
|
+
# Is the Query text a loopback or private IP address?
|
|
71
|
+
#
|
|
72
|
+
def internal_ip_address?
|
|
73
|
+
ip_address? && IpAddress.new(text).internal?
|
|
74
|
+
end
|
|
75
|
+
|
|
69
76
|
##
|
|
70
77
|
# Is the Query text a loopback IP address?
|
|
71
78
|
#
|
|
@@ -73,6 +80,13 @@ module Geocoder
|
|
|
73
80
|
ip_address? && IpAddress.new(text).loopback?
|
|
74
81
|
end
|
|
75
82
|
|
|
83
|
+
##
|
|
84
|
+
# Is the Query text a private IP address?
|
|
85
|
+
#
|
|
86
|
+
def private_ip_address?
|
|
87
|
+
ip_address? && IpAddress.new(text).private?
|
|
88
|
+
end
|
|
89
|
+
|
|
76
90
|
##
|
|
77
91
|
# Does the given string look like latitude/longitude coordinates?
|
|
78
92
|
#
|
data/lib/geocoder/railtie.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Geocoder
|
|
|
4
4
|
if defined? Rails::Railtie
|
|
5
5
|
require 'rails'
|
|
6
6
|
class Railtie < Rails::Railtie
|
|
7
|
-
initializer 'geocoder.insert_into_active_record' do
|
|
7
|
+
initializer 'geocoder.insert_into_active_record', before: :load_config_initializers do
|
|
8
8
|
ActiveSupport.on_load :active_record do
|
|
9
9
|
Geocoder::Railtie.insert
|
|
10
10
|
end
|
|
@@ -11,34 +11,34 @@ module Geocoder::Result
|
|
|
11
11
|
@data['formatted_address']
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def state
|
|
15
|
-
province
|
|
16
|
-
end
|
|
17
|
-
|
|
18
14
|
def province
|
|
19
|
-
@data['addressComponent']['province']
|
|
15
|
+
@data['addressComponent'] and @data['addressComponent']['province'] or ""
|
|
20
16
|
end
|
|
21
17
|
|
|
18
|
+
alias_method :state, :province
|
|
19
|
+
|
|
22
20
|
def city
|
|
23
|
-
@data['addressComponent']['city']
|
|
21
|
+
@data['addressComponent'] and @data['addressComponent']['city'] or ""
|
|
24
22
|
end
|
|
25
23
|
|
|
26
24
|
def district
|
|
27
|
-
@data['addressComponent']['district']
|
|
25
|
+
@data['addressComponent'] and @data['addressComponent']['district'] or ""
|
|
28
26
|
end
|
|
29
27
|
|
|
30
28
|
def street
|
|
31
|
-
@data['addressComponent']['street']
|
|
29
|
+
@data['addressComponent'] and @data['addressComponent']['street'] or ""
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
def street_number
|
|
35
|
-
@data['addressComponent']['street_number']
|
|
33
|
+
@data['addressComponent'] and @data['addressComponent']['street_number']
|
|
36
34
|
end
|
|
37
35
|
|
|
38
36
|
def formatted_address
|
|
39
|
-
@data['formatted_address']
|
|
37
|
+
@data['formatted_address'] or ""
|
|
40
38
|
end
|
|
41
39
|
|
|
40
|
+
alias_method :address, :formatted_address
|
|
41
|
+
|
|
42
42
|
def address_components
|
|
43
43
|
@data['addressComponent']
|
|
44
44
|
end
|
|
@@ -20,8 +20,20 @@ module Geocoder
|
|
|
20
20
|
##
|
|
21
21
|
# A string in the given format.
|
|
22
22
|
#
|
|
23
|
+
# This default implementation dumbly follows the United States address
|
|
24
|
+
# format and will return incorrect results for most countries. Some APIs
|
|
25
|
+
# return properly formatted addresses and those should be funneled
|
|
26
|
+
# through this method.
|
|
27
|
+
#
|
|
23
28
|
def address(format = :full)
|
|
24
|
-
|
|
29
|
+
if state_code.to_s != ""
|
|
30
|
+
s = ", #{state_code}"
|
|
31
|
+
elsif state.to_s != ""
|
|
32
|
+
s = ", #{state}"
|
|
33
|
+
else
|
|
34
|
+
s = ""
|
|
35
|
+
end
|
|
36
|
+
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '')
|
|
25
37
|
end
|
|
26
38
|
|
|
27
39
|
##
|