geocoder 1.5.0 → 1.6.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.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +29 -2
  3. data/LICENSE +1 -1
  4. data/README.md +15 -17
  5. data/bin/console +7 -0
  6. data/examples/autoexpire_cache_redis.rb +2 -0
  7. data/lib/easting_northing.rb +171 -0
  8. data/lib/geocoder/calculations.rb +1 -1
  9. data/lib/geocoder/ip_address.rb +13 -0
  10. data/lib/geocoder/lookup.rb +8 -4
  11. data/lib/geocoder/lookups/baidu_ip.rb +1 -1
  12. data/lib/geocoder/lookups/ban_data_gouv_fr.rb +13 -0
  13. data/lib/geocoder/lookups/base.rb +7 -2
  14. data/lib/geocoder/lookups/bing.rb +2 -1
  15. data/lib/geocoder/lookups/esri.rb +38 -13
  16. data/lib/geocoder/lookups/freegeoip.rb +7 -7
  17. data/lib/geocoder/lookups/here.rb +28 -22
  18. data/lib/geocoder/lookups/ip2location.rb +7 -14
  19. data/lib/geocoder/lookups/ipapi_com.rb +2 -1
  20. data/lib/geocoder/lookups/ipdata_co.rb +5 -4
  21. data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
  22. data/lib/geocoder/lookups/ipinfo_io.rb +2 -11
  23. data/lib/geocoder/lookups/ipregistry.rb +68 -0
  24. data/lib/geocoder/lookups/ipstack.rb +2 -2
  25. data/lib/geocoder/lookups/maxmind.rb +2 -2
  26. data/lib/geocoder/lookups/maxmind_geoip2.rb +4 -7
  27. data/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
  28. data/lib/geocoder/lookups/osmnames.rb +57 -0
  29. data/lib/geocoder/lookups/pelias.rb +2 -3
  30. data/lib/geocoder/lookups/pickpoint.rb +1 -1
  31. data/lib/geocoder/lookups/pointpin.rb +3 -3
  32. data/lib/geocoder/lookups/smarty_streets.rb +13 -3
  33. data/lib/geocoder/lookups/telize.rb +2 -2
  34. data/lib/geocoder/lookups/tencent.rb +59 -0
  35. data/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
  36. data/lib/geocoder/lookups/yandex.rb +2 -2
  37. data/lib/geocoder/query.rb +14 -0
  38. data/lib/geocoder/railtie.rb +1 -1
  39. data/lib/geocoder/results/baidu.rb +0 -4
  40. data/lib/geocoder/results/ban_data_gouv_fr.rb +1 -1
  41. data/lib/geocoder/results/here.rb +4 -1
  42. data/lib/geocoder/results/ipgeolocation.rb +59 -0
  43. data/lib/geocoder/results/ipregistry.rb +308 -0
  44. data/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
  45. data/lib/geocoder/results/osmnames.rb +56 -0
  46. data/lib/geocoder/results/smarty_streets.rb +48 -18
  47. data/lib/geocoder/results/tencent.rb +72 -0
  48. data/lib/geocoder/results/uk_ordnance_survey_names.rb +59 -0
  49. data/lib/geocoder/results/yandex.rb +217 -59
  50. data/lib/geocoder/sql.rb +4 -4
  51. data/lib/geocoder/stores/active_record.rb +1 -1
  52. data/lib/geocoder/version.rb +1 -1
  53. data/lib/hash_recursive_merge.rb +1 -2
  54. data/lib/maxmind_database.rb +3 -3
  55. metadata +18 -13
  56. data/lib/geocoder/lookups/geocoder_us.rb +0 -51
  57. data/lib/geocoder/lookups/mapzen.rb +0 -15
  58. data/lib/geocoder/results/geocoder_us.rb +0 -39
  59. data/lib/geocoder/results/mapzen.rb +0 -5
@@ -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,62 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class NationaalGeoregisterNl < Base
5
+
6
+ def response_attributes
7
+ @data
8
+ end
9
+
10
+ def coordinates
11
+ @data['centroide_ll'][6..-2].split(' ').map(&:to_f)
12
+ end
13
+
14
+ def formatted_address
15
+ @data['weergavenaam']
16
+ end
17
+
18
+ alias_method :address, :formatted_address
19
+
20
+ def province
21
+ @data['provincienaam']
22
+ end
23
+
24
+ alias_method :state, :province
25
+
26
+ def city
27
+ @data['woonplaatsnaam']
28
+ end
29
+
30
+ def district
31
+ @data['gemeentenaam']
32
+ end
33
+
34
+ def street
35
+ @data['straatnaam']
36
+ end
37
+
38
+ def street_number
39
+ @data['huis_nlt']
40
+ end
41
+
42
+ def address_components
43
+ @data
44
+ end
45
+
46
+ def state_code
47
+ @data['provinciecode']
48
+ end
49
+
50
+ def postal_code
51
+ @data['postcode']
52
+ end
53
+
54
+ def country
55
+ "Netherlands"
56
+ end
57
+
58
+ def country_code
59
+ "NL"
60
+ end
61
+ end
62
+ end
@@ -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
- delivery_line_1,
20
- delivery_line_2,
21
- last_line
22
- ].select{ |i| i.to_s != "" }.join(" ")
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
- zipcode_endpoint? ?
27
- city_states.first['state'] :
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
- zipcode_endpoint? ?
33
- city_states.first['state_abbreviation'] :
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
- # SmartyStreets returns results for USA only
39
- "United States"
52
+ international_endpoint? ?
53
+ components['country_iso_3'] :
54
+ "United States"
40
55
  end
41
56
 
42
57
  def country_code
43
- # SmartyStreets returns results for USA only
44
- "US"
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
- components['street_name']
66
+ international_endpoint? ?
67
+ components['thoroughfare_name'] :
68
+ components['street_name']
51
69
  end
52
70
 
53
71
  def city
54
- zipcode_endpoint? ?
55
- city_states.first['city'] :
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
- zipcode_endpoint? ?
61
- zipcodes.first['zipcode'] :
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,