geocoder 1.2.6 → 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 +189 -1
- data/LICENSE +1 -1
- data/README.md +387 -755
- data/examples/autoexpire_cache_redis.rb +5 -3
- data/examples/reverse_geocode_job.rb +40 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +17 -16
- 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 +30 -38
- data/lib/geocoder/cli.rb +2 -2
- data/lib/geocoder/configuration.rb +18 -5
- data/lib/geocoder/esri_token.rb +38 -0
- data/lib/geocoder/exceptions.rb +19 -0
- data/lib/geocoder/ip_address.rb +16 -11
- data/lib/geocoder/kernel_logger.rb +25 -0
- data/lib/geocoder/logger.rb +47 -0
- data/lib/geocoder/lookup.rb +31 -12
- data/lib/geocoder/lookups/amap.rb +63 -0
- data/lib/geocoder/lookups/baidu.rb +17 -9
- data/lib/geocoder/lookups/baidu_ip.rb +7 -31
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +143 -0
- data/lib/geocoder/lookups/base.rb +73 -25
- data/lib/geocoder/lookups/bing.rb +38 -15
- data/lib/geocoder/lookups/db_ip_com.rb +52 -0
- data/lib/geocoder/lookups/dstk.rb +4 -2
- data/lib/geocoder/lookups/esri.rb +55 -8
- data/lib/geocoder/lookups/freegeoip.rb +18 -5
- data/lib/geocoder/lookups/geocoder_ca.rb +5 -6
- data/lib/geocoder/lookups/geocodio.rb +8 -8
- data/lib/geocoder/lookups/geoip2.rb +10 -5
- data/lib/geocoder/lookups/geoportail_lu.rb +65 -0
- data/lib/geocoder/lookups/google.rb +37 -9
- data/lib/geocoder/lookups/google_places_details.rb +9 -9
- data/lib/geocoder/lookups/google_places_search.rb +33 -0
- 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 +82 -0
- data/lib/geocoder/lookups/ipdata_co.rb +62 -0
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +44 -0
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/ipstack.rb +63 -0
- data/lib/geocoder/lookups/latlon.rb +59 -0
- data/lib/geocoder/lookups/location_iq.rb +50 -0
- data/lib/geocoder/lookups/mapbox.rb +59 -0
- data/lib/geocoder/lookups/mapquest.rb +7 -9
- data/lib/geocoder/lookups/maxmind.rb +7 -7
- data/lib/geocoder/lookups/maxmind_geoip2.rb +70 -0
- data/lib/geocoder/lookups/maxmind_local.rb +9 -2
- data/lib/geocoder/lookups/nominatim.rb +18 -6
- data/lib/geocoder/lookups/opencagedata.rb +16 -9
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pelias.rb +63 -0
- data/lib/geocoder/lookups/pickpoint.rb +41 -0
- data/lib/geocoder/lookups/pointpin.rb +14 -13
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +7 -8
- data/lib/geocoder/lookups/postcodes_io.rb +31 -0
- data/lib/geocoder/lookups/smarty_streets.rb +23 -5
- data/lib/geocoder/lookups/telize.rb +42 -7
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +17 -9
- data/lib/geocoder/models/active_record.rb +4 -3
- data/lib/geocoder/models/mongo_base.rb +0 -2
- data/lib/geocoder/query.rb +15 -1
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/request.rb +103 -14
- 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 +257 -0
- data/lib/geocoder/results/base.rb +13 -1
- data/lib/geocoder/results/bing.rb +5 -1
- data/lib/geocoder/results/db_ip_com.rb +58 -0
- data/lib/geocoder/results/esri.rb +30 -6
- data/lib/geocoder/results/freegeoip.rb +2 -7
- data/lib/geocoder/results/geocoder_ca.rb +3 -3
- data/lib/geocoder/results/geocodio.rb +15 -3
- data/lib/geocoder/results/geoip2.rb +37 -25
- data/lib/geocoder/results/geoportail_lu.rb +71 -0
- data/lib/geocoder/results/google.rb +26 -0
- data/lib/geocoder/results/google_places_details.rb +4 -0
- data/lib/geocoder/results/google_places_search.rb +52 -0
- data/lib/geocoder/results/here.rb +21 -1
- data/lib/geocoder/results/ip2location.rb +22 -0
- data/lib/geocoder/results/ipapi_com.rb +45 -0
- data/lib/geocoder/results/ipdata_co.rb +40 -0
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipinfo_io.rb +48 -0
- data/lib/geocoder/results/ipregistry.rb +308 -0
- data/lib/geocoder/results/ipstack.rb +60 -0
- data/lib/geocoder/results/latlon.rb +71 -0
- data/lib/geocoder/results/location_iq.rb +6 -0
- data/lib/geocoder/results/mapbox.rb +57 -0
- data/lib/geocoder/results/mapquest.rb +5 -8
- data/lib/geocoder/results/maxmind.rb +0 -5
- data/lib/geocoder/results/maxmind_geoip2.rb +9 -0
- data/lib/geocoder/results/maxmind_local.rb +0 -5
- data/lib/geocoder/results/nominatim.rb +18 -3
- data/lib/geocoder/results/opencagedata.rb +20 -2
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/pelias.rb +58 -0
- data/lib/geocoder/results/pickpoint.rb +6 -0
- data/lib/geocoder/results/pointpin.rb +0 -4
- 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/results/yandex.rb +57 -7
- data/lib/geocoder/sql.rb +9 -6
- data/lib/geocoder/stores/active_record.rb +49 -10
- data/lib/geocoder/stores/base.rb +2 -14
- data/lib/geocoder/stores/mongo_base.rb +0 -31
- data/lib/geocoder/version.rb +1 -1
- data/lib/geocoder.rb +2 -1
- data/lib/hash_recursive_merge.rb +1 -2
- data/lib/maxmind_database.rb +4 -4
- data/lib/tasks/geocoder.rake +29 -4
- metadata +56 -159
- data/.gitignore +0 -6
- data/.travis.yml +0 -31
- data/Rakefile +0 -25
- data/gemfiles/Gemfile.mongoid-2.4.x +0 -16
- data/lib/geocoder/lookups/geocoder_us.rb +0 -39
- data/lib/geocoder/lookups/okf.rb +0 -43
- data/lib/geocoder/lookups/ovi.rb +0 -62
- data/lib/geocoder/lookups/yahoo.rb +0 -88
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/geocoder/results/okf.rb +0 -106
- data/lib/geocoder/results/ovi.rb +0 -62
- data/lib/geocoder/results/yahoo.rb +0 -55
- data/lib/oauth_util.rb +0 -112
- data/test/fixtures/baidu_invalid_key +0 -1
- data/test/fixtures/baidu_ip_202_198_16_3 +0 -19
- data/test/fixtures/baidu_ip_invalid_key +0 -1
- data/test/fixtures/baidu_ip_no_results +0 -1
- data/test/fixtures/baidu_no_results +0 -1
- data/test/fixtures/baidu_reverse +0 -1
- data/test/fixtures/baidu_shanghai_pearl_tower +0 -12
- data/test/fixtures/bing_invalid_key +0 -1
- data/test/fixtures/bing_madison_square_garden +0 -40
- data/test/fixtures/bing_no_results +0 -16
- data/test/fixtures/bing_reverse +0 -42
- data/test/fixtures/cloudmade_invalid_key +0 -1
- data/test/fixtures/cloudmade_madison_square_garden +0 -1
- data/test/fixtures/cloudmade_no_results +0 -1
- data/test/fixtures/esri_madison_square_garden +0 -59
- data/test/fixtures/esri_no_results +0 -8
- data/test/fixtures/esri_reverse +0 -21
- data/test/fixtures/freegeoip_74_200_247_59 +0 -12
- data/test/fixtures/freegeoip_no_results +0 -1
- data/test/fixtures/geocoder_ca_madison_square_garden +0 -1
- data/test/fixtures/geocoder_ca_no_results +0 -1
- data/test/fixtures/geocoder_ca_reverse +0 -34
- data/test/fixtures/geocoder_us_madison_square_garden +0 -1
- data/test/fixtures/geocoder_us_no_results +0 -1
- data/test/fixtures/geocodio_1101_pennsylvania_ave +0 -1
- data/test/fixtures/geocodio_bad_api_key +0 -3
- data/test/fixtures/geocodio_invalid +0 -4
- data/test/fixtures/geocodio_no_results +0 -1
- data/test/fixtures/geocodio_over_query_limit +0 -4
- data/test/fixtures/google_garbage +0 -456
- data/test/fixtures/google_madison_square_garden +0 -57
- data/test/fixtures/google_no_city_data +0 -44
- data/test/fixtures/google_no_locality +0 -51
- data/test/fixtures/google_no_results +0 -4
- data/test/fixtures/google_over_limit +0 -4
- data/test/fixtures/google_places_details_invalid_request +0 -4
- data/test/fixtures/google_places_details_madison_square_garden +0 -120
- data/test/fixtures/google_places_details_no_results +0 -4
- data/test/fixtures/google_places_details_no_reviews +0 -60
- data/test/fixtures/google_places_details_no_types +0 -66
- data/test/fixtures/here_madison_square_garden +0 -72
- data/test/fixtures/here_no_results +0 -8
- data/test/fixtures/mapquest_error +0 -16
- data/test/fixtures/mapquest_invalid_api_key +0 -16
- data/test/fixtures/mapquest_invalid_request +0 -16
- data/test/fixtures/mapquest_madison_square_garden +0 -52
- data/test/fixtures/mapquest_no_results +0 -16
- data/test/fixtures/maxmind_24_24_24_21 +0 -1
- data/test/fixtures/maxmind_24_24_24_22 +0 -1
- data/test/fixtures/maxmind_24_24_24_23 +0 -1
- data/test/fixtures/maxmind_24_24_24_24 +0 -1
- data/test/fixtures/maxmind_74_200_247_59 +0 -1
- data/test/fixtures/maxmind_invalid_key +0 -1
- data/test/fixtures/maxmind_no_results +0 -1
- data/test/fixtures/nominatim_madison_square_garden +0 -150
- data/test/fixtures/nominatim_no_results +0 -1
- data/test/fixtures/nominatim_over_limit +0 -1
- data/test/fixtures/okf_kirstinmaki +0 -67
- data/test/fixtures/okf_no_results +0 -4
- data/test/fixtures/opencagedata_invalid_api_key +0 -25
- data/test/fixtures/opencagedata_invalid_request +0 -26
- data/test/fixtures/opencagedata_madison_square_garden +0 -73
- data/test/fixtures/opencagedata_no_results +0 -29
- data/test/fixtures/opencagedata_over_limit +0 -31
- data/test/fixtures/ovi_madison_square_garden +0 -72
- data/test/fixtures/ovi_no_results +0 -8
- data/test/fixtures/pointpin_10_10_10_10 +0 -1
- data/test/fixtures/pointpin_555_555_555_555 +0 -1
- data/test/fixtures/pointpin_80_111_555_555 +0 -1
- data/test/fixtures/pointpin_no_results +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_WR26NJ +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_generic_error +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_hampshire +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_key_limit_exceeded +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_no_results +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_romsey +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_unknown_key +0 -1
- data/test/fixtures/smarty_streets_11211 +0 -1
- data/test/fixtures/smarty_streets_madison_square_garden +0 -47
- data/test/fixtures/smarty_streets_no_results +0 -1
- data/test/fixtures/telize_10_10_10_10 +0 -1
- data/test/fixtures/telize_555_555_555_555 +0 -4
- data/test/fixtures/telize_74_200_247_59 +0 -1
- data/test/fixtures/telize_no_results +0 -1
- data/test/fixtures/yahoo_error +0 -1
- data/test/fixtures/yahoo_invalid_key +0 -2
- data/test/fixtures/yahoo_madison_square_garden +0 -52
- data/test/fixtures/yahoo_no_results +0 -10
- data/test/fixtures/yahoo_over_limit +0 -2
- data/test/fixtures/yandex_canada_rue_dupuis_14 +0 -446
- data/test/fixtures/yandex_invalid_key +0 -1
- data/test/fixtures/yandex_kremlin +0 -48
- data/test/fixtures/yandex_new_york +0 -1
- data/test/fixtures/yandex_no_city_and_town +0 -112
- data/test/fixtures/yandex_no_results +0 -16
- data/test/integration/http_client_test.rb +0 -31
- data/test/mongoid_test_helper.rb +0 -43
- data/test/test_helper.rb +0 -416
- data/test/unit/active_record_test.rb +0 -16
- data/test/unit/cache_test.rb +0 -37
- data/test/unit/calculations_test.rb +0 -220
- data/test/unit/configuration_test.rb +0 -55
- data/test/unit/error_handling_test.rb +0 -56
- data/test/unit/geocoder_test.rb +0 -78
- data/test/unit/https_test.rb +0 -17
- data/test/unit/ip_address_test.rb +0 -27
- data/test/unit/lookup_test.rb +0 -153
- data/test/unit/lookups/bing_test.rb +0 -68
- data/test/unit/lookups/dstk_test.rb +0 -26
- data/test/unit/lookups/esri_test.rb +0 -48
- data/test/unit/lookups/freegeoip_test.rb +0 -27
- data/test/unit/lookups/geocoder_ca_test.rb +0 -17
- data/test/unit/lookups/geocodio_test.rb +0 -55
- data/test/unit/lookups/geoip2_test.rb +0 -27
- data/test/unit/lookups/google_places_details_test.rb +0 -122
- data/test/unit/lookups/google_premier_test.rb +0 -22
- data/test/unit/lookups/google_test.rb +0 -84
- data/test/unit/lookups/mapquest_test.rb +0 -60
- data/test/unit/lookups/maxmind_local_test.rb +0 -28
- data/test/unit/lookups/maxmind_test.rb +0 -63
- data/test/unit/lookups/nominatim_test.rb +0 -31
- data/test/unit/lookups/okf_test.rb +0 -38
- data/test/unit/lookups/opencagedata_test.rb +0 -64
- data/test/unit/lookups/pointpin_test.rb +0 -30
- data/test/unit/lookups/postcode_anywhere_uk_test.rb +0 -70
- data/test/unit/lookups/smarty_streets_test.rb +0 -71
- data/test/unit/lookups/telize_test.rb +0 -36
- data/test/unit/lookups/yahoo_test.rb +0 -35
- data/test/unit/method_aliases_test.rb +0 -26
- data/test/unit/model_test.rb +0 -38
- data/test/unit/mongoid_test.rb +0 -47
- data/test/unit/near_test.rb +0 -87
- data/test/unit/oauth_util_test.rb +0 -31
- data/test/unit/proxy_test.rb +0 -37
- data/test/unit/query_test.rb +0 -52
- data/test/unit/rake_task_test.rb +0 -21
- data/test/unit/request_test.rb +0 -35
- data/test/unit/result_test.rb +0 -72
- data/test/unit/test_mode_test.rb +0 -70
@@ -1,26 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class DstkTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(lookup: :dstk)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_dstk_result_components
|
12
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
13
|
-
assert_equal "Manhattan", result.address_components_of_type(:sublocality).first['long_name']
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_dstk_query_url
|
17
|
-
query = Geocoder::Query.new("Madison Square Garden, New York, NY")
|
18
|
-
assert_equal "http://www.datasciencetoolkit.org/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&language=en&sensor=false", query.url
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_dstk_query_url_with_custom_host
|
22
|
-
Geocoder.configure(dstk: {host: 'NOT_AN_ACTUAL_HOST'})
|
23
|
-
query = Geocoder::Query.new("Madison Square Garden, New York, NY")
|
24
|
-
assert_equal "http://NOT_AN_ACTUAL_HOST/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&language=en&sensor=false", query.url
|
25
|
-
end
|
26
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class EsriTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(lookup: :esri)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_query_for_geocode
|
12
|
-
query = Geocoder::Query.new("Bluffton, SC")
|
13
|
-
lookup = Geocoder::Lookup.get(:esri)
|
14
|
-
res = lookup.query_url(query)
|
15
|
-
assert_equal "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?f=pjson&outFields=%2A&text=Bluffton%2C+SC",
|
16
|
-
res
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_query_for_reverse_geocode
|
20
|
-
query = Geocoder::Query.new([45.423733, -75.676333])
|
21
|
-
lookup = Geocoder::Lookup.get(:esri)
|
22
|
-
res = lookup.query_url(query)
|
23
|
-
assert_equal "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?f=pjson&location=-75.676333%2C45.423733&outFields=%2A",
|
24
|
-
res
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_results_component
|
28
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
29
|
-
assert_equal "10001", result.postal_code
|
30
|
-
assert_equal "USA", result.country
|
31
|
-
assert_equal "Madison Square Garden", result.address
|
32
|
-
assert_equal "New York", result.city
|
33
|
-
assert_equal "New York", result.state
|
34
|
-
assert_equal(40.75004981300049, result.coordinates[0])
|
35
|
-
assert_equal(-73.99423889799965, result.coordinates[1])
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_results_component_when_reverse_geocoding
|
39
|
-
result = Geocoder.search([45.423733, -75.676333]).first
|
40
|
-
assert_equal "75007", result.postal_code
|
41
|
-
assert_equal "FRA", result.country
|
42
|
-
assert_equal "4 Avenue Gustave Eiffel", result.address
|
43
|
-
assert_equal "Paris", result.city
|
44
|
-
assert_equal "Île-de-France", result.state
|
45
|
-
assert_equal(48.858129997357558, result.coordinates[0])
|
46
|
-
assert_equal(2.2956200048981574, result.coordinates[1])
|
47
|
-
end
|
48
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class FreegeoipTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(ip_lookup: :freegeoip)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_result_on_ip_address_search
|
12
|
-
result = Geocoder.search("74.200.247.59").first
|
13
|
-
assert result.is_a?(Geocoder::Result::Freegeoip)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_result_components
|
17
|
-
result = Geocoder.search("74.200.247.59").first
|
18
|
-
assert_equal "Plano, TX 75093, United States", result.address
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_host_config
|
22
|
-
Geocoder.configure(freegeoip: {host: "local.com"})
|
23
|
-
lookup = Geocoder::Lookup::Freegeoip.new
|
24
|
-
query = Geocoder::Query.new("24.24.24.23")
|
25
|
-
assert_match %r(http://local\.com), lookup.query_url(query)
|
26
|
-
end
|
27
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class GeocoderCaTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(lookup: :geocoder_ca)
|
9
|
-
set_api_key!(:geocoder_ca)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_result_components
|
13
|
-
result = Geocoder.search([45.423733, -75.676333]).first
|
14
|
-
assert_equal "CA", result.country_code
|
15
|
-
assert_equal "289 Somerset ST E, Ottawa, ON K1N6W1, Canada", result.address
|
16
|
-
end
|
17
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class GeocodioTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(lookup: :geocodio)
|
9
|
-
set_api_key!(:geocodio)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_result_components
|
13
|
-
result = Geocoder.search("1101 Pennsylvania Ave NW, Washington DC").first
|
14
|
-
assert_equal 1.0, result.accuracy
|
15
|
-
assert_equal "1101", result.number
|
16
|
-
assert_equal "Ave", result.suffix
|
17
|
-
assert_equal "DC", result.state
|
18
|
-
assert_equal "20004", result.zip
|
19
|
-
assert_equal "NW", result.postdirectional
|
20
|
-
assert_equal "Washington", result.city
|
21
|
-
assert_equal "1101 Pennsylvania Ave NW, Washington DC, 20004", result.formatted_address
|
22
|
-
assert_equal({ "lat" => "38.895019", "lng" => "-77.028095" }, result.location)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_no_results
|
26
|
-
results = Geocoder.search("no results")
|
27
|
-
assert_equal 0, results.length
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_geocodio_reverse_url
|
31
|
-
query = Geocoder::Query.new([45.423733, -75.676333])
|
32
|
-
assert_match /reverse/, query.url
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_raises_invalid_request_exception
|
36
|
-
Geocoder.configure Geocoder.configure(:always_raise => [Geocoder::InvalidRequest])
|
37
|
-
assert_raises Geocoder::InvalidRequest do
|
38
|
-
Geocoder.search("invalid")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_raises_api_key_exception
|
43
|
-
Geocoder.configure Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey])
|
44
|
-
assert_raises Geocoder::InvalidApiKey do
|
45
|
-
Geocoder.search("bad api key")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_raises_over_limit_exception
|
50
|
-
Geocoder.configure Geocoder.configure(:always_raise => [Geocoder::OverQueryLimitError])
|
51
|
-
assert_raises Geocoder::OverQueryLimitError do
|
52
|
-
Geocoder.search("over query limit")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class Geoip2Test < GeocoderTestCase
|
5
|
-
def setup
|
6
|
-
Geocoder.configure(ip_lookup: :geoip2, file: 'test_file')
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_result_attributes
|
10
|
-
result = Geocoder.search('8.8.8.8').first
|
11
|
-
assert_equal 'Mountain View, CA 94043, United States', result.address
|
12
|
-
assert_equal 'Mountain View', result.city
|
13
|
-
assert_equal 'CA', result.state_code
|
14
|
-
assert_equal 'California', result.state
|
15
|
-
assert_equal 'United States', result.country
|
16
|
-
assert_equal 'US', result.country_code
|
17
|
-
assert_equal '94043', result.postal_code
|
18
|
-
assert_equal 37.41919999999999, result.latitude
|
19
|
-
assert_equal -122.0574, result.longitude
|
20
|
-
assert_equal [37.41919999999999, -122.0574], result.coordinates
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_loopback
|
24
|
-
results = Geocoder.search('127.0.0.1')
|
25
|
-
assert_equal [], results
|
26
|
-
end
|
27
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class GooglePlacesDetailsTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(lookup: :google_places_details)
|
9
|
-
set_api_key!(:google_places_details)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_google_places_details_result_components
|
13
|
-
assert_equal "Manhattan", madison_square_garden.address_components_of_type(:sublocality).first["long_name"]
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_google_places_details_result_components_contains_route
|
17
|
-
assert_equal "Pennsylvania Plaza", madison_square_garden.address_components_of_type(:route).first["long_name"]
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_google_places_details_result_components_contains_street_number
|
21
|
-
assert_equal "4", madison_square_garden.address_components_of_type(:street_number).first["long_name"]
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_google_places_details_street_address_returns_formatted_street_address
|
25
|
-
assert_equal "4 Pennsylvania Plaza", madison_square_garden.street_address
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_google_places_details_result_contains_place_id
|
29
|
-
assert_equal "ChIJhRwB-yFawokR5Phil-QQ3zM", madison_square_garden.place_id
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_google_places_details_result_contains_latitude
|
33
|
-
assert_equal madison_square_garden.latitude, 40.750504
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_google_places_details_result_contains_longitude
|
37
|
-
assert_equal madison_square_garden.longitude, -73.993439
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_google_places_details_result_contains_rating
|
41
|
-
assert_equal 4.4, madison_square_garden.rating
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_google_places_details_result_contains_rating_count
|
45
|
-
assert_equal 382, madison_square_garden.rating_count
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_google_places_details_result_contains_reviews
|
49
|
-
reviews = madison_square_garden.reviews
|
50
|
-
|
51
|
-
assert_equal 2, reviews.size
|
52
|
-
assert_equal "John Smith", reviews.first["author_name"]
|
53
|
-
assert_equal 5, reviews.first["rating"]
|
54
|
-
assert_equal "It's nice.", reviews.first["text"]
|
55
|
-
assert_equal "en", reviews.first["language"]
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_google_places_details_result_contains_types
|
59
|
-
assert_equal madison_square_garden.types, %w(stadium establishment)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_google_places_details_result_contains_website
|
63
|
-
assert_equal madison_square_garden.website, "http://www.thegarden.com/"
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_google_places_details_result_contains_phone_number
|
67
|
-
assert_equal madison_square_garden.phone_number, "+1 212-465-6741"
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_google_places_details_query_url_contains_placeid
|
71
|
-
url = lookup.query_url(Geocoder::Query.new("some-place-id"))
|
72
|
-
assert_match(/placeid=some-place-id/, url)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_google_places_details_query_url_contains_language
|
76
|
-
url = lookup.query_url(Geocoder::Query.new("some-place-id", language: "de"))
|
77
|
-
assert_match(/language=de/, url)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_google_places_details_query_url_always_uses_https
|
81
|
-
url = lookup.query_url(Geocoder::Query.new("some-place-id"))
|
82
|
-
assert_match(%r(^https://), url)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_google_places_details_result_with_no_reviews_shows_empty_reviews
|
86
|
-
assert_equal no_reviews_result.reviews, []
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_google_places_details_result_with_no_types_shows_empty_types
|
90
|
-
assert_equal no_types_result.types, []
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_google_places_details_result_with_invalid_place_id_empty
|
94
|
-
assert_equal Geocoder.search("invalid request"), []
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_raises_exception_on_google_places_details_invalid_request
|
98
|
-
Geocoder.configure(always_raise: [Geocoder::InvalidRequest])
|
99
|
-
assert_raises Geocoder::InvalidRequest do
|
100
|
-
Geocoder.search("invalid request")
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
def lookup
|
107
|
-
Geocoder::Lookup::GooglePlacesDetails.new
|
108
|
-
end
|
109
|
-
|
110
|
-
def madison_square_garden
|
111
|
-
Geocoder.search("ChIJhRwB-yFawokR5Phil-QQ3zM").first
|
112
|
-
end
|
113
|
-
|
114
|
-
def no_reviews_result
|
115
|
-
Geocoder.search("no reviews").first
|
116
|
-
end
|
117
|
-
|
118
|
-
def no_types_result
|
119
|
-
Geocoder.search("no types").first
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class GooglePremierTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(lookup: :google_premier)
|
9
|
-
set_api_key!(:google_premier)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_result_components
|
13
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
14
|
-
assert_equal "Manhattan", result.address_components_of_type(:sublocality).first['long_name']
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_query_url
|
18
|
-
Geocoder.configure(google_premier: {api_key: ["deadbeef", "gme-test", "test-dev"]})
|
19
|
-
query = Geocoder::Query.new("Madison Square Garden, New York, NY")
|
20
|
-
assert_equal "http://maps.googleapis.com/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&channel=test-dev&client=gme-test&language=en&sensor=false&signature=doJvJqX7YJzgV9rJ0DnVkTGZqTg=", query.url
|
21
|
-
end
|
22
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class GoogleTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def test_google_result_components
|
8
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
9
|
-
assert_equal "Manhattan",
|
10
|
-
result.address_components_of_type(:sublocality).first['long_name']
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_google_result_components_contains_route
|
14
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
15
|
-
assert_equal "Penn Plaza",
|
16
|
-
result.address_components_of_type(:route).first['long_name']
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_google_result_components_contains_street_number
|
20
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
21
|
-
assert_equal "4",
|
22
|
-
result.address_components_of_type(:street_number).first['long_name']
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_google_returns_city_when_no_locality_in_result
|
26
|
-
result = Geocoder.search("no locality").first
|
27
|
-
assert_equal "Haram", result.city
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_google_city_results_returns_nil_if_no_matching_component_types
|
31
|
-
result = Geocoder.search("no city data").first
|
32
|
-
assert_equal nil, result.city
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_google_street_address_returns_formatted_street_address
|
36
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
37
|
-
assert_equal "4 Penn Plaza", result.street_address
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_google_precision
|
41
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
42
|
-
assert_equal "ROOFTOP",
|
43
|
-
result.precision
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_google_query_url_contains_bounds
|
47
|
-
lookup = Geocoder::Lookup::Google.new
|
48
|
-
url = lookup.query_url(Geocoder::Query.new(
|
49
|
-
"Some Intersection",
|
50
|
-
:bounds => [[40.0, -120.0], [39.0, -121.0]]
|
51
|
-
))
|
52
|
-
assert_match(/bounds=40.0+%2C-120.0+%7C39.0+%2C-121.0+/, url)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_google_query_url_contains_region
|
56
|
-
lookup = Geocoder::Lookup::Google.new
|
57
|
-
url = lookup.query_url(Geocoder::Query.new(
|
58
|
-
"Some Intersection",
|
59
|
-
:region => "gb"
|
60
|
-
))
|
61
|
-
assert_match(/region=gb/, url)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_google_query_url_contains_components_when_given_as_string
|
65
|
-
lookup = Geocoder::Lookup::Google.new
|
66
|
-
url = lookup.query_url(Geocoder::Query.new(
|
67
|
-
"Some Intersection",
|
68
|
-
:components => "locality:ES"
|
69
|
-
))
|
70
|
-
formatted = "components=" + CGI.escape("locality:ES")
|
71
|
-
assert url.include?(formatted), "Expected #{formatted} to be included in #{url}"
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_google_query_url_contains_components_when_given_as_array
|
75
|
-
lookup = Geocoder::Lookup::Google.new
|
76
|
-
url = lookup.query_url(Geocoder::Query.new(
|
77
|
-
"Some Intersection",
|
78
|
-
:components => ["country:ES", "locality:ES"]
|
79
|
-
))
|
80
|
-
formatted = "components=" + CGI.escape("country:ES|locality:ES")
|
81
|
-
assert url.include?(formatted), "Expected #{formatted} to be included in #{url}"
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class MapquestTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(lookup: :mapquest)
|
9
|
-
set_api_key!(:mapquest)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_url_contains_api_key
|
13
|
-
Geocoder.configure(mapquest: {api_key: "abc123"})
|
14
|
-
query = Geocoder::Query.new("Bluffton, SC")
|
15
|
-
assert_equal "http://www.mapquestapi.com/geocoding/v1/address?key=abc123&location=Bluffton%2C+SC", query.url
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_url_for_version_2
|
19
|
-
Geocoder.configure(mapquest: {api_key: "abc123", version: 2})
|
20
|
-
query = Geocoder::Query.new("Bluffton, SC")
|
21
|
-
assert_equal "http://www.mapquestapi.com/geocoding/v2/address?key=abc123&location=Bluffton%2C+SC", query.url
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_url_for_open_street_maps
|
25
|
-
Geocoder.configure(mapquest: {api_key: "abc123", open: true})
|
26
|
-
query = Geocoder::Query.new("Bluffton, SC")
|
27
|
-
assert_equal "http://open.mapquestapi.com/geocoding/v1/address?key=abc123&location=Bluffton%2C+SC", query.url
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_result_components
|
31
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
32
|
-
assert_equal "10001", result.postal_code
|
33
|
-
assert_equal "46 West 31st Street, New York, NY, 10001, US", result.address
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_no_results
|
37
|
-
assert_equal [], Geocoder.search("no results")
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_raises_exception_when_invalid_request
|
41
|
-
Geocoder.configure(always_raise: [Geocoder::InvalidRequest])
|
42
|
-
assert_raises Geocoder::InvalidRequest do
|
43
|
-
Geocoder.search("invalid request")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_raises_exception_when_invalid_api_key
|
48
|
-
Geocoder.configure(always_raise: [Geocoder::InvalidApiKey])
|
49
|
-
assert_raises Geocoder::InvalidApiKey do
|
50
|
-
Geocoder.search("invalid api key")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_raises_exception_when_error
|
55
|
-
Geocoder.configure(always_raise: [Geocoder::Error])
|
56
|
-
assert_raises Geocoder::Error do
|
57
|
-
Geocoder.search("error")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class MaxmindLocalTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(ip_lookup: :maxmind_local)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_result_attributes
|
12
|
-
result = Geocoder.search('8.8.8.8').first
|
13
|
-
assert_equal 'Mountain View, CA 94043, United States', result.address
|
14
|
-
assert_equal 'Mountain View', result.city
|
15
|
-
assert_equal 'CA', result.state
|
16
|
-
assert_equal 'United States', result.country
|
17
|
-
assert_equal 'US', result.country_code
|
18
|
-
assert_equal '94043', result.postal_code
|
19
|
-
assert_equal 37.41919999999999, result.latitude
|
20
|
-
assert_equal -122.0574, result.longitude
|
21
|
-
assert_equal [37.41919999999999, -122.0574], result.coordinates
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_loopback
|
25
|
-
results = Geocoder.search('127.0.0.1')
|
26
|
-
assert_equal [], results
|
27
|
-
end
|
28
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class MaxmindTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(ip_lookup: :maxmind)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_maxmind_result_on_ip_address_search
|
12
|
-
Geocoder.configure(maxmind: {service: :city_isp_org})
|
13
|
-
result = Geocoder.search("74.200.247.59").first
|
14
|
-
assert result.is_a?(Geocoder::Result::Maxmind)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_maxmind_result_knows_country_service_name
|
18
|
-
Geocoder.configure(maxmind: {service: :country})
|
19
|
-
assert_equal :country, Geocoder.search("24.24.24.21").first.service_name
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_maxmind_result_knows_city_service_name
|
23
|
-
Geocoder.configure(maxmind: {service: :city})
|
24
|
-
assert_equal :city, Geocoder.search("24.24.24.22").first.service_name
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_maxmind_result_knows_city_isp_org_service_name
|
28
|
-
Geocoder.configure(maxmind: {service: :city_isp_org})
|
29
|
-
assert_equal :city_isp_org, Geocoder.search("24.24.24.23").first.service_name
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_maxmind_result_knows_omni_service_name
|
33
|
-
Geocoder.configure(maxmind: {service: :omni})
|
34
|
-
assert_equal :omni, Geocoder.search("24.24.24.24").first.service_name
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_maxmind_special_result_components
|
38
|
-
Geocoder.configure(maxmind: {service: :omni})
|
39
|
-
result = Geocoder.search("24.24.24.24").first
|
40
|
-
assert_equal "Road Runner", result.isp_name
|
41
|
-
assert_equal "Cable/DSL", result.netspeed
|
42
|
-
assert_equal "rr.com", result.domain
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_maxmind_raises_exception_when_service_not_configured
|
46
|
-
Geocoder.configure(maxmind: {service: nil})
|
47
|
-
assert_raises Geocoder::ConfigurationError do
|
48
|
-
Geocoder::Query.new("24.24.24.24").url
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_maxmind_works_when_loopback_address_on_omni
|
53
|
-
Geocoder.configure(maxmind: {service: :omni})
|
54
|
-
result = Geocoder.search("127.0.0.1").first
|
55
|
-
assert_equal "", result.country_code
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_maxmind_works_when_loopback_address_on_country
|
59
|
-
Geocoder.configure(maxmind: {service: :country})
|
60
|
-
result = Geocoder.search("127.0.0.1").first
|
61
|
-
assert_equal "", result.country_code
|
62
|
-
end
|
63
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class NominatimTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(lookup: :nominatim)
|
9
|
-
set_api_key!(:nominatim)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_result_components
|
13
|
-
result = Geocoder.search("Madison Square Garden, New York, NY").first
|
14
|
-
assert_equal "10001", result.postal_code
|
15
|
-
assert_equal "Madison Square Garden, West 31st Street, Long Island City, New York City, New York, 10001, United States of America", result.address
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_host_configuration
|
19
|
-
Geocoder.configure(nominatim: {host: "local.com"})
|
20
|
-
query = Geocoder::Query.new("Bluffton, SC")
|
21
|
-
assert_match %r(http://local\.com), query.url
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_raises_exception_when_over_query_limit
|
25
|
-
Geocoder.configure(:always_raise => [Geocoder::OverQueryLimitError])
|
26
|
-
l = Geocoder::Lookup.get(:nominatim)
|
27
|
-
assert_raises Geocoder::OverQueryLimitError do
|
28
|
-
l.send(:results, Geocoder::Query.new("over limit"))
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class OkfTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Geocoder.configure(lookup: :okf)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_okf_result_components
|
12
|
-
result = Geocoder.search("Kirstinmäki 11b28").first
|
13
|
-
assert_equal "Espoo",
|
14
|
-
result.address_components_of_type(:administrative_area_level_3).first['long_name']
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_okf_result_components_contains_route
|
18
|
-
result = Geocoder.search("Kirstinmäki 11b28").first
|
19
|
-
assert_equal "Kirstinmäki",
|
20
|
-
result.address_components_of_type(:route).first['long_name']
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_okf_result_components_contains_street_number
|
24
|
-
result = Geocoder.search("Kirstinmäki 11b28").first
|
25
|
-
assert_equal "1",
|
26
|
-
result.address_components_of_type(:street_number).first['long_name']
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_okf_street_address_returns_formatted_street_address
|
30
|
-
result = Geocoder.search("Kirstinmäki 11b28").first
|
31
|
-
assert_equal "Kirstinmäki 1", result.street_address
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_okf_precision
|
35
|
-
result = Geocoder.search("Kirstinmäki 11b28").first
|
36
|
-
assert_equal "RANGE_INTERPOLATED", result.precision
|
37
|
-
end
|
38
|
-
end
|