geocoder 1.2.6 → 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.
Files changed (276) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +189 -1
  3. data/LICENSE +1 -1
  4. data/README.md +387 -755
  5. data/examples/autoexpire_cache_redis.rb +5 -3
  6. data/examples/reverse_geocode_job.rb +40 -0
  7. data/lib/generators/geocoder/config/templates/initializer.rb +17 -16
  8. data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +2 -0
  9. data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +2 -0
  10. data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +1 -1
  11. data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +1 -1
  12. data/lib/generators/geocoder/migration_version.rb +15 -0
  13. data/lib/geocoder/cache.rb +6 -2
  14. data/lib/geocoder/calculations.rb +30 -38
  15. data/lib/geocoder/cli.rb +2 -2
  16. data/lib/geocoder/configuration.rb +18 -5
  17. data/lib/geocoder/esri_token.rb +38 -0
  18. data/lib/geocoder/exceptions.rb +19 -0
  19. data/lib/geocoder/ip_address.rb +16 -11
  20. data/lib/geocoder/kernel_logger.rb +25 -0
  21. data/lib/geocoder/logger.rb +47 -0
  22. data/lib/geocoder/lookup.rb +31 -12
  23. data/lib/geocoder/lookups/amap.rb +63 -0
  24. data/lib/geocoder/lookups/baidu.rb +17 -9
  25. data/lib/geocoder/lookups/baidu_ip.rb +7 -31
  26. data/lib/geocoder/lookups/ban_data_gouv_fr.rb +143 -0
  27. data/lib/geocoder/lookups/base.rb +73 -25
  28. data/lib/geocoder/lookups/bing.rb +38 -15
  29. data/lib/geocoder/lookups/db_ip_com.rb +52 -0
  30. data/lib/geocoder/lookups/dstk.rb +4 -2
  31. data/lib/geocoder/lookups/esri.rb +55 -8
  32. data/lib/geocoder/lookups/freegeoip.rb +18 -5
  33. data/lib/geocoder/lookups/geocoder_ca.rb +5 -6
  34. data/lib/geocoder/lookups/geocodio.rb +8 -8
  35. data/lib/geocoder/lookups/geoip2.rb +10 -5
  36. data/lib/geocoder/lookups/geoportail_lu.rb +65 -0
  37. data/lib/geocoder/lookups/google.rb +37 -9
  38. data/lib/geocoder/lookups/google_places_details.rb +9 -9
  39. data/lib/geocoder/lookups/google_places_search.rb +33 -0
  40. data/lib/geocoder/lookups/google_premier.rb +11 -1
  41. data/lib/geocoder/lookups/here.rb +29 -23
  42. data/lib/geocoder/lookups/ip2location.rb +67 -0
  43. data/lib/geocoder/lookups/ipapi_com.rb +82 -0
  44. data/lib/geocoder/lookups/ipdata_co.rb +62 -0
  45. data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
  46. data/lib/geocoder/lookups/ipinfo_io.rb +44 -0
  47. data/lib/geocoder/lookups/ipregistry.rb +68 -0
  48. data/lib/geocoder/lookups/ipstack.rb +63 -0
  49. data/lib/geocoder/lookups/latlon.rb +59 -0
  50. data/lib/geocoder/lookups/location_iq.rb +50 -0
  51. data/lib/geocoder/lookups/mapbox.rb +59 -0
  52. data/lib/geocoder/lookups/mapquest.rb +7 -9
  53. data/lib/geocoder/lookups/maxmind.rb +7 -7
  54. data/lib/geocoder/lookups/maxmind_geoip2.rb +70 -0
  55. data/lib/geocoder/lookups/maxmind_local.rb +9 -2
  56. data/lib/geocoder/lookups/nominatim.rb +18 -6
  57. data/lib/geocoder/lookups/opencagedata.rb +16 -9
  58. data/lib/geocoder/lookups/osmnames.rb +57 -0
  59. data/lib/geocoder/lookups/pelias.rb +63 -0
  60. data/lib/geocoder/lookups/pickpoint.rb +41 -0
  61. data/lib/geocoder/lookups/pointpin.rb +14 -13
  62. data/lib/geocoder/lookups/postcode_anywhere_uk.rb +7 -8
  63. data/lib/geocoder/lookups/postcodes_io.rb +31 -0
  64. data/lib/geocoder/lookups/smarty_streets.rb +23 -5
  65. data/lib/geocoder/lookups/telize.rb +42 -7
  66. data/lib/geocoder/lookups/tencent.rb +59 -0
  67. data/lib/geocoder/lookups/yandex.rb +17 -9
  68. data/lib/geocoder/models/active_record.rb +4 -3
  69. data/lib/geocoder/models/mongo_base.rb +0 -2
  70. data/lib/geocoder/query.rb +15 -1
  71. data/lib/geocoder/railtie.rb +1 -1
  72. data/lib/geocoder/request.rb +103 -14
  73. data/lib/geocoder/results/amap.rb +87 -0
  74. data/lib/geocoder/results/baidu.rb +10 -14
  75. data/lib/geocoder/results/ban_data_gouv_fr.rb +257 -0
  76. data/lib/geocoder/results/base.rb +13 -1
  77. data/lib/geocoder/results/bing.rb +5 -1
  78. data/lib/geocoder/results/db_ip_com.rb +58 -0
  79. data/lib/geocoder/results/esri.rb +30 -6
  80. data/lib/geocoder/results/freegeoip.rb +2 -7
  81. data/lib/geocoder/results/geocoder_ca.rb +3 -3
  82. data/lib/geocoder/results/geocodio.rb +15 -3
  83. data/lib/geocoder/results/geoip2.rb +37 -25
  84. data/lib/geocoder/results/geoportail_lu.rb +71 -0
  85. data/lib/geocoder/results/google.rb +26 -0
  86. data/lib/geocoder/results/google_places_details.rb +4 -0
  87. data/lib/geocoder/results/google_places_search.rb +52 -0
  88. data/lib/geocoder/results/here.rb +21 -1
  89. data/lib/geocoder/results/ip2location.rb +22 -0
  90. data/lib/geocoder/results/ipapi_com.rb +45 -0
  91. data/lib/geocoder/results/ipdata_co.rb +40 -0
  92. data/lib/geocoder/results/ipgeolocation.rb +59 -0
  93. data/lib/geocoder/results/ipinfo_io.rb +48 -0
  94. data/lib/geocoder/results/ipregistry.rb +308 -0
  95. data/lib/geocoder/results/ipstack.rb +60 -0
  96. data/lib/geocoder/results/latlon.rb +71 -0
  97. data/lib/geocoder/results/location_iq.rb +6 -0
  98. data/lib/geocoder/results/mapbox.rb +57 -0
  99. data/lib/geocoder/results/mapquest.rb +5 -8
  100. data/lib/geocoder/results/maxmind.rb +0 -5
  101. data/lib/geocoder/results/maxmind_geoip2.rb +9 -0
  102. data/lib/geocoder/results/maxmind_local.rb +0 -5
  103. data/lib/geocoder/results/nominatim.rb +18 -3
  104. data/lib/geocoder/results/opencagedata.rb +20 -2
  105. data/lib/geocoder/results/osmnames.rb +56 -0
  106. data/lib/geocoder/results/pelias.rb +58 -0
  107. data/lib/geocoder/results/pickpoint.rb +6 -0
  108. data/lib/geocoder/results/pointpin.rb +0 -4
  109. data/lib/geocoder/results/postcodes_io.rb +40 -0
  110. data/lib/geocoder/results/smarty_streets.rb +55 -19
  111. data/lib/geocoder/results/telize.rb +0 -5
  112. data/lib/geocoder/results/tencent.rb +72 -0
  113. data/lib/geocoder/results/test.rb +1 -1
  114. data/lib/geocoder/results/yandex.rb +57 -7
  115. data/lib/geocoder/sql.rb +9 -6
  116. data/lib/geocoder/stores/active_record.rb +49 -10
  117. data/lib/geocoder/stores/base.rb +2 -14
  118. data/lib/geocoder/stores/mongo_base.rb +0 -31
  119. data/lib/geocoder/version.rb +1 -1
  120. data/lib/geocoder.rb +2 -1
  121. data/lib/hash_recursive_merge.rb +1 -2
  122. data/lib/maxmind_database.rb +4 -4
  123. data/lib/tasks/geocoder.rake +29 -4
  124. metadata +56 -159
  125. data/.gitignore +0 -6
  126. data/.travis.yml +0 -31
  127. data/Rakefile +0 -25
  128. data/gemfiles/Gemfile.mongoid-2.4.x +0 -16
  129. data/lib/geocoder/lookups/geocoder_us.rb +0 -39
  130. data/lib/geocoder/lookups/okf.rb +0 -43
  131. data/lib/geocoder/lookups/ovi.rb +0 -62
  132. data/lib/geocoder/lookups/yahoo.rb +0 -88
  133. data/lib/geocoder/results/geocoder_us.rb +0 -39
  134. data/lib/geocoder/results/okf.rb +0 -106
  135. data/lib/geocoder/results/ovi.rb +0 -62
  136. data/lib/geocoder/results/yahoo.rb +0 -55
  137. data/lib/oauth_util.rb +0 -112
  138. data/test/fixtures/baidu_invalid_key +0 -1
  139. data/test/fixtures/baidu_ip_202_198_16_3 +0 -19
  140. data/test/fixtures/baidu_ip_invalid_key +0 -1
  141. data/test/fixtures/baidu_ip_no_results +0 -1
  142. data/test/fixtures/baidu_no_results +0 -1
  143. data/test/fixtures/baidu_reverse +0 -1
  144. data/test/fixtures/baidu_shanghai_pearl_tower +0 -12
  145. data/test/fixtures/bing_invalid_key +0 -1
  146. data/test/fixtures/bing_madison_square_garden +0 -40
  147. data/test/fixtures/bing_no_results +0 -16
  148. data/test/fixtures/bing_reverse +0 -42
  149. data/test/fixtures/cloudmade_invalid_key +0 -1
  150. data/test/fixtures/cloudmade_madison_square_garden +0 -1
  151. data/test/fixtures/cloudmade_no_results +0 -1
  152. data/test/fixtures/esri_madison_square_garden +0 -59
  153. data/test/fixtures/esri_no_results +0 -8
  154. data/test/fixtures/esri_reverse +0 -21
  155. data/test/fixtures/freegeoip_74_200_247_59 +0 -12
  156. data/test/fixtures/freegeoip_no_results +0 -1
  157. data/test/fixtures/geocoder_ca_madison_square_garden +0 -1
  158. data/test/fixtures/geocoder_ca_no_results +0 -1
  159. data/test/fixtures/geocoder_ca_reverse +0 -34
  160. data/test/fixtures/geocoder_us_madison_square_garden +0 -1
  161. data/test/fixtures/geocoder_us_no_results +0 -1
  162. data/test/fixtures/geocodio_1101_pennsylvania_ave +0 -1
  163. data/test/fixtures/geocodio_bad_api_key +0 -3
  164. data/test/fixtures/geocodio_invalid +0 -4
  165. data/test/fixtures/geocodio_no_results +0 -1
  166. data/test/fixtures/geocodio_over_query_limit +0 -4
  167. data/test/fixtures/google_garbage +0 -456
  168. data/test/fixtures/google_madison_square_garden +0 -57
  169. data/test/fixtures/google_no_city_data +0 -44
  170. data/test/fixtures/google_no_locality +0 -51
  171. data/test/fixtures/google_no_results +0 -4
  172. data/test/fixtures/google_over_limit +0 -4
  173. data/test/fixtures/google_places_details_invalid_request +0 -4
  174. data/test/fixtures/google_places_details_madison_square_garden +0 -120
  175. data/test/fixtures/google_places_details_no_results +0 -4
  176. data/test/fixtures/google_places_details_no_reviews +0 -60
  177. data/test/fixtures/google_places_details_no_types +0 -66
  178. data/test/fixtures/here_madison_square_garden +0 -72
  179. data/test/fixtures/here_no_results +0 -8
  180. data/test/fixtures/mapquest_error +0 -16
  181. data/test/fixtures/mapquest_invalid_api_key +0 -16
  182. data/test/fixtures/mapquest_invalid_request +0 -16
  183. data/test/fixtures/mapquest_madison_square_garden +0 -52
  184. data/test/fixtures/mapquest_no_results +0 -16
  185. data/test/fixtures/maxmind_24_24_24_21 +0 -1
  186. data/test/fixtures/maxmind_24_24_24_22 +0 -1
  187. data/test/fixtures/maxmind_24_24_24_23 +0 -1
  188. data/test/fixtures/maxmind_24_24_24_24 +0 -1
  189. data/test/fixtures/maxmind_74_200_247_59 +0 -1
  190. data/test/fixtures/maxmind_invalid_key +0 -1
  191. data/test/fixtures/maxmind_no_results +0 -1
  192. data/test/fixtures/nominatim_madison_square_garden +0 -150
  193. data/test/fixtures/nominatim_no_results +0 -1
  194. data/test/fixtures/nominatim_over_limit +0 -1
  195. data/test/fixtures/okf_kirstinmaki +0 -67
  196. data/test/fixtures/okf_no_results +0 -4
  197. data/test/fixtures/opencagedata_invalid_api_key +0 -25
  198. data/test/fixtures/opencagedata_invalid_request +0 -26
  199. data/test/fixtures/opencagedata_madison_square_garden +0 -73
  200. data/test/fixtures/opencagedata_no_results +0 -29
  201. data/test/fixtures/opencagedata_over_limit +0 -31
  202. data/test/fixtures/ovi_madison_square_garden +0 -72
  203. data/test/fixtures/ovi_no_results +0 -8
  204. data/test/fixtures/pointpin_10_10_10_10 +0 -1
  205. data/test/fixtures/pointpin_555_555_555_555 +0 -1
  206. data/test/fixtures/pointpin_80_111_555_555 +0 -1
  207. data/test/fixtures/pointpin_no_results +0 -1
  208. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_WR26NJ +0 -1
  209. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_generic_error +0 -1
  210. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_hampshire +0 -1
  211. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_key_limit_exceeded +0 -1
  212. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_no_results +0 -1
  213. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_romsey +0 -1
  214. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_unknown_key +0 -1
  215. data/test/fixtures/smarty_streets_11211 +0 -1
  216. data/test/fixtures/smarty_streets_madison_square_garden +0 -47
  217. data/test/fixtures/smarty_streets_no_results +0 -1
  218. data/test/fixtures/telize_10_10_10_10 +0 -1
  219. data/test/fixtures/telize_555_555_555_555 +0 -4
  220. data/test/fixtures/telize_74_200_247_59 +0 -1
  221. data/test/fixtures/telize_no_results +0 -1
  222. data/test/fixtures/yahoo_error +0 -1
  223. data/test/fixtures/yahoo_invalid_key +0 -2
  224. data/test/fixtures/yahoo_madison_square_garden +0 -52
  225. data/test/fixtures/yahoo_no_results +0 -10
  226. data/test/fixtures/yahoo_over_limit +0 -2
  227. data/test/fixtures/yandex_canada_rue_dupuis_14 +0 -446
  228. data/test/fixtures/yandex_invalid_key +0 -1
  229. data/test/fixtures/yandex_kremlin +0 -48
  230. data/test/fixtures/yandex_new_york +0 -1
  231. data/test/fixtures/yandex_no_city_and_town +0 -112
  232. data/test/fixtures/yandex_no_results +0 -16
  233. data/test/integration/http_client_test.rb +0 -31
  234. data/test/mongoid_test_helper.rb +0 -43
  235. data/test/test_helper.rb +0 -416
  236. data/test/unit/active_record_test.rb +0 -16
  237. data/test/unit/cache_test.rb +0 -37
  238. data/test/unit/calculations_test.rb +0 -220
  239. data/test/unit/configuration_test.rb +0 -55
  240. data/test/unit/error_handling_test.rb +0 -56
  241. data/test/unit/geocoder_test.rb +0 -78
  242. data/test/unit/https_test.rb +0 -17
  243. data/test/unit/ip_address_test.rb +0 -27
  244. data/test/unit/lookup_test.rb +0 -153
  245. data/test/unit/lookups/bing_test.rb +0 -68
  246. data/test/unit/lookups/dstk_test.rb +0 -26
  247. data/test/unit/lookups/esri_test.rb +0 -48
  248. data/test/unit/lookups/freegeoip_test.rb +0 -27
  249. data/test/unit/lookups/geocoder_ca_test.rb +0 -17
  250. data/test/unit/lookups/geocodio_test.rb +0 -55
  251. data/test/unit/lookups/geoip2_test.rb +0 -27
  252. data/test/unit/lookups/google_places_details_test.rb +0 -122
  253. data/test/unit/lookups/google_premier_test.rb +0 -22
  254. data/test/unit/lookups/google_test.rb +0 -84
  255. data/test/unit/lookups/mapquest_test.rb +0 -60
  256. data/test/unit/lookups/maxmind_local_test.rb +0 -28
  257. data/test/unit/lookups/maxmind_test.rb +0 -63
  258. data/test/unit/lookups/nominatim_test.rb +0 -31
  259. data/test/unit/lookups/okf_test.rb +0 -38
  260. data/test/unit/lookups/opencagedata_test.rb +0 -64
  261. data/test/unit/lookups/pointpin_test.rb +0 -30
  262. data/test/unit/lookups/postcode_anywhere_uk_test.rb +0 -70
  263. data/test/unit/lookups/smarty_streets_test.rb +0 -71
  264. data/test/unit/lookups/telize_test.rb +0 -36
  265. data/test/unit/lookups/yahoo_test.rb +0 -35
  266. data/test/unit/method_aliases_test.rb +0 -26
  267. data/test/unit/model_test.rb +0 -38
  268. data/test/unit/mongoid_test.rb +0 -47
  269. data/test/unit/near_test.rb +0 -87
  270. data/test/unit/oauth_util_test.rb +0 -31
  271. data/test/unit/proxy_test.rb +0 -37
  272. data/test/unit/query_test.rb +0 -52
  273. data/test/unit/rake_task_test.rb +0 -21
  274. data/test/unit/request_test.rb +0 -35
  275. data/test/unit/result_test.rb +0 -72
  276. data/test/unit/test_mode_test.rb +0 -70
@@ -0,0 +1,48 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class IpinfoIo < Base
5
+
6
+ def address(format = :full)
7
+ "#{city} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
8
+ end
9
+
10
+ def coordinates
11
+ @data['loc'].to_s.split(",").map(&:to_f)
12
+ end
13
+
14
+ def city
15
+ @data['city']
16
+ end
17
+
18
+ def state
19
+ @data['region']
20
+ end
21
+
22
+ def country
23
+ @data['country']
24
+ end
25
+
26
+ def postal_code
27
+ @data['postal']
28
+ end
29
+
30
+ def country_code
31
+ @data.fetch('country', '')
32
+ end
33
+
34
+ def state_code
35
+ @data.fetch('region_code', '')
36
+ end
37
+
38
+ def self.response_attributes
39
+ %w(ip region postal)
40
+ end
41
+
42
+ response_attributes.each do |a|
43
+ define_method a do
44
+ @data[a]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -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
@@ -0,0 +1,71 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Latlon < Base
5
+
6
+ def city
7
+ address_components["city"]
8
+ end
9
+
10
+ def coordinates
11
+ [@data['lat'].to_f, @data['lon'].to_f]
12
+ end
13
+
14
+ def country
15
+ "United States" # LatLon.io only supports the US
16
+ end
17
+
18
+ def country_code
19
+ "US" # LatLon.io only supports the US
20
+ end
21
+
22
+ def formatted_address(format = :full)
23
+ address_components["address"]
24
+ end
25
+ alias_method :address, :formatted_address
26
+
27
+ def number
28
+ address_components["number"]
29
+ end
30
+
31
+ def prefix
32
+ address_components["prefix"]
33
+ end
34
+
35
+ def state
36
+ address_components["state"]
37
+ end
38
+ alias_method :state_code, :state
39
+
40
+ def street
41
+ [street_name, street_type].compact.join(' ')
42
+ end
43
+
44
+ def street_name
45
+ address_components["street_name"]
46
+ end
47
+
48
+ def street_type
49
+ address_components["street_type"]
50
+ end
51
+
52
+ def suffix
53
+ address_components["suffix"]
54
+ end
55
+
56
+ def unit
57
+ address_components["unit"]
58
+ end
59
+
60
+ def zip
61
+ address_components["zip"]
62
+ end
63
+ alias_method :postal_code, :zip
64
+
65
+ private
66
+
67
+ def address_components
68
+ @data["address"] || {}
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,6 @@
1
+ require 'geocoder/results/nominatim'
2
+
3
+ module Geocoder::Result
4
+ class LocationIq < Nominatim
5
+ end
6
+ end
@@ -0,0 +1,57 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Mapbox < Base
5
+
6
+ def coordinates
7
+ data['geometry']['coordinates'].reverse.map(&:to_f)
8
+ end
9
+
10
+ def place_name
11
+ data['text']
12
+ end
13
+
14
+ def street
15
+ data['properties']['address']
16
+ end
17
+
18
+ def city
19
+ context_part('place')
20
+ end
21
+
22
+ def state
23
+ context_part('region')
24
+ end
25
+
26
+ alias_method :state_code, :state
27
+
28
+ def postal_code
29
+ context_part('postcode')
30
+ end
31
+
32
+ def country
33
+ context_part('country')
34
+ end
35
+
36
+ alias_method :country_code, :country
37
+
38
+ def neighborhood
39
+ context_part('neighborhood')
40
+ end
41
+
42
+ def address
43
+ [place_name, street, city, state, postal_code, country].compact.join(', ')
44
+ end
45
+
46
+ private
47
+
48
+ def context_part(name)
49
+ context.map { |c| c['text'] if c['id'] =~ Regexp.new(name) }.compact.first
50
+ end
51
+
52
+ def context
53
+ Array(data['context'])
54
+ end
55
+ end
56
+ end
57
+
@@ -2,16 +2,9 @@ require 'geocoder/results/base'
2
2
 
3
3
  module Geocoder::Result
4
4
  class Mapquest < Base
5
- def latitude
6
- @data["latLng"]["lat"]
7
- end
8
-
9
- def longitude
10
- @data["latLng"]["lng"]
11
- end
12
5
 
13
6
  def coordinates
14
- [latitude, longitude]
7
+ %w[lat lng].map{ |l| @data["latLng"][l] }
15
8
  end
16
9
 
17
10
  def city
@@ -26,6 +19,10 @@ module Geocoder::Result
26
19
  @data['adminArea3']
27
20
  end
28
21
 
22
+ def county
23
+ @data['adminArea4']
24
+ end
25
+
29
26
  alias_method :state_code, :state
30
27
 
31
28
  #FIXME: these might not be right, unclear with MQ documentation
@@ -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
@@ -0,0 +1,9 @@
1
+ require 'geocoder/results/geoip2'
2
+
3
+ module Geocoder::Result
4
+ class MaxmindGeoip2 < Geoip2
5
+ # MindmindGeoip2 has the same results as Geoip2 because both are from MaxMind's GeoIP2 Precision Services
6
+ # See http://dev.maxmind.com/geoip/geoip2/web-services/ The difference being that Maxmind calls the service
7
+ # directly while GeoIP2 uses Hive::GeoIP2. See https://github.com/desuwa/hive_geoip2
8
+ end
9
+ 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
@@ -4,9 +4,7 @@ module Geocoder::Result
4
4
  class Nominatim < Base
5
5
 
6
6
  def poi
7
- %w[stadium bus_stop tram_stop].each do |key|
8
- return @data['address'][key] if @data['address'].key?(key)
9
- end
7
+ return @data['address'][place_type] if @data['address'].key?(place_type)
10
8
  return nil
11
9
  end
12
10
 
@@ -66,6 +64,18 @@ module Geocoder::Result
66
64
  @data['address']['suburb']
67
65
  end
68
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
+
69
79
  def coordinates
70
80
  [@data['lat'].to_f, @data['lon'].to_f]
71
81
  end
@@ -78,6 +88,11 @@ module Geocoder::Result
78
88
  @data['type']
79
89
  end
80
90
 
91
+ def viewport
92
+ south, north, west, east = @data['boundingbox'].map(&:to_f)
93
+ [south, west, north, east]
94
+ end
95
+
81
96
  def self.response_attributes
82
97
  %w[place_id osm_type osm_id boundingbox license
83
98
  polygonpoints display_name class type stadium]
@@ -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
- alias_method :state_code, :state
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
@@ -66,6 +67,23 @@ module Geocoder::Result
66
67
  def coordinates
67
68
  [@data['geometry']['lat'].to_f, @data['geometry']['lng'].to_f]
68
69
  end
70
+
71
+ def viewport
72
+ bounds = @data['bounds'] || fail
73
+ south, west = %w(lat lng).map { |i| bounds['southwest'][i] }
74
+ north, east = %w(lat lng).map { |i| bounds['northeast'][i] }
75
+ [south, west, north, east]
76
+ end
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
+
69
87
  def self.response_attributes
70
88
  %w[boundingbox license
71
89
  formatted stadium]