geocoder 1.5.0 → 1.6.1
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 +23 -2
- data/LICENSE +1 -1
- data/README.md +15 -17
- data/examples/autoexpire_cache_redis.rb +2 -0
- data/lib/geocoder/calculations.rb +1 -1
- data/lib/geocoder/ip_address.rb +13 -0
- data/lib/geocoder/lookup.rb +6 -4
- data/lib/geocoder/lookups/baidu_ip.rb +1 -1
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +13 -0
- data/lib/geocoder/lookups/base.rb +7 -2
- data/lib/geocoder/lookups/bing.rb +2 -1
- data/lib/geocoder/lookups/esri.rb +38 -13
- data/lib/geocoder/lookups/freegeoip.rb +7 -7
- data/lib/geocoder/lookups/here.rb +28 -22
- data/lib/geocoder/lookups/ip2location.rb +7 -14
- data/lib/geocoder/lookups/ipapi_com.rb +2 -1
- data/lib/geocoder/lookups/ipdata_co.rb +5 -4
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +2 -11
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/ipstack.rb +2 -2
- data/lib/geocoder/lookups/maxmind.rb +2 -2
- data/lib/geocoder/lookups/maxmind_geoip2.rb +4 -7
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pelias.rb +2 -3
- data/lib/geocoder/lookups/pickpoint.rb +1 -1
- data/lib/geocoder/lookups/pointpin.rb +3 -3
- data/lib/geocoder/lookups/smarty_streets.rb +13 -3
- data/lib/geocoder/lookups/telize.rb +2 -2
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +2 -2
- data/lib/geocoder/query.rb +14 -0
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/results/baidu.rb +0 -4
- data/lib/geocoder/results/ban_data_gouv_fr.rb +1 -1
- data/lib/geocoder/results/here.rb +4 -1
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipregistry.rb +308 -0
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/smarty_streets.rb +48 -18
- data/lib/geocoder/results/tencent.rb +72 -0
- data/lib/geocoder/sql.rb +4 -4
- data/lib/geocoder/stores/active_record.rb +1 -1
- data/lib/geocoder/version.rb +1 -1
- data/lib/hash_recursive_merge.rb +1 -2
- data/lib/maxmind_database.rb +3 -3
- metadata +12 -13
- data/lib/geocoder/lookups/geocoder_us.rb +0 -51
- data/lib/geocoder/lookups/mapzen.rb +0 -15
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/geocoder/results/mapzen.rb +0 -5
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Osmnames < Base
|
|
5
|
+
def address
|
|
6
|
+
@data['display_name']
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def coordinates
|
|
10
|
+
[@data['lat'].to_f, @data['lon'].to_f]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def viewport
|
|
14
|
+
west, south, east, north = @data['boundingbox'].map(&:to_f)
|
|
15
|
+
[south, west, north, east]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def state
|
|
19
|
+
@data['state']
|
|
20
|
+
end
|
|
21
|
+
alias_method :state_code, :state
|
|
22
|
+
|
|
23
|
+
def place_class
|
|
24
|
+
@data['class']
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def place_type
|
|
28
|
+
@data['type']
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def postal_code
|
|
32
|
+
''
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def country_code
|
|
36
|
+
@data['country_code']
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def country
|
|
40
|
+
@data['country']
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.response_attributes
|
|
44
|
+
%w[house_number street city name osm_id osm_type boundingbox place_rank
|
|
45
|
+
importance county rank name_suffix]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
response_attributes.each do |a|
|
|
49
|
+
unless method_defined?(a)
|
|
50
|
+
define_method a do
|
|
51
|
+
@data[a]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -15,51 +15,77 @@ module Geocoder::Result
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def address
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
parts =
|
|
19
|
+
if international_endpoint?
|
|
20
|
+
(1..12).map { |i| @data["address#{i}"] }
|
|
21
|
+
else
|
|
22
|
+
[
|
|
23
|
+
delivery_line_1,
|
|
24
|
+
delivery_line_2,
|
|
25
|
+
last_line
|
|
26
|
+
]
|
|
27
|
+
end
|
|
28
|
+
parts.select{ |i| i.to_s != "" }.join(" ")
|
|
23
29
|
end
|
|
24
30
|
|
|
25
31
|
def state
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
if international_endpoint?
|
|
33
|
+
components['administrative_area']
|
|
34
|
+
elsif zipcode_endpoint?
|
|
35
|
+
city_states.first['state']
|
|
36
|
+
else
|
|
28
37
|
components['state_abbreviation']
|
|
38
|
+
end
|
|
29
39
|
end
|
|
30
40
|
|
|
31
41
|
def state_code
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
if international_endpoint?
|
|
43
|
+
components['administrative_area']
|
|
44
|
+
elsif zipcode_endpoint?
|
|
45
|
+
city_states.first['state_abbreviation']
|
|
46
|
+
else
|
|
34
47
|
components['state_abbreviation']
|
|
48
|
+
end
|
|
35
49
|
end
|
|
36
50
|
|
|
37
51
|
def country
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
international_endpoint? ?
|
|
53
|
+
components['country_iso_3'] :
|
|
54
|
+
"United States"
|
|
40
55
|
end
|
|
41
56
|
|
|
42
57
|
def country_code
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
international_endpoint? ?
|
|
59
|
+
components['country_iso_3'] :
|
|
60
|
+
"US"
|
|
45
61
|
end
|
|
46
62
|
|
|
47
63
|
## Extra methods not in base.rb ------------------------
|
|
48
64
|
|
|
49
65
|
def street
|
|
50
|
-
|
|
66
|
+
international_endpoint? ?
|
|
67
|
+
components['thoroughfare_name'] :
|
|
68
|
+
components['street_name']
|
|
51
69
|
end
|
|
52
70
|
|
|
53
71
|
def city
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
if international_endpoint?
|
|
73
|
+
components['locality']
|
|
74
|
+
elsif zipcode_endpoint?
|
|
75
|
+
city_states.first['city']
|
|
76
|
+
else
|
|
56
77
|
components['city_name']
|
|
78
|
+
end
|
|
57
79
|
end
|
|
58
80
|
|
|
59
81
|
def zipcode
|
|
60
|
-
|
|
61
|
-
|
|
82
|
+
if international_endpoint?
|
|
83
|
+
components['postal_code']
|
|
84
|
+
elsif zipcode_endpoint?
|
|
85
|
+
zipcodes.first['zipcode']
|
|
86
|
+
else
|
|
62
87
|
components['zipcode']
|
|
88
|
+
end
|
|
63
89
|
end
|
|
64
90
|
alias_method :postal_code, :zipcode
|
|
65
91
|
|
|
@@ -78,6 +104,10 @@ module Geocoder::Result
|
|
|
78
104
|
zipcodes.any?
|
|
79
105
|
end
|
|
80
106
|
|
|
107
|
+
def international_endpoint?
|
|
108
|
+
!@data['address1'].nil?
|
|
109
|
+
end
|
|
110
|
+
|
|
81
111
|
[
|
|
82
112
|
:delivery_line_1,
|
|
83
113
|
:delivery_line_2,
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Tencent < Base
|
|
5
|
+
|
|
6
|
+
def coordinates
|
|
7
|
+
['lat', 'lng'].map{ |i| @data['location'][i] }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def address
|
|
11
|
+
"#{province}#{city}#{district}#{street}#{street_number}"
|
|
12
|
+
|
|
13
|
+
#@data['title'] or @data['address']
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# NOTE: The Tencent reverse geocoding API has the field named
|
|
17
|
+
# 'address_component' compared to 'address_components' in the
|
|
18
|
+
# regular geocoding API.
|
|
19
|
+
def province
|
|
20
|
+
@data['address_components'] and (@data['address_components']['province']) or
|
|
21
|
+
(@data['address_component'] and @data['address_component']['province']) or
|
|
22
|
+
""
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
alias_method :state, :province
|
|
26
|
+
|
|
27
|
+
def city
|
|
28
|
+
@data['address_components'] and (@data['address_components']['city']) or
|
|
29
|
+
(@data['address_component'] and @data['address_component']['city']) or
|
|
30
|
+
""
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def district
|
|
34
|
+
@data['address_components'] and (@data['address_components']['district']) or
|
|
35
|
+
(@data['address_component'] and @data['address_component']['district']) or
|
|
36
|
+
""
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def street
|
|
40
|
+
@data['address_components'] and (@data['address_components']['street']) or
|
|
41
|
+
(@data['address_component'] and @data['address_component']['street']) or
|
|
42
|
+
""
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def street_number
|
|
46
|
+
@data['address_components'] and (@data['address_components']['street_number']) or
|
|
47
|
+
(@data['address_component'] and @data['address_component']['street_number']) or
|
|
48
|
+
""
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def address_components
|
|
52
|
+
@data['address_components'] or @data['address_component']
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def state_code
|
|
56
|
+
""
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def postal_code
|
|
60
|
+
""
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def country
|
|
64
|
+
"China"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def country_code
|
|
68
|
+
"CN"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
end
|
data/lib/geocoder/sql.rb
CHANGED
|
@@ -44,13 +44,13 @@ module Geocoder
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def within_bounding_box(sw_lat, sw_lng, ne_lat, ne_lng, lat_attr, lon_attr)
|
|
47
|
-
spans = "#{lat_attr} BETWEEN #{sw_lat} AND #{ne_lat} AND "
|
|
47
|
+
spans = "#{lat_attr} BETWEEN #{sw_lat.to_f} AND #{ne_lat.to_f} AND "
|
|
48
48
|
# handle box that spans 180 longitude
|
|
49
49
|
if sw_lng.to_f > ne_lng.to_f
|
|
50
|
-
spans + "(#{lon_attr} BETWEEN #{sw_lng} AND 180 OR " +
|
|
51
|
-
"#{lon_attr} BETWEEN -180 AND #{ne_lng})"
|
|
50
|
+
spans + "(#{lon_attr} BETWEEN #{sw_lng.to_f} AND 180 OR " +
|
|
51
|
+
"#{lon_attr} BETWEEN -180 AND #{ne_lng.to_f})"
|
|
52
52
|
else
|
|
53
|
-
spans + "#{lon_attr} BETWEEN #{sw_lng} AND #{ne_lng}"
|
|
53
|
+
spans + "#{lon_attr} BETWEEN #{sw_lng.to_f} AND #{ne_lng.to_f}"
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
@@ -60,7 +60,7 @@ module Geocoder::Store
|
|
|
60
60
|
# corner followed by the northeast corner of the box
|
|
61
61
|
# (<tt>[[sw_lat, sw_lon], [ne_lat, ne_lon]]</tt>).
|
|
62
62
|
#
|
|
63
|
-
scope :within_bounding_box, lambda{
|
|
63
|
+
scope :within_bounding_box, lambda{ |*bounds|
|
|
64
64
|
sw_lat, sw_lng, ne_lat, ne_lng = bounds.flatten if bounds
|
|
65
65
|
if sw_lat && sw_lng && ne_lat && ne_lng
|
|
66
66
|
where(Geocoder::Sql.within_bounding_box(
|
data/lib/geocoder/version.rb
CHANGED
data/lib/hash_recursive_merge.rb
CHANGED
|
@@ -60,9 +60,8 @@ module HashRecursiveMerge
|
|
|
60
60
|
# h1.merge(h2) #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
|
|
61
61
|
#
|
|
62
62
|
def rmerge(other_hash)
|
|
63
|
-
r = {}
|
|
64
63
|
merge(other_hash) do |key, oldval, newval|
|
|
65
|
-
|
|
64
|
+
oldval.class == self.class ? oldval.rmerge(newval) : newval
|
|
66
65
|
end
|
|
67
66
|
end
|
|
68
67
|
|
data/lib/maxmind_database.rb
CHANGED
|
@@ -96,9 +96,9 @@ module Geocoder
|
|
|
96
96
|
|
|
97
97
|
def archive_url_path(package)
|
|
98
98
|
{
|
|
99
|
-
geolite_country_csv: "
|
|
100
|
-
geolite_city_csv: "
|
|
101
|
-
geolite_asn_csv: "
|
|
99
|
+
geolite_country_csv: "GeoLite2-Country-CSV.zip",
|
|
100
|
+
geolite_city_csv: "GeoLite2-City-CSV.zip",
|
|
101
|
+
geolite_asn_csv: "GeoLite2-ASN-CSV.zip"
|
|
102
102
|
}[package]
|
|
103
103
|
end
|
|
104
104
|
|
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.
|
|
4
|
+
version: 1.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alex Reisner
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-01-23 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,
|
|
@@ -59,7 +59,6 @@ files:
|
|
|
59
59
|
- lib/geocoder/lookups/esri.rb
|
|
60
60
|
- lib/geocoder/lookups/freegeoip.rb
|
|
61
61
|
- lib/geocoder/lookups/geocoder_ca.rb
|
|
62
|
-
- lib/geocoder/lookups/geocoder_us.rb
|
|
63
62
|
- lib/geocoder/lookups/geocodio.rb
|
|
64
63
|
- lib/geocoder/lookups/geoip2.rb
|
|
65
64
|
- lib/geocoder/lookups/geoportail_lu.rb
|
|
@@ -71,18 +70,20 @@ files:
|
|
|
71
70
|
- lib/geocoder/lookups/ip2location.rb
|
|
72
71
|
- lib/geocoder/lookups/ipapi_com.rb
|
|
73
72
|
- lib/geocoder/lookups/ipdata_co.rb
|
|
73
|
+
- lib/geocoder/lookups/ipgeolocation.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
|
|
78
79
|
- lib/geocoder/lookups/mapbox.rb
|
|
79
80
|
- lib/geocoder/lookups/mapquest.rb
|
|
80
|
-
- lib/geocoder/lookups/mapzen.rb
|
|
81
81
|
- lib/geocoder/lookups/maxmind.rb
|
|
82
82
|
- lib/geocoder/lookups/maxmind_geoip2.rb
|
|
83
83
|
- lib/geocoder/lookups/maxmind_local.rb
|
|
84
84
|
- lib/geocoder/lookups/nominatim.rb
|
|
85
85
|
- lib/geocoder/lookups/opencagedata.rb
|
|
86
|
+
- lib/geocoder/lookups/osmnames.rb
|
|
86
87
|
- lib/geocoder/lookups/pelias.rb
|
|
87
88
|
- lib/geocoder/lookups/pickpoint.rb
|
|
88
89
|
- lib/geocoder/lookups/pointpin.rb
|
|
@@ -90,6 +91,7 @@ files:
|
|
|
90
91
|
- lib/geocoder/lookups/postcodes_io.rb
|
|
91
92
|
- lib/geocoder/lookups/smarty_streets.rb
|
|
92
93
|
- lib/geocoder/lookups/telize.rb
|
|
94
|
+
- lib/geocoder/lookups/tencent.rb
|
|
93
95
|
- lib/geocoder/lookups/test.rb
|
|
94
96
|
- lib/geocoder/lookups/yandex.rb
|
|
95
97
|
- lib/geocoder/models/active_record.rb
|
|
@@ -111,7 +113,6 @@ files:
|
|
|
111
113
|
- lib/geocoder/results/esri.rb
|
|
112
114
|
- lib/geocoder/results/freegeoip.rb
|
|
113
115
|
- lib/geocoder/results/geocoder_ca.rb
|
|
114
|
-
- lib/geocoder/results/geocoder_us.rb
|
|
115
116
|
- lib/geocoder/results/geocodio.rb
|
|
116
117
|
- lib/geocoder/results/geoip2.rb
|
|
117
118
|
- lib/geocoder/results/geoportail_lu.rb
|
|
@@ -123,18 +124,20 @@ files:
|
|
|
123
124
|
- lib/geocoder/results/ip2location.rb
|
|
124
125
|
- lib/geocoder/results/ipapi_com.rb
|
|
125
126
|
- lib/geocoder/results/ipdata_co.rb
|
|
127
|
+
- lib/geocoder/results/ipgeolocation.rb
|
|
126
128
|
- lib/geocoder/results/ipinfo_io.rb
|
|
129
|
+
- lib/geocoder/results/ipregistry.rb
|
|
127
130
|
- lib/geocoder/results/ipstack.rb
|
|
128
131
|
- lib/geocoder/results/latlon.rb
|
|
129
132
|
- lib/geocoder/results/location_iq.rb
|
|
130
133
|
- lib/geocoder/results/mapbox.rb
|
|
131
134
|
- lib/geocoder/results/mapquest.rb
|
|
132
|
-
- lib/geocoder/results/mapzen.rb
|
|
133
135
|
- lib/geocoder/results/maxmind.rb
|
|
134
136
|
- lib/geocoder/results/maxmind_geoip2.rb
|
|
135
137
|
- lib/geocoder/results/maxmind_local.rb
|
|
136
138
|
- lib/geocoder/results/nominatim.rb
|
|
137
139
|
- lib/geocoder/results/opencagedata.rb
|
|
140
|
+
- lib/geocoder/results/osmnames.rb
|
|
138
141
|
- lib/geocoder/results/pelias.rb
|
|
139
142
|
- lib/geocoder/results/pickpoint.rb
|
|
140
143
|
- lib/geocoder/results/pointpin.rb
|
|
@@ -142,6 +145,7 @@ files:
|
|
|
142
145
|
- lib/geocoder/results/postcodes_io.rb
|
|
143
146
|
- lib/geocoder/results/smarty_streets.rb
|
|
144
147
|
- lib/geocoder/results/telize.rb
|
|
148
|
+
- lib/geocoder/results/tencent.rb
|
|
145
149
|
- lib/geocoder/results/test.rb
|
|
146
150
|
- lib/geocoder/results/yandex.rb
|
|
147
151
|
- lib/geocoder/sql.rb
|
|
@@ -161,11 +165,7 @@ licenses:
|
|
|
161
165
|
metadata:
|
|
162
166
|
source_code_uri: https://github.com/alexreisner/geocoder
|
|
163
167
|
changelog_uri: https://github.com/alexreisner/geocoder/blob/master/CHANGELOG.md
|
|
164
|
-
post_install_message:
|
|
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
|
-
|
|
168
|
+
post_install_message:
|
|
169
169
|
rdoc_options: []
|
|
170
170
|
require_paths:
|
|
171
171
|
- lib
|
|
@@ -180,8 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
180
180
|
- !ruby/object:Gem::Version
|
|
181
181
|
version: '0'
|
|
182
182
|
requirements: []
|
|
183
|
-
|
|
184
|
-
rubygems_version: 2.5.2
|
|
183
|
+
rubygems_version: 3.0.1
|
|
185
184
|
signing_key:
|
|
186
185
|
specification_version: 4
|
|
187
186
|
summary: Complete geocoding solution for Ruby.
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require 'geocoder/lookups/base'
|
|
2
|
-
require "geocoder/results/geocoder_us"
|
|
3
|
-
|
|
4
|
-
module Geocoder::Lookup
|
|
5
|
-
class GeocoderUs < Base
|
|
6
|
-
|
|
7
|
-
def name
|
|
8
|
-
"Geocoder.us"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def supported_protocols
|
|
12
|
-
[:http]
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private # ----------------------------------------------------------------
|
|
16
|
-
|
|
17
|
-
def base_query_url(query)
|
|
18
|
-
base_query_url_with_optional_key(configuration.api_key)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def cache_key(query)
|
|
22
|
-
base_query_url_with_optional_key(nil) + url_query_string(query)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def base_query_url_with_optional_key(key = nil)
|
|
26
|
-
base = "#{protocol}://"
|
|
27
|
-
if configuration.api_key
|
|
28
|
-
base << "#{configuration.api_key}@"
|
|
29
|
-
end
|
|
30
|
-
base + "geocoder.us/member/service/csv/geocode?"
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def results(query)
|
|
34
|
-
return [] unless doc = fetch_data(query)
|
|
35
|
-
if doc[0].to_s =~ /^(\d+)\:/
|
|
36
|
-
return []
|
|
37
|
-
else
|
|
38
|
-
return [doc.size == 5 ? ((doc[0..1] << nil) + doc[2..4]) : doc]
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def query_url_params(query)
|
|
43
|
-
(query.text =~ /^\d{5}(?:-\d{4})?$/ ? {:zip => query} : {:address => query.sanitized_text}).merge(super)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def parse_raw_data(raw_data)
|
|
47
|
-
raw_data.chomp.split(',')
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|