geocoder 1.4.3 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +64 -0
- data/LICENSE +1 -1
- data/README.md +365 -883
- data/examples/autoexpire_cache_redis.rb +5 -3
- data/lib/generators/geocoder/config/templates/initializer.rb +3 -2
- data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +2 -0
- data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +2 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +1 -1
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +1 -1
- data/lib/generators/geocoder/migration_version.rb +15 -0
- data/lib/geocoder/cache.rb +6 -2
- 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 +13 -6
- data/lib/geocoder/lookups/amap.rb +63 -0
- 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 +17 -4
- data/lib/geocoder/lookups/base.rb +28 -5
- data/lib/geocoder/lookups/bing.rb +15 -13
- data/lib/geocoder/lookups/db_ip_com.rb +52 -0
- data/lib/geocoder/lookups/dstk.rb +4 -2
- data/lib/geocoder/lookups/esri.rb +39 -29
- data/lib/geocoder/lookups/freegeoip.rb +16 -7
- data/lib/geocoder/lookups/geocoder_ca.rb +4 -4
- data/lib/geocoder/lookups/geocodio.rb +5 -5
- data/lib/geocoder/lookups/geoportail_lu.rb +7 -7
- data/lib/geocoder/lookups/google.rb +13 -9
- 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 +11 -1
- data/lib/geocoder/lookups/here.rb +29 -23
- data/lib/geocoder/lookups/ip2location.rb +67 -0
- data/lib/geocoder/lookups/ipapi_com.rb +9 -13
- data/lib/geocoder/lookups/ipdata_co.rb +62 -0
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- 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 +26 -8
- data/lib/geocoder/lookups/mapbox.rb +12 -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 +17 -5
- data/lib/geocoder/lookups/opencagedata.rb +7 -6
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pelias.rb +8 -9
- data/lib/geocoder/lookups/pickpoint.rb +41 -0
- 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 +12 -8
- data/lib/geocoder/models/active_record.rb +4 -3
- data/lib/geocoder/query.rb +14 -0
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/request.rb +32 -0
- data/lib/geocoder/results/amap.rb +87 -0
- data/lib/geocoder/results/baidu.rb +10 -14
- data/lib/geocoder/results/ban_data_gouv_fr.rb +1 -1
- data/lib/geocoder/results/base.rb +13 -1
- data/lib/geocoder/results/bing.rb +1 -1
- data/lib/geocoder/results/db_ip_com.rb +58 -0
- data/lib/geocoder/results/freegeoip.rb +0 -5
- data/lib/geocoder/results/geocoder_ca.rb +3 -3
- data/lib/geocoder/results/geoip2.rb +24 -10
- data/lib/geocoder/results/geoportail_lu.rb +5 -3
- data/lib/geocoder/results/google.rb +16 -5
- data/lib/geocoder/results/here.rb +12 -1
- data/lib/geocoder/results/ip2location.rb +22 -0
- data/lib/geocoder/results/ipdata_co.rb +40 -0
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- 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/nominatim.rb +12 -0
- data/lib/geocoder/results/opencagedata.rb +12 -2
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/pickpoint.rb +6 -0
- data/lib/geocoder/results/postcodes_io.rb +40 -0
- data/lib/geocoder/results/smarty_streets.rb +55 -19
- 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/sql.rb +4 -4
- data/lib/geocoder/stores/active_record.rb +16 -5
- data/lib/geocoder/stores/base.rb +1 -2
- data/lib/geocoder/version.rb +1 -1
- data/lib/hash_recursive_merge.rb +1 -2
- data/lib/maxmind_database.rb +3 -3
- data/lib/tasks/geocoder.rake +11 -3
- metadata +30 -14
- data/lib/geocoder/lookups/geocoder_us.rb +0 -43
- 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/geocoder_us.rb +0 -39
- data/lib/geocoder/results/mapzen.rb +0 -5
- data/lib/geocoder/results/okf.rb +0 -106
- data/lib/geocoder/results/ovi.rb +0 -71
@@ -0,0 +1,308 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Ipregistry < Base
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
super
|
8
|
+
|
9
|
+
@data = flatten_hash(data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def flatten_hash(hash)
|
13
|
+
hash.each_with_object({}) do |(k, v), h|
|
14
|
+
if v.is_a? Hash
|
15
|
+
flatten_hash(v).map do |h_k, h_v|
|
16
|
+
h["#{k}_#{h_k}".to_s] = h_v
|
17
|
+
end
|
18
|
+
else
|
19
|
+
h[k] = v
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private :flatten_hash
|
25
|
+
|
26
|
+
def city
|
27
|
+
@data['location_city']
|
28
|
+
end
|
29
|
+
|
30
|
+
def country
|
31
|
+
@data['location_country_name']
|
32
|
+
end
|
33
|
+
|
34
|
+
def country_code
|
35
|
+
@data['location_country_code']
|
36
|
+
end
|
37
|
+
|
38
|
+
def latitude
|
39
|
+
@data['location_latitude']
|
40
|
+
end
|
41
|
+
|
42
|
+
def longitude
|
43
|
+
@data['location_longitude']
|
44
|
+
end
|
45
|
+
|
46
|
+
def postal_code
|
47
|
+
@data['location_postal']
|
48
|
+
end
|
49
|
+
|
50
|
+
def state
|
51
|
+
@data['location_region_name']
|
52
|
+
end
|
53
|
+
|
54
|
+
def state_code
|
55
|
+
@data['location_region_code']
|
56
|
+
end
|
57
|
+
|
58
|
+
# methods for fields specific to Ipregistry
|
59
|
+
|
60
|
+
def ip
|
61
|
+
@data["ip"]
|
62
|
+
end
|
63
|
+
|
64
|
+
def type
|
65
|
+
@data["type"]
|
66
|
+
end
|
67
|
+
|
68
|
+
def hostname
|
69
|
+
@data["hostname"]
|
70
|
+
end
|
71
|
+
|
72
|
+
def carrier_name
|
73
|
+
@data["carrier_name"]
|
74
|
+
end
|
75
|
+
|
76
|
+
def carrier_mcc
|
77
|
+
@data["carrier_mcc"]
|
78
|
+
end
|
79
|
+
|
80
|
+
def carrier_mnc
|
81
|
+
@data["carrier_mnc"]
|
82
|
+
end
|
83
|
+
|
84
|
+
def connection_asn
|
85
|
+
@data["connection_asn"]
|
86
|
+
end
|
87
|
+
|
88
|
+
def connection_domain
|
89
|
+
@data["connection_domain"]
|
90
|
+
end
|
91
|
+
|
92
|
+
def connection_organization
|
93
|
+
@data["connection_organization"]
|
94
|
+
end
|
95
|
+
|
96
|
+
def connection_type
|
97
|
+
@data["connection_type"]
|
98
|
+
end
|
99
|
+
|
100
|
+
def currency_code
|
101
|
+
@data["currency_code"]
|
102
|
+
end
|
103
|
+
|
104
|
+
def currency_name
|
105
|
+
@data["currency_name"]
|
106
|
+
end
|
107
|
+
|
108
|
+
def currency_plural
|
109
|
+
@data["currency_plural"]
|
110
|
+
end
|
111
|
+
|
112
|
+
def currency_symbol
|
113
|
+
@data["currency_symbol"]
|
114
|
+
end
|
115
|
+
|
116
|
+
def currency_symbol_native
|
117
|
+
@data["currency_symbol_native"]
|
118
|
+
end
|
119
|
+
|
120
|
+
def currency_format_negative_prefix
|
121
|
+
@data["currency_format_negative_prefix"]
|
122
|
+
end
|
123
|
+
|
124
|
+
def currency_format_negative_suffix
|
125
|
+
@data["currency_format_negative_suffix"]
|
126
|
+
end
|
127
|
+
|
128
|
+
def currency_format_positive_prefix
|
129
|
+
@data["currency_format_positive_prefix"]
|
130
|
+
end
|
131
|
+
|
132
|
+
def currency_format_positive_suffix
|
133
|
+
@data["currency_format_positive_suffix"]
|
134
|
+
end
|
135
|
+
|
136
|
+
def location_continent_code
|
137
|
+
@data["location_continent_code"]
|
138
|
+
end
|
139
|
+
|
140
|
+
def location_continent_name
|
141
|
+
@data["location_continent_name"]
|
142
|
+
end
|
143
|
+
|
144
|
+
def location_country_area
|
145
|
+
@data["location_country_area"]
|
146
|
+
end
|
147
|
+
|
148
|
+
def location_country_borders
|
149
|
+
@data["location_country_borders"]
|
150
|
+
end
|
151
|
+
|
152
|
+
def location_country_calling_code
|
153
|
+
@data["location_country_calling_code"]
|
154
|
+
end
|
155
|
+
|
156
|
+
def location_country_capital
|
157
|
+
@data["location_country_capital"]
|
158
|
+
end
|
159
|
+
|
160
|
+
def location_country_code
|
161
|
+
@data["location_country_code"]
|
162
|
+
end
|
163
|
+
|
164
|
+
def location_country_name
|
165
|
+
@data["location_country_name"]
|
166
|
+
end
|
167
|
+
|
168
|
+
def location_country_population
|
169
|
+
@data["location_country_population"]
|
170
|
+
end
|
171
|
+
|
172
|
+
def location_country_population_density
|
173
|
+
@data["location_country_population_density"]
|
174
|
+
end
|
175
|
+
|
176
|
+
def location_country_flag_emoji
|
177
|
+
@data["location_country_flag_emoji"]
|
178
|
+
end
|
179
|
+
|
180
|
+
def location_country_flag_emoji_unicode
|
181
|
+
@data["location_country_flag_emoji_unicode"]
|
182
|
+
end
|
183
|
+
|
184
|
+
def location_country_flag_emojitwo
|
185
|
+
@data["location_country_flag_emojitwo"]
|
186
|
+
end
|
187
|
+
|
188
|
+
def location_country_flag_noto
|
189
|
+
@data["location_country_flag_noto"]
|
190
|
+
end
|
191
|
+
|
192
|
+
def location_country_flag_twemoji
|
193
|
+
@data["location_country_flag_twemoji"]
|
194
|
+
end
|
195
|
+
|
196
|
+
def location_country_flag_wikimedia
|
197
|
+
@data["location_country_flag_wikimedia"]
|
198
|
+
end
|
199
|
+
|
200
|
+
def location_country_languages
|
201
|
+
@data["location_country_languages"]
|
202
|
+
end
|
203
|
+
|
204
|
+
def location_country_tld
|
205
|
+
@data["location_country_tld"]
|
206
|
+
end
|
207
|
+
|
208
|
+
def location_region_code
|
209
|
+
@data["location_region_code"]
|
210
|
+
end
|
211
|
+
|
212
|
+
def location_region_name
|
213
|
+
@data["location_region_name"]
|
214
|
+
end
|
215
|
+
|
216
|
+
def location_city
|
217
|
+
@data["location_city"]
|
218
|
+
end
|
219
|
+
|
220
|
+
def location_postal
|
221
|
+
@data["location_postal"]
|
222
|
+
end
|
223
|
+
|
224
|
+
def location_latitude
|
225
|
+
@data["location_latitude"]
|
226
|
+
end
|
227
|
+
|
228
|
+
def location_longitude
|
229
|
+
@data["location_longitude"]
|
230
|
+
end
|
231
|
+
|
232
|
+
def location_language_code
|
233
|
+
@data["location_language_code"]
|
234
|
+
end
|
235
|
+
|
236
|
+
def location_language_name
|
237
|
+
@data["location_language_name"]
|
238
|
+
end
|
239
|
+
|
240
|
+
def location_language_native
|
241
|
+
@data["location_language_native"]
|
242
|
+
end
|
243
|
+
|
244
|
+
def location_in_eu
|
245
|
+
@data["location_in_eu"]
|
246
|
+
end
|
247
|
+
|
248
|
+
def security_is_bogon
|
249
|
+
@data["security_is_bogon"]
|
250
|
+
end
|
251
|
+
|
252
|
+
def security_is_cloud_provider
|
253
|
+
@data["security_is_cloud_provider"]
|
254
|
+
end
|
255
|
+
|
256
|
+
def security_is_tor
|
257
|
+
@data["security_is_tor"]
|
258
|
+
end
|
259
|
+
|
260
|
+
def security_is_tor_exit
|
261
|
+
@data["security_is_tor_exit"]
|
262
|
+
end
|
263
|
+
|
264
|
+
def security_is_proxy
|
265
|
+
@data["security_is_proxy"]
|
266
|
+
end
|
267
|
+
|
268
|
+
def security_is_anonymous
|
269
|
+
@data["security_is_anonymous"]
|
270
|
+
end
|
271
|
+
|
272
|
+
def security_is_abuser
|
273
|
+
@data["security_is_abuser"]
|
274
|
+
end
|
275
|
+
|
276
|
+
def security_is_attacker
|
277
|
+
@data["security_is_attacker"]
|
278
|
+
end
|
279
|
+
|
280
|
+
def security_is_threat
|
281
|
+
@data["security_is_threat"]
|
282
|
+
end
|
283
|
+
|
284
|
+
def time_zone_id
|
285
|
+
@data["time_zone_id"]
|
286
|
+
end
|
287
|
+
|
288
|
+
def time_zone_abbreviation
|
289
|
+
@data["time_zone_abbreviation"]
|
290
|
+
end
|
291
|
+
|
292
|
+
def time_zone_current_time
|
293
|
+
@data["time_zone_current_time"]
|
294
|
+
end
|
295
|
+
|
296
|
+
def time_zone_name
|
297
|
+
@data["time_zone_name"]
|
298
|
+
end
|
299
|
+
|
300
|
+
def time_zone_offset
|
301
|
+
@data["time_zone_offset"]
|
302
|
+
end
|
303
|
+
|
304
|
+
def time_zone_in_daylight_saving
|
305
|
+
@data["time_zone_in_daylight_saving"]
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Ipstack < Base
|
5
|
+
|
6
|
+
def address(format = :full)
|
7
|
+
s = region_code.empty? ? "" : ", #{region_code}"
|
8
|
+
"#{city}#{s} #{zip}, #{country_name}".sub(/^[ ,]*/, "")
|
9
|
+
end
|
10
|
+
|
11
|
+
def state
|
12
|
+
@data['region_name']
|
13
|
+
end
|
14
|
+
|
15
|
+
def state_code
|
16
|
+
@data['region_code']
|
17
|
+
end
|
18
|
+
|
19
|
+
def country
|
20
|
+
@data['country_name']
|
21
|
+
end
|
22
|
+
|
23
|
+
def postal_code
|
24
|
+
@data['zip'] || @data['zipcode'] || @data['zip_code']
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.response_attributes
|
28
|
+
[
|
29
|
+
['ip', ''],
|
30
|
+
['hostname', ''],
|
31
|
+
['continent_code', ''],
|
32
|
+
['continent_name', ''],
|
33
|
+
['country_code', ''],
|
34
|
+
['country_name', ''],
|
35
|
+
['region_code', ''],
|
36
|
+
['region_name', ''],
|
37
|
+
['city', ''],
|
38
|
+
['zip', ''],
|
39
|
+
['latitude', 0],
|
40
|
+
['longitude', 0],
|
41
|
+
['location', {}],
|
42
|
+
['time_zone', {}],
|
43
|
+
['currency', {}],
|
44
|
+
['connection', {}],
|
45
|
+
['security', {}],
|
46
|
+
]
|
47
|
+
end
|
48
|
+
|
49
|
+
response_attributes.each do |attr, default|
|
50
|
+
define_method attr do
|
51
|
+
@data[attr] || default
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def metro_code
|
56
|
+
Geocoder.log(:warn, "Ipstack does not implement `metro_code` in api results. Please discontinue use.")
|
57
|
+
0 # no longer implemented by ipstack
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -87,11 +87,6 @@ module Geocoder::Result
|
|
87
87
|
[data_hash[:latitude].to_f, data_hash[:longitude].to_f]
|
88
88
|
end
|
89
89
|
|
90
|
-
def address(format = :full)
|
91
|
-
s = state_code.to_s == "" ? "" : ", #{state_code}"
|
92
|
-
"#{city}#{s} #{postal_code}, #{country_code}".sub(/^[ ,]*/, "")
|
93
|
-
end
|
94
|
-
|
95
90
|
def city
|
96
91
|
data_hash[:city_name]
|
97
92
|
end
|
@@ -3,11 +3,6 @@ require 'geocoder/results/base'
|
|
3
3
|
module Geocoder::Result
|
4
4
|
class MaxmindLocal < Base
|
5
5
|
|
6
|
-
def address(format = :full)
|
7
|
-
s = state.to_s == "" ? "" : ", #{state}"
|
8
|
-
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
9
|
-
end
|
10
|
-
|
11
6
|
def coordinates
|
12
7
|
[@data[:latitude], @data[:longitude]]
|
13
8
|
end
|
@@ -64,6 +64,18 @@ module Geocoder::Result
|
|
64
64
|
@data['address']['suburb']
|
65
65
|
end
|
66
66
|
|
67
|
+
def city_district
|
68
|
+
@data['address']['city_district']
|
69
|
+
end
|
70
|
+
|
71
|
+
def state_district
|
72
|
+
@data['address']['state_district']
|
73
|
+
end
|
74
|
+
|
75
|
+
def neighbourhood
|
76
|
+
@data['address']['neighbourhood']
|
77
|
+
end
|
78
|
+
|
67
79
|
def coordinates
|
68
80
|
[@data['lat'].to_f, @data['lon'].to_f]
|
69
81
|
end
|
@@ -36,12 +36,13 @@ module Geocoder::Result
|
|
36
36
|
@data['components']['village']
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
39
|
def state
|
41
40
|
@data['components']['state']
|
42
41
|
end
|
43
42
|
|
44
|
-
|
43
|
+
def state_code
|
44
|
+
@data['components']['state_code']
|
45
|
+
end
|
45
46
|
|
46
47
|
def postal_code
|
47
48
|
@data['components']['postcode'].to_s
|
@@ -74,6 +75,15 @@ module Geocoder::Result
|
|
74
75
|
[south, west, north, east]
|
75
76
|
end
|
76
77
|
|
78
|
+
def time_zone
|
79
|
+
# The OpenCage API documentation states that `annotations` is available
|
80
|
+
# "when possible" https://geocoder.opencagedata.com/api#annotations
|
81
|
+
@data
|
82
|
+
.fetch('annotations', {})
|
83
|
+
.fetch('timezone', {})
|
84
|
+
.fetch('name', nil)
|
85
|
+
end
|
86
|
+
|
77
87
|
def self.response_attributes
|
78
88
|
%w[boundingbox license
|
79
89
|
formatted stadium]
|
@@ -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
|