geocoder-kb 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (248) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.travis.yml +31 -0
  4. data/CHANGELOG.md +384 -0
  5. data/LICENSE +20 -0
  6. data/README.md +1085 -0
  7. data/Rakefile +25 -0
  8. data/bin/geocode +5 -0
  9. data/examples/autoexpire_cache_dalli.rb +62 -0
  10. data/examples/autoexpire_cache_redis.rb +28 -0
  11. data/examples/cache_bypass.rb +48 -0
  12. data/examples/sidekiq_worker.rb +16 -0
  13. data/gemfiles/Gemfile.mongoid-2.4.x +16 -0
  14. data/lib/generators/geocoder/config/config_generator.rb +14 -0
  15. data/lib/generators/geocoder/config/templates/initializer.rb +21 -0
  16. data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +28 -0
  17. data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +28 -0
  18. data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +30 -0
  19. data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +17 -0
  20. data/lib/geocoder.rb +47 -0
  21. data/lib/geocoder/cache.rb +90 -0
  22. data/lib/geocoder/calculations.rb +428 -0
  23. data/lib/geocoder/cli.rb +121 -0
  24. data/lib/geocoder/configuration.rb +124 -0
  25. data/lib/geocoder/configuration_hash.rb +11 -0
  26. data/lib/geocoder/exceptions.rb +21 -0
  27. data/lib/geocoder/ip_address.rb +21 -0
  28. data/lib/geocoder/lookup.rb +102 -0
  29. data/lib/geocoder/lookups/amap.rb +55 -0
  30. data/lib/geocoder/lookups/baidu.rb +55 -0
  31. data/lib/geocoder/lookups/baidu_ip.rb +54 -0
  32. data/lib/geocoder/lookups/base.rb +302 -0
  33. data/lib/geocoder/lookups/bing.rb +59 -0
  34. data/lib/geocoder/lookups/dstk.rb +20 -0
  35. data/lib/geocoder/lookups/esri.rb +48 -0
  36. data/lib/geocoder/lookups/freegeoip.rb +47 -0
  37. data/lib/geocoder/lookups/geocoder_ca.rb +54 -0
  38. data/lib/geocoder/lookups/geocoder_us.rb +39 -0
  39. data/lib/geocoder/lookups/geocodio.rb +42 -0
  40. data/lib/geocoder/lookups/geoip2.rb +40 -0
  41. data/lib/geocoder/lookups/google.rb +67 -0
  42. data/lib/geocoder/lookups/google_places_details.rb +50 -0
  43. data/lib/geocoder/lookups/google_premier.rb +47 -0
  44. data/lib/geocoder/lookups/here.rb +62 -0
  45. data/lib/geocoder/lookups/mapquest.rb +60 -0
  46. data/lib/geocoder/lookups/maxmind.rb +90 -0
  47. data/lib/geocoder/lookups/maxmind_local.rb +58 -0
  48. data/lib/geocoder/lookups/nominatim.rb +52 -0
  49. data/lib/geocoder/lookups/okf.rb +43 -0
  50. data/lib/geocoder/lookups/opencagedata.rb +58 -0
  51. data/lib/geocoder/lookups/ovi.rb +62 -0
  52. data/lib/geocoder/lookups/pointpin.rb +68 -0
  53. data/lib/geocoder/lookups/postcode_anywhere_uk.rb +51 -0
  54. data/lib/geocoder/lookups/smarty_streets.rb +45 -0
  55. data/lib/geocoder/lookups/telize.rb +40 -0
  56. data/lib/geocoder/lookups/test.rb +44 -0
  57. data/lib/geocoder/lookups/yahoo.rb +88 -0
  58. data/lib/geocoder/lookups/yandex.rb +54 -0
  59. data/lib/geocoder/models/active_record.rb +50 -0
  60. data/lib/geocoder/models/base.rb +39 -0
  61. data/lib/geocoder/models/mongo_base.rb +64 -0
  62. data/lib/geocoder/models/mongo_mapper.rb +26 -0
  63. data/lib/geocoder/models/mongoid.rb +32 -0
  64. data/lib/geocoder/query.rb +111 -0
  65. data/lib/geocoder/railtie.rb +26 -0
  66. data/lib/geocoder/request.rb +25 -0
  67. data/lib/geocoder/results/amap.rb +85 -0
  68. data/lib/geocoder/results/baidu.rb +79 -0
  69. data/lib/geocoder/results/baidu_ip.rb +62 -0
  70. data/lib/geocoder/results/base.rb +67 -0
  71. data/lib/geocoder/results/bing.rb +48 -0
  72. data/lib/geocoder/results/dstk.rb +6 -0
  73. data/lib/geocoder/results/esri.rb +51 -0
  74. data/lib/geocoder/results/freegeoip.rb +45 -0
  75. data/lib/geocoder/results/geocoder_ca.rb +60 -0
  76. data/lib/geocoder/results/geocoder_us.rb +39 -0
  77. data/lib/geocoder/results/geocodio.rb +66 -0
  78. data/lib/geocoder/results/geoip2.rb +64 -0
  79. data/lib/geocoder/results/google.rb +124 -0
  80. data/lib/geocoder/results/google_places_details.rb +35 -0
  81. data/lib/geocoder/results/google_premier.rb +6 -0
  82. data/lib/geocoder/results/here.rb +62 -0
  83. data/lib/geocoder/results/mapquest.rb +51 -0
  84. data/lib/geocoder/results/maxmind.rb +135 -0
  85. data/lib/geocoder/results/maxmind_local.rb +49 -0
  86. data/lib/geocoder/results/nominatim.rb +94 -0
  87. data/lib/geocoder/results/okf.rb +106 -0
  88. data/lib/geocoder/results/opencagedata.rb +82 -0
  89. data/lib/geocoder/results/ovi.rb +62 -0
  90. data/lib/geocoder/results/pointpin.rb +44 -0
  91. data/lib/geocoder/results/postcode_anywhere_uk.rb +42 -0
  92. data/lib/geocoder/results/smarty_streets.rb +106 -0
  93. data/lib/geocoder/results/telize.rb +45 -0
  94. data/lib/geocoder/results/test.rb +33 -0
  95. data/lib/geocoder/results/yahoo.rb +55 -0
  96. data/lib/geocoder/results/yandex.rb +84 -0
  97. data/lib/geocoder/sql.rb +107 -0
  98. data/lib/geocoder/stores/active_record.rb +289 -0
  99. data/lib/geocoder/stores/base.rb +127 -0
  100. data/lib/geocoder/stores/mongo_base.rb +89 -0
  101. data/lib/geocoder/stores/mongo_mapper.rb +13 -0
  102. data/lib/geocoder/stores/mongoid.rb +13 -0
  103. data/lib/geocoder/version.rb +3 -0
  104. data/lib/hash_recursive_merge.rb +74 -0
  105. data/lib/maxmind_database.rb +109 -0
  106. data/lib/oauth_util.rb +112 -0
  107. data/lib/tasks/geocoder.rake +29 -0
  108. data/lib/tasks/maxmind.rake +73 -0
  109. data/test/fixtures/baidu_invalid_key +1 -0
  110. data/test/fixtures/baidu_ip_202_198_16_3 +19 -0
  111. data/test/fixtures/baidu_ip_invalid_key +1 -0
  112. data/test/fixtures/baidu_ip_no_results +1 -0
  113. data/test/fixtures/baidu_no_results +1 -0
  114. data/test/fixtures/baidu_reverse +1 -0
  115. data/test/fixtures/baidu_shanghai_pearl_tower +12 -0
  116. data/test/fixtures/bing_invalid_key +1 -0
  117. data/test/fixtures/bing_madison_square_garden +40 -0
  118. data/test/fixtures/bing_no_results +16 -0
  119. data/test/fixtures/bing_reverse +42 -0
  120. data/test/fixtures/cloudmade_invalid_key +1 -0
  121. data/test/fixtures/cloudmade_madison_square_garden +1 -0
  122. data/test/fixtures/cloudmade_no_results +1 -0
  123. data/test/fixtures/esri_madison_square_garden +59 -0
  124. data/test/fixtures/esri_no_results +8 -0
  125. data/test/fixtures/esri_reverse +21 -0
  126. data/test/fixtures/freegeoip_74_200_247_59 +12 -0
  127. data/test/fixtures/freegeoip_no_results +1 -0
  128. data/test/fixtures/geocoder_ca_madison_square_garden +1 -0
  129. data/test/fixtures/geocoder_ca_no_results +1 -0
  130. data/test/fixtures/geocoder_ca_reverse +34 -0
  131. data/test/fixtures/geocoder_us_madison_square_garden +1 -0
  132. data/test/fixtures/geocoder_us_no_results +1 -0
  133. data/test/fixtures/geocodio_1101_pennsylvania_ave +1 -0
  134. data/test/fixtures/geocodio_bad_api_key +3 -0
  135. data/test/fixtures/geocodio_invalid +4 -0
  136. data/test/fixtures/geocodio_no_results +1 -0
  137. data/test/fixtures/geocodio_over_query_limit +4 -0
  138. data/test/fixtures/google_garbage +456 -0
  139. data/test/fixtures/google_madison_square_garden +57 -0
  140. data/test/fixtures/google_no_city_data +44 -0
  141. data/test/fixtures/google_no_locality +51 -0
  142. data/test/fixtures/google_no_results +4 -0
  143. data/test/fixtures/google_over_limit +4 -0
  144. data/test/fixtures/google_places_details_invalid_request +4 -0
  145. data/test/fixtures/google_places_details_madison_square_garden +120 -0
  146. data/test/fixtures/google_places_details_no_results +4 -0
  147. data/test/fixtures/google_places_details_no_reviews +60 -0
  148. data/test/fixtures/google_places_details_no_types +66 -0
  149. data/test/fixtures/here_madison_square_garden +72 -0
  150. data/test/fixtures/here_no_results +8 -0
  151. data/test/fixtures/mapquest_error +16 -0
  152. data/test/fixtures/mapquest_invalid_api_key +16 -0
  153. data/test/fixtures/mapquest_invalid_request +16 -0
  154. data/test/fixtures/mapquest_madison_square_garden +52 -0
  155. data/test/fixtures/mapquest_no_results +16 -0
  156. data/test/fixtures/maxmind_24_24_24_21 +1 -0
  157. data/test/fixtures/maxmind_24_24_24_22 +1 -0
  158. data/test/fixtures/maxmind_24_24_24_23 +1 -0
  159. data/test/fixtures/maxmind_24_24_24_24 +1 -0
  160. data/test/fixtures/maxmind_74_200_247_59 +1 -0
  161. data/test/fixtures/maxmind_invalid_key +1 -0
  162. data/test/fixtures/maxmind_no_results +1 -0
  163. data/test/fixtures/nominatim_madison_square_garden +150 -0
  164. data/test/fixtures/nominatim_no_results +1 -0
  165. data/test/fixtures/nominatim_over_limit +1 -0
  166. data/test/fixtures/okf_kirstinmaki +67 -0
  167. data/test/fixtures/okf_no_results +4 -0
  168. data/test/fixtures/opencagedata_invalid_api_key +25 -0
  169. data/test/fixtures/opencagedata_invalid_request +26 -0
  170. data/test/fixtures/opencagedata_madison_square_garden +73 -0
  171. data/test/fixtures/opencagedata_no_results +29 -0
  172. data/test/fixtures/opencagedata_over_limit +31 -0
  173. data/test/fixtures/ovi_madison_square_garden +72 -0
  174. data/test/fixtures/ovi_no_results +8 -0
  175. data/test/fixtures/pointpin_10_10_10_10 +1 -0
  176. data/test/fixtures/pointpin_555_555_555_555 +1 -0
  177. data/test/fixtures/pointpin_80_111_555_555 +1 -0
  178. data/test/fixtures/pointpin_no_results +1 -0
  179. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_WR26NJ +1 -0
  180. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_generic_error +1 -0
  181. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_hampshire +1 -0
  182. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_key_limit_exceeded +1 -0
  183. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_no_results +1 -0
  184. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_romsey +1 -0
  185. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_unknown_key +1 -0
  186. data/test/fixtures/smarty_streets_11211 +1 -0
  187. data/test/fixtures/smarty_streets_madison_square_garden +47 -0
  188. data/test/fixtures/smarty_streets_no_results +1 -0
  189. data/test/fixtures/telize_10_10_10_10 +1 -0
  190. data/test/fixtures/telize_555_555_555_555 +4 -0
  191. data/test/fixtures/telize_74_200_247_59 +1 -0
  192. data/test/fixtures/telize_no_results +1 -0
  193. data/test/fixtures/yahoo_error +1 -0
  194. data/test/fixtures/yahoo_invalid_key +2 -0
  195. data/test/fixtures/yahoo_madison_square_garden +52 -0
  196. data/test/fixtures/yahoo_no_results +10 -0
  197. data/test/fixtures/yahoo_over_limit +2 -0
  198. data/test/fixtures/yandex_canada_rue_dupuis_14 +446 -0
  199. data/test/fixtures/yandex_invalid_key +1 -0
  200. data/test/fixtures/yandex_kremlin +48 -0
  201. data/test/fixtures/yandex_new_york +1 -0
  202. data/test/fixtures/yandex_no_city_and_town +112 -0
  203. data/test/fixtures/yandex_no_results +16 -0
  204. data/test/integration/http_client_test.rb +31 -0
  205. data/test/mongoid_test_helper.rb +43 -0
  206. data/test/test_helper.rb +416 -0
  207. data/test/unit/active_record_test.rb +16 -0
  208. data/test/unit/cache_test.rb +37 -0
  209. data/test/unit/calculations_test.rb +220 -0
  210. data/test/unit/configuration_test.rb +55 -0
  211. data/test/unit/error_handling_test.rb +56 -0
  212. data/test/unit/geocoder_test.rb +78 -0
  213. data/test/unit/https_test.rb +17 -0
  214. data/test/unit/ip_address_test.rb +27 -0
  215. data/test/unit/lookup_test.rb +153 -0
  216. data/test/unit/lookups/bing_test.rb +68 -0
  217. data/test/unit/lookups/dstk_test.rb +26 -0
  218. data/test/unit/lookups/esri_test.rb +48 -0
  219. data/test/unit/lookups/freegeoip_test.rb +27 -0
  220. data/test/unit/lookups/geocoder_ca_test.rb +17 -0
  221. data/test/unit/lookups/geocodio_test.rb +55 -0
  222. data/test/unit/lookups/geoip2_test.rb +27 -0
  223. data/test/unit/lookups/google_places_details_test.rb +122 -0
  224. data/test/unit/lookups/google_premier_test.rb +22 -0
  225. data/test/unit/lookups/google_test.rb +84 -0
  226. data/test/unit/lookups/mapquest_test.rb +60 -0
  227. data/test/unit/lookups/maxmind_local_test.rb +28 -0
  228. data/test/unit/lookups/maxmind_test.rb +63 -0
  229. data/test/unit/lookups/nominatim_test.rb +31 -0
  230. data/test/unit/lookups/okf_test.rb +38 -0
  231. data/test/unit/lookups/opencagedata_test.rb +64 -0
  232. data/test/unit/lookups/pointpin_test.rb +30 -0
  233. data/test/unit/lookups/postcode_anywhere_uk_test.rb +70 -0
  234. data/test/unit/lookups/smarty_streets_test.rb +71 -0
  235. data/test/unit/lookups/telize_test.rb +36 -0
  236. data/test/unit/lookups/yahoo_test.rb +35 -0
  237. data/test/unit/method_aliases_test.rb +26 -0
  238. data/test/unit/model_test.rb +38 -0
  239. data/test/unit/mongoid_test.rb +47 -0
  240. data/test/unit/near_test.rb +87 -0
  241. data/test/unit/oauth_util_test.rb +31 -0
  242. data/test/unit/proxy_test.rb +37 -0
  243. data/test/unit/query_test.rb +52 -0
  244. data/test/unit/rake_task_test.rb +21 -0
  245. data/test/unit/request_test.rb +35 -0
  246. data/test/unit/result_test.rb +72 -0
  247. data/test/unit/test_mode_test.rb +70 -0
  248. metadata +294 -0
@@ -0,0 +1 @@
1
+ {"error":{"status":401,"message":"invalid key"}}
@@ -0,0 +1,48 @@
1
+ {
2
+ "response": {
3
+ "GeoObjectCollection": {
4
+ "metaDataProperty": {
5
+ "GeocoderResponseMetaData": {
6
+ "request": "Кремль, Moscow, Russia",
7
+ "found": "1",
8
+ "results": "10"
9
+ }
10
+ },
11
+ "featureMember": [
12
+ {
13
+ "GeoObject": {
14
+ "metaDataProperty": {
15
+ "GeocoderMetaData": {
16
+ "kind": "vegetation",
17
+ "text": "Россия, Москва, Московский Кремль",
18
+ "precision": "other",
19
+ "AddressDetails": {
20
+ "Country": {
21
+ "CountryNameCode": "RU",
22
+ "CountryName": "Россия",
23
+ "Locality": {
24
+ "LocalityName": "Москва",
25
+ "Premise": {
26
+ "PremiseName": "Московский Кремль"
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ },
33
+ "name": "Московский Кремль",
34
+ "boundedBy": {
35
+ "Envelope": {
36
+ "lowerCorner": "37.584182 55.733361",
37
+ "upperCorner": "37.650064 55.770517"
38
+ }
39
+ },
40
+ "Point": {
41
+ "pos": "37.617123 55.751943"
42
+ }
43
+ }
44
+ }
45
+ ]
46
+ }
47
+ }
48
+ }
@@ -0,0 +1 @@
1
+ {"response":{"Attribution":"","GeoObjectCollection":{"metaDataProperty":{"GeocoderResponseMetaData":{"request":"New York, NY","found":"21","results":"10"}},"featureMember":[{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"province","text":"United States, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New York"}}}}},"description":"United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-79.762115 40.477414","upperCorner":"-71.668635 45.016078"}},"Point":{"pos":"-74.007112 40.714545"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, New York, Bronx, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New York, Bronx, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New York","SubAdministrativeArea":{"SubAdministrativeAreaName":"Bronx","Locality":{"LocalityName":"New York"}}}}}}},"description":"Bronx, New York, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-74.258892 40.477414","upperCorner":"-73.700373 40.917616"}},"Point":{"pos":"-74.007112 40.714545"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"hydro","text":"United States, Upper New York Bay","precision":"other","AddressDetails":{"Country":{"AddressLine":"Upper New York Bay","CountryNameCode":"US","CountryName":"United States","Locality":{"Premise":{"PremiseName":"Upper New York Bay"}}}}}},"description":"United States","name":"Upper New York Bay","boundedBy":{"Envelope":{"lowerCorner":"-74.107633 40.604124","upperCorner":"-73.998434 40.706697"}},"Point":{"pos":"-74.048758 40.660893"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, New Jersey, Hudson, West New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New Jersey, Hudson, West New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New Jersey","SubAdministrativeArea":{"SubAdministrativeAreaName":"Hudson","Locality":{"LocalityName":"West New York"}}}}}}},"description":"Hudson, New Jersey, United States","name":"West New York","boundedBy":{"Envelope":{"lowerCorner":"-74.023569 40.7746","upperCorner":"-73.992936 40.796565"}},"Point":{"pos":"-74.015260 40.788325"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United Kingdom of Great Britain and Northern Ireland, England, Lincolnshire, East Lindsey, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"England, Lincolnshire, East Lindsey, New York","CountryNameCode":"GB","CountryName":"United Kingdom of Great Britain and Northern Ireland","AdministrativeArea":{"AdministrativeAreaName":"England","SubAdministrativeArea":{"SubAdministrativeAreaName":"Lincolnshire","Locality":{"LocalityName":"New York"}}}}}}},"description":"East Lindsey, Lincolnshire, England, United Kingdom of Great Britain and Northern Ireland","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-0.205993 53.039103","upperCorner":"-0.074192 53.11847"}},"Point":{"pos":"-0.140092 53.078805"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"South Africa, North West, Bophirima, Naledi, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"North West, Bophirima, Naledi, New York","CountryNameCode":"ZA","CountryName":"South Africa","AdministrativeArea":{"AdministrativeAreaName":"North West","SubAdministrativeArea":{"SubAdministrativeAreaName":"Bophirima","Locality":{"LocalityName":"New York"}}}}}}},"description":"Naledi, Bophirima, North West, South Africa","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"24.454037 -26.943742","upperCorner":"24.585838 -26.825556"}},"Point":{"pos":"24.519938 -26.884665"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, New Mexico, Cibola, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New Mexico, Cibola, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New Mexico","SubAdministrativeArea":{"SubAdministrativeAreaName":"Cibola","Locality":{"LocalityName":"New York"}}}}}}},"description":"Cibola, New Mexico, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-107.592515 35.00522","upperCorner":"-107.460714 35.113594"}},"Point":{"pos":"-107.526615 35.059425"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, Iowa, Wayne, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"Iowa, Wayne, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"Iowa","SubAdministrativeArea":{"SubAdministrativeAreaName":"Wayne","Locality":{"LocalityName":"New York"}}}}}}},"description":"Wayne, Iowa, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-93.32337 40.801487","upperCorner":"-93.191569 40.901567"}},"Point":{"pos":"-93.257469 40.851546"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, Missouri, Caldwell, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"Missouri, Caldwell, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"Missouri","SubAdministrativeArea":{"SubAdministrativeAreaName":"Caldwell","Locality":{"LocalityName":"New York"}}}}}}},"description":"Caldwell, Missouri, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-93.97525 39.633979","upperCorner":"-93.843449 39.735813"}},"Point":{"pos":"-93.909350 39.684915"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, Texas, Henderson, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"Texas, Henderson, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"Texas","SubAdministrativeArea":{"SubAdministrativeAreaName":"Henderson","Locality":{"LocalityName":"New York"}}}}}}},"description":"Henderson, Texas, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-95.735086 32.112428","upperCorner":"-95.603285 32.224535"}},"Point":{"pos":"-95.669185 32.168499"}}}]}}}
@@ -0,0 +1,112 @@
1
+ {
2
+ "response":{
3
+ "GeoObjectCollection":{
4
+ "metaDataProperty":{
5
+ "GeocoderResponseMetaData":{
6
+ "request":"57.423359,55.892596",
7
+ "found":"3",
8
+ "results":"10",
9
+ "Point":{
10
+ "pos":"57.423359 55.892596"
11
+ }
12
+ }
13
+ },
14
+ "featureMember":[
15
+ {
16
+ "GeoObject":{
17
+ "metaDataProperty":{
18
+ "GeocoderMetaData":{
19
+ "kind":"area",
20
+ "text":"Россия, республика Башкортостан, Караидельский район",
21
+ "precision":"other",
22
+ "AddressDetails":{
23
+ "Country":{
24
+ "AddressLine":"республика Башкортостан, Караидельский район",
25
+ "CountryNameCode":"RU",
26
+ "CountryName":"Россия",
27
+ "AdministrativeArea":{
28
+ "AdministrativeAreaName":"республика Башкортостан",
29
+ "SubAdministrativeArea":{
30
+ "SubAdministrativeAreaName":"Караидельский район"
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ },
37
+ "description":"республика Башкортостан, Россия",
38
+ "name":"Караидельский район",
39
+ "boundedBy":{
40
+ "Envelope":{
41
+ "lowerCorner":"56.231384 55.462814",
42
+ "upperCorner":"57.705348 56.076117"
43
+ }
44
+ },
45
+ "Point":{
46
+ "pos":"57.423359 55.892596"
47
+ }
48
+ }
49
+ },
50
+ {
51
+ "GeoObject":{
52
+ "metaDataProperty":{
53
+ "GeocoderMetaData":{
54
+ "kind":"province",
55
+ "text":"Россия, республика Башкортостан",
56
+ "precision":"other",
57
+ "AddressDetails":{
58
+ "Country":{
59
+ "AddressLine":"республика Башкортостан",
60
+ "CountryNameCode":"RU",
61
+ "CountryName":"Россия",
62
+ "AdministrativeArea":{
63
+ "AdministrativeAreaName":"республика Башкортостан"
64
+ }
65
+ }
66
+ }
67
+ }
68
+ },
69
+ "description":"Россия",
70
+ "name":"республика Башкортостан",
71
+ "boundedBy":{
72
+ "Envelope":{
73
+ "lowerCorner":"53.157475 51.571991",
74
+ "upperCorner":"60.001577 56.533651"
75
+ }
76
+ },
77
+ "Point":{
78
+ "pos":"56.579526 54.127354"
79
+ }
80
+ }
81
+ },
82
+ {
83
+ "GeoObject":{
84
+ "metaDataProperty":{
85
+ "GeocoderMetaData":{
86
+ "kind":"country",
87
+ "text":"Россия",
88
+ "precision":"other",
89
+ "AddressDetails":{
90
+ "Country":{
91
+ "CountryNameCode":"RU",
92
+ "CountryName":"Россия"
93
+ }
94
+ }
95
+ }
96
+ },
97
+ "name":"Россия",
98
+ "boundedBy":{
99
+ "Envelope":{
100
+ "lowerCorner":"19.641673 36.84312",
101
+ "upperCorner":"179.999997 81.848739"
102
+ }
103
+ },
104
+ "Point":{
105
+ "pos":"37.617761 55.755773"
106
+ }
107
+ }
108
+ }
109
+ ]
110
+ }
111
+ }
112
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "response": {
3
+ "GeoObjectCollection": {
4
+ "metaDataProperty": {
5
+ "GeocoderResponseMetaData": {
6
+ "request": "blah",
7
+ "found": "0",
8
+ "results": "10"
9
+ }
10
+ },
11
+ "featureMember": [
12
+
13
+ ]
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ $: << File.join(File.dirname(__FILE__), "..", "..", "lib")
3
+ require 'pathname'
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'geocoder'
7
+ require 'yaml'
8
+
9
+ class HttpClientTest < Test::Unit::TestCase
10
+ def setup
11
+ @api_keys = YAML.load_file("api_keys.yml")
12
+ end
13
+
14
+ def test_http_basic_auth
15
+ Geocoder.configure(lookup: :geocoder_us, api_key: @api_keys["geocoder_us"])
16
+ results = Geocoder.search "27701"
17
+ assert_not_nil results.first
18
+ end
19
+
20
+ def test_ssl
21
+ Geocoder.configure(lookup: :esri, use_https: true)
22
+ results = Geocoder.search "27701"
23
+ assert_not_nil results.first
24
+ end
25
+
26
+ def test_ssl_opt_out
27
+ Geocoder.configure(ip_lookup: :telize, use_https: true)
28
+ results = Geocoder.search "74.200.247.59"
29
+ assert_not_nil results.first
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'test_helper'
4
+ require 'mongoid'
5
+ require 'geocoder/models/mongoid'
6
+
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+
10
+ if (::Mongoid::VERSION >= "3")
11
+ Mongoid.logger = Logger.new($stderr, :debug)
12
+ else
13
+ Mongoid.configure do |config|
14
+ config.logger = Logger.new($stderr, :debug)
15
+ end
16
+ end
17
+
18
+ ##
19
+ # Geocoded model.
20
+ #
21
+ class PlaceUsingMongoid
22
+ include Mongoid::Document
23
+ include Geocoder::Model::Mongoid
24
+
25
+ geocoded_by :address, :coordinates => :location
26
+ field :name
27
+ field :address
28
+ field :location, :type => Array
29
+
30
+ def initialize(name, address)
31
+ super()
32
+ write_attribute :name, name
33
+ write_attribute :address, address
34
+ end
35
+ end
36
+
37
+ class PlaceUsingMongoidWithoutIndex
38
+ include Mongoid::Document
39
+ include Geocoder::Model::Mongoid
40
+
41
+ field :location, :type => Array
42
+ geocoded_by :location, :skip_index => true
43
+ end
@@ -0,0 +1,416 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+
7
+ class MysqlConnection
8
+ def adapter_name
9
+ "mysql"
10
+ end
11
+ end
12
+
13
+ ##
14
+ # Simulate enough of ActiveRecord::Base that objects can be used for testing.
15
+ #
16
+ module ActiveRecord
17
+ class Base
18
+
19
+ def initialize
20
+ @attributes = {}
21
+ end
22
+
23
+ def read_attribute(attr_name)
24
+ @attributes[attr_name.to_sym]
25
+ end
26
+
27
+ def write_attribute(attr_name, value)
28
+ @attributes[attr_name.to_sym] = value
29
+ end
30
+
31
+ def update_attribute(attr_name, value)
32
+ write_attribute(attr_name.to_sym, value)
33
+ end
34
+
35
+ def self.scope(*args); end
36
+
37
+ def self.connection
38
+ MysqlConnection.new
39
+ end
40
+
41
+ def method_missing(name, *args, &block)
42
+ if name.to_s[-1..-1] == "="
43
+ write_attribute name.to_s[0...-1], *args
44
+ else
45
+ read_attribute name
46
+ end
47
+ end
48
+
49
+ class << self
50
+ def table_name
51
+ 'test_table_name'
52
+ end
53
+
54
+ def primary_key
55
+ :id
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+
62
+ # simulate Rails module so Railtie gets loaded
63
+ module Rails
64
+ end
65
+
66
+ # Require Geocoder after ActiveRecord simulator.
67
+ require 'geocoder'
68
+ require "geocoder/lookups/base"
69
+
70
+ ##
71
+ # Mock HTTP request to geocoding service.
72
+ #
73
+ module Geocoder
74
+ module Lookup
75
+ class Base
76
+ private
77
+ def fixture_exists?(filename)
78
+ File.exist?(File.join("test", "fixtures", filename))
79
+ end
80
+
81
+ def read_fixture(file)
82
+ filepath = File.join("test", "fixtures", file)
83
+ s = File.read(filepath).strip.gsub(/\n\s*/, "")
84
+ s.instance_eval do
85
+ def body; self; end
86
+ def code; "200"; end
87
+ end
88
+ s
89
+ end
90
+
91
+ ##
92
+ # Fixture to use if none match the given query.
93
+ #
94
+ def default_fixture_filename
95
+ "#{fixture_prefix}_madison_square_garden"
96
+ end
97
+
98
+ def fixture_prefix
99
+ handle
100
+ end
101
+
102
+ def fixture_for_query(query)
103
+ label = query.reverse_geocode? ? "reverse" : query.text.gsub(/[ \.]/, "_")
104
+ filename = "#{fixture_prefix}_#{label}"
105
+ fixture_exists?(filename) ? filename : default_fixture_filename
106
+ end
107
+
108
+ remove_method(:make_api_request)
109
+
110
+ def make_api_request(query)
111
+ raise TimeoutError if query.text == "timeout"
112
+ raise SocketError if query.text == "socket_error"
113
+ raise Errno::ECONNREFUSED if query.text == "connection_refused"
114
+ read_fixture fixture_for_query(query)
115
+ end
116
+ end
117
+
118
+ class GooglePremier
119
+ private
120
+ def fixture_prefix
121
+ "google"
122
+ end
123
+ end
124
+
125
+ class GooglePlacesDetails
126
+ private
127
+ def fixture_prefix
128
+ "google_places_details"
129
+ end
130
+ end
131
+
132
+ class Dstk
133
+ private
134
+ def fixture_prefix
135
+ "google"
136
+ end
137
+ end
138
+
139
+ class Yandex
140
+ private
141
+ def default_fixture_filename
142
+ "yandex_kremlin"
143
+ end
144
+ end
145
+
146
+ class Freegeoip
147
+ private
148
+ def default_fixture_filename
149
+ "freegeoip_74_200_247_59"
150
+ end
151
+ end
152
+
153
+ class Geoip2
154
+ private
155
+
156
+ remove_method(:results)
157
+
158
+ def results(query)
159
+ return [] if query.to_s == 'no results'
160
+ return [] if query.to_s == '127.0.0.1'
161
+ [{'city'=>{'names'=>{'en'=>'Mountain View'}},'country'=>{'iso_code'=>'US','names'=>
162
+ {'en'=>'United States'}},'location'=>{'latitude'=>37.41919999999999,
163
+ 'longitude'=>-122.0574},'postal'=>{'code'=>'94043'},'subdivisions'=>[{
164
+ 'iso_code'=>'CA','names'=>{'en'=>'California'}}]}]
165
+ end
166
+
167
+ def default_fixture_filename
168
+ 'geoip2_74_200_247_59'
169
+ end
170
+ end
171
+
172
+ class Telize
173
+ private
174
+ def default_fixture_filename
175
+ "telize_74_200_247_59"
176
+ end
177
+ end
178
+
179
+ class Pointpin
180
+ private
181
+ def default_fixture_filename
182
+ "pointpin_80_111_555_555"
183
+ end
184
+ end
185
+
186
+ class Maxmind
187
+ private
188
+ def default_fixture_filename
189
+ "maxmind_74_200_247_59"
190
+ end
191
+ end
192
+
193
+ class MaxmindLocal
194
+ private
195
+
196
+ remove_method(:results)
197
+
198
+ def results query
199
+ return [] if query.to_s == "no results"
200
+
201
+ if query.to_s == '127.0.0.1'
202
+ []
203
+ else
204
+ [{:request=>"8.8.8.8", :ip=>"8.8.8.8", :country_code2=>"US", :country_code3=>"USA", :country_name=>"United States", :continent_code=>"NA", :region_name=>"CA", :city_name=>"Mountain View", :postal_code=>"94043", :latitude=>37.41919999999999, :longitude=>-122.0574, :dma_code=>807, :area_code=>650, :timezone=>"America/Los_Angeles"}]
205
+ end
206
+ end
207
+ end
208
+
209
+ class Baidu
210
+ private
211
+ def default_fixture_filename
212
+ "baidu_shanghai_pearl_tower"
213
+ end
214
+ end
215
+
216
+ class BaiduIp
217
+ private
218
+ def default_fixture_filename
219
+ "baidu_ip_202_198_16_3"
220
+ end
221
+ end
222
+
223
+ class Geocodio
224
+ private
225
+ def default_fixture_filename
226
+ "geocodio_1101_pennsylvania_ave"
227
+ end
228
+ end
229
+
230
+ class Okf
231
+ private
232
+ def default_fixture_filename
233
+ "okf_kirstinmaki"
234
+ end
235
+ end
236
+
237
+ class PostcodeAnywhereUk
238
+ private
239
+ def fixture_prefix
240
+ 'postcode_anywhere_uk_geocode_v2_00'
241
+ end
242
+
243
+ def default_fixture_filename
244
+ "#{fixture_prefix}_romsey"
245
+ end
246
+ end
247
+ end
248
+ end
249
+
250
+ ##
251
+ # Geocoded model.
252
+ #
253
+ class Place < ActiveRecord::Base
254
+ geocoded_by :address
255
+
256
+ def initialize(name, address)
257
+ super()
258
+ write_attribute :name, name
259
+ write_attribute :address, address
260
+ end
261
+ end
262
+
263
+ ##
264
+ # Geocoded model.
265
+ # - Has user-defined primary key (not just 'id')
266
+ #
267
+ class PlaceWithCustomPrimaryKey < Place
268
+
269
+ class << self
270
+ def primary_key
271
+ :custom_primary_key_id
272
+ end
273
+ end
274
+
275
+ end
276
+
277
+ class PlaceReverseGeocoded < ActiveRecord::Base
278
+ reverse_geocoded_by :latitude, :longitude
279
+
280
+ def initialize(name, latitude, longitude)
281
+ super()
282
+ write_attribute :name, name
283
+ write_attribute :latitude, latitude
284
+ write_attribute :longitude, longitude
285
+ end
286
+ end
287
+
288
+ class PlaceWithCustomResultsHandling < ActiveRecord::Base
289
+ geocoded_by :address do |obj,results|
290
+ if result = results.first
291
+ obj.coords_string = "#{result.latitude},#{result.longitude}"
292
+ else
293
+ obj.coords_string = "NOT FOUND"
294
+ end
295
+ end
296
+
297
+ def initialize(name, address)
298
+ super()
299
+ write_attribute :name, name
300
+ write_attribute :address, address
301
+ end
302
+ end
303
+
304
+ class PlaceReverseGeocodedWithCustomResultsHandling < ActiveRecord::Base
305
+ reverse_geocoded_by :latitude, :longitude do |obj,results|
306
+ if result = results.first
307
+ obj.country = result.country_code
308
+ end
309
+ end
310
+
311
+ def initialize(name, latitude, longitude)
312
+ super()
313
+ write_attribute :name, name
314
+ write_attribute :latitude, latitude
315
+ write_attribute :longitude, longitude
316
+ end
317
+ end
318
+
319
+ class PlaceWithForwardAndReverseGeocoding < ActiveRecord::Base
320
+ geocoded_by :address, :latitude => :lat, :longitude => :lon
321
+ reverse_geocoded_by :lat, :lon, :address => :location
322
+
323
+ def initialize(name)
324
+ super()
325
+ write_attribute :name, name
326
+ end
327
+ end
328
+
329
+ class PlaceWithCustomLookup < ActiveRecord::Base
330
+ geocoded_by :address, :lookup => :nominatim do |obj,results|
331
+ if result = results.first
332
+ obj.result_class = result.class
333
+ end
334
+ end
335
+
336
+ def initialize(name, address)
337
+ super()
338
+ write_attribute :name, name
339
+ write_attribute :address, address
340
+ end
341
+ end
342
+
343
+ class PlaceWithCustomLookupProc < ActiveRecord::Base
344
+ geocoded_by :address, :lookup => lambda{|obj| obj.custom_lookup } do |obj,results|
345
+ if result = results.first
346
+ obj.result_class = result.class
347
+ end
348
+ end
349
+
350
+ def custom_lookup
351
+ :nominatim
352
+ end
353
+
354
+ def initialize(name, address)
355
+ super()
356
+ write_attribute :name, name
357
+ write_attribute :address, address
358
+ end
359
+ end
360
+
361
+ class PlaceReverseGeocodedWithCustomLookup < ActiveRecord::Base
362
+ reverse_geocoded_by :latitude, :longitude, :lookup => :nominatim do |obj,results|
363
+ if result = results.first
364
+ obj.result_class = result.class
365
+ end
366
+ end
367
+
368
+ def initialize(name, latitude, longitude)
369
+ super()
370
+ write_attribute :name, name
371
+ write_attribute :latitude, latitude
372
+ write_attribute :longitude, longitude
373
+ end
374
+ end
375
+
376
+
377
+ class GeocoderTestCase < Test::Unit::TestCase
378
+
379
+ def setup
380
+ super
381
+ Geocoder::Configuration.instance.set_defaults
382
+ Geocoder.configure(:maxmind => {:service => :city_isp_org})
383
+ end
384
+
385
+ def geocoded_object_params(abbrev)
386
+ {
387
+ :msg => ["Madison Square Garden", "4 Penn Plaza, New York, NY"]
388
+ }[abbrev]
389
+ end
390
+
391
+ def reverse_geocoded_object_params(abbrev)
392
+ {
393
+ :msg => ["Madison Square Garden", 40.750354, -73.993371]
394
+ }[abbrev]
395
+ end
396
+
397
+ def set_api_key!(lookup_name)
398
+ lookup = Geocoder::Lookup.get(lookup_name)
399
+ if lookup.required_api_key_parts.size == 1
400
+ key = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
401
+ elsif lookup.required_api_key_parts.size > 1
402
+ key = lookup.required_api_key_parts
403
+ else
404
+ key = nil
405
+ end
406
+ Geocoder.configure(:api_key => key)
407
+ end
408
+ end
409
+
410
+ class MockHttpResponse
411
+ attr_reader :code, :body
412
+ def initialize(options = {})
413
+ @code = options[:code].to_s
414
+ @body = options[:body]
415
+ end
416
+ end