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
data/lib/geocoder/lookups/ovi.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'geocoder/lookups/base'
|
2
|
-
require 'geocoder/results/ovi'
|
3
|
-
|
4
|
-
module Geocoder::Lookup
|
5
|
-
class Ovi < Base
|
6
|
-
|
7
|
-
def name
|
8
|
-
"Ovi"
|
9
|
-
end
|
10
|
-
|
11
|
-
def required_api_key_parts
|
12
|
-
[]
|
13
|
-
end
|
14
|
-
|
15
|
-
def query_url(query)
|
16
|
-
"#{protocol}://lbs.ovi.com/search/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?" + url_query_string(query)
|
17
|
-
end
|
18
|
-
|
19
|
-
private # ---------------------------------------------------------------
|
20
|
-
|
21
|
-
def results(query)
|
22
|
-
return [] unless doc = fetch_data(query)
|
23
|
-
return [] unless doc['Response'] && doc['Response']['View']
|
24
|
-
if r=doc['Response']['View']
|
25
|
-
return [] if r.nil? || !r.is_a?(Array) || r.empty?
|
26
|
-
return r.first['Result']
|
27
|
-
end
|
28
|
-
[]
|
29
|
-
end
|
30
|
-
|
31
|
-
def query_url_params(query)
|
32
|
-
options = {
|
33
|
-
:gen=>1,
|
34
|
-
:app_id=>api_key,
|
35
|
-
:app_code=>api_code
|
36
|
-
}
|
37
|
-
|
38
|
-
if query.reverse_geocode?
|
39
|
-
super.merge(options).merge(
|
40
|
-
:prox=>query.sanitized_text,
|
41
|
-
:mode=>:retrieveAddresses
|
42
|
-
)
|
43
|
-
else
|
44
|
-
super.merge(options).merge(
|
45
|
-
:searchtext=>query.sanitized_text
|
46
|
-
)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def api_key
|
51
|
-
if a=configuration.api_key
|
52
|
-
return a.first if a.is_a?(Array)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def api_code
|
57
|
-
if a=configuration.api_key
|
58
|
-
return a.last if a.is_a?(Array)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'geocoder/lookups/base'
|
2
|
-
require "geocoder/results/yahoo"
|
3
|
-
require 'oauth_util'
|
4
|
-
|
5
|
-
module Geocoder::Lookup
|
6
|
-
class Yahoo < Base
|
7
|
-
|
8
|
-
def name
|
9
|
-
"Yahoo BOSS"
|
10
|
-
end
|
11
|
-
|
12
|
-
def map_link_url(coordinates)
|
13
|
-
"http://maps.yahoo.com/#lat=#{coordinates[0]}&lon=#{coordinates[1]}"
|
14
|
-
end
|
15
|
-
|
16
|
-
def required_api_key_parts
|
17
|
-
["consumer key", "consumer secret"]
|
18
|
-
end
|
19
|
-
|
20
|
-
def query_url(query)
|
21
|
-
parsed_url = URI.parse(raw_url(query))
|
22
|
-
o = OauthUtil.new
|
23
|
-
o.consumer_key = configuration.api_key[0]
|
24
|
-
o.consumer_secret = configuration.api_key[1]
|
25
|
-
base_url + o.sign(parsed_url).query_string
|
26
|
-
end
|
27
|
-
|
28
|
-
private # ---------------------------------------------------------------
|
29
|
-
|
30
|
-
def results(query)
|
31
|
-
return [] unless doc = fetch_data(query)
|
32
|
-
doc = doc['bossresponse']
|
33
|
-
if doc['responsecode'].to_i == 200
|
34
|
-
if doc['placefinder']['count'].to_i > 0
|
35
|
-
return doc['placefinder']['results']
|
36
|
-
else
|
37
|
-
return []
|
38
|
-
end
|
39
|
-
else
|
40
|
-
warn "Yahoo Geocoding API error: #{doc['responsecode']} (#{doc['reason']})."
|
41
|
-
return []
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
##
|
46
|
-
# Yahoo returns errors as XML even when JSON format is specified.
|
47
|
-
# Handle that here, without parsing the XML
|
48
|
-
# (which would add unnecessary complexity).
|
49
|
-
# Yahoo auth errors can also be cryptic, so add raw error desc
|
50
|
-
# to warning message.
|
51
|
-
#
|
52
|
-
def parse_raw_data(raw_data)
|
53
|
-
if raw_data.match(/^<\?xml/)
|
54
|
-
if raw_data.include?("Rate Limit Exceeded")
|
55
|
-
raise_error(Geocoder::OverQueryLimitError) || warn("Over API query limit.")
|
56
|
-
elsif raw_data =~ /<yahoo:description>(Please provide valid credentials.*)<\/yahoo:description>/i
|
57
|
-
raise_error(Geocoder::InvalidApiKey) || warn("Invalid API key. Error response: #{$1}")
|
58
|
-
end
|
59
|
-
else
|
60
|
-
super(raw_data)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def query_url_params(query)
|
65
|
-
lang = (query.language || configuration.language).to_s
|
66
|
-
lang += '_US' if lang == 'en'
|
67
|
-
{
|
68
|
-
:location => query.sanitized_text,
|
69
|
-
:flags => "JXTSR",
|
70
|
-
:gflags => "AC#{'R' if query.reverse_geocode?}",
|
71
|
-
:locale => lang,
|
72
|
-
:appid => configuration.api_key
|
73
|
-
}.merge(super)
|
74
|
-
end
|
75
|
-
|
76
|
-
def cache_key(query)
|
77
|
-
raw_url(query)
|
78
|
-
end
|
79
|
-
|
80
|
-
def base_url
|
81
|
-
"#{protocol}://yboss.yahooapis.com/geo/placefinder?"
|
82
|
-
end
|
83
|
-
|
84
|
-
def raw_url(query)
|
85
|
-
base_url + url_query_string(query)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'geocoder/results/base'
|
2
|
-
|
3
|
-
module Geocoder::Result
|
4
|
-
class GeocoderUs < Base
|
5
|
-
def coordinates
|
6
|
-
[@data[0].to_f, @data[1].to_f]
|
7
|
-
end
|
8
|
-
|
9
|
-
def address(format = :full)
|
10
|
-
"#{street_address}, #{city}, #{state} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
11
|
-
end
|
12
|
-
|
13
|
-
def street_address
|
14
|
-
@data[2]
|
15
|
-
end
|
16
|
-
|
17
|
-
def city
|
18
|
-
@data[3]
|
19
|
-
end
|
20
|
-
|
21
|
-
def state
|
22
|
-
@data[4]
|
23
|
-
end
|
24
|
-
|
25
|
-
alias_method :state_code, :state
|
26
|
-
|
27
|
-
def postal_code
|
28
|
-
@data[5]
|
29
|
-
end
|
30
|
-
|
31
|
-
def country
|
32
|
-
'United States'
|
33
|
-
end
|
34
|
-
|
35
|
-
def country_code
|
36
|
-
'US'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/geocoder/results/okf.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'geocoder/results/base'
|
2
|
-
|
3
|
-
module Geocoder::Result
|
4
|
-
class Okf < Base
|
5
|
-
|
6
|
-
def coordinates
|
7
|
-
['lat', 'lng'].map{ |i| geometry['location'][i] }
|
8
|
-
end
|
9
|
-
|
10
|
-
def address(format = :full)
|
11
|
-
formatted_address
|
12
|
-
end
|
13
|
-
|
14
|
-
def city
|
15
|
-
fields = [:locality, :sublocality,
|
16
|
-
:administrative_area_level_3,
|
17
|
-
:administrative_area_level_2]
|
18
|
-
fields.each do |f|
|
19
|
-
if entity = address_components_of_type(f).first
|
20
|
-
return entity['long_name']
|
21
|
-
end
|
22
|
-
end
|
23
|
-
return nil # no appropriate components found
|
24
|
-
end
|
25
|
-
|
26
|
-
def state
|
27
|
-
""
|
28
|
-
end
|
29
|
-
|
30
|
-
def sub_state
|
31
|
-
""
|
32
|
-
end
|
33
|
-
|
34
|
-
def state_code
|
35
|
-
""
|
36
|
-
end
|
37
|
-
|
38
|
-
def country
|
39
|
-
if country = address_components_of_type(:country).first
|
40
|
-
country['long_name']
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def country_code
|
45
|
-
if country = address_components_of_type(:country).first
|
46
|
-
country['short_name']
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def postal_code
|
51
|
-
if postal = address_components_of_type(:postal_code).first
|
52
|
-
postal['long_name']
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def route
|
57
|
-
if route = address_components_of_type(:route).first
|
58
|
-
route['long_name']
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def street_number
|
63
|
-
if street_number = address_components_of_type(:street_number).first
|
64
|
-
street_number['long_name']
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def street_address
|
69
|
-
[route, street_number].compact.join(' ')
|
70
|
-
end
|
71
|
-
|
72
|
-
def types
|
73
|
-
@data['types']
|
74
|
-
end
|
75
|
-
|
76
|
-
def formatted_address
|
77
|
-
@data['formatted_address']
|
78
|
-
end
|
79
|
-
|
80
|
-
def address_components
|
81
|
-
@data['address_components']
|
82
|
-
end
|
83
|
-
|
84
|
-
##
|
85
|
-
# Get address components of a given type. Valid types are defined in
|
86
|
-
# Google's Geocoding API documentation and include (among others):
|
87
|
-
#
|
88
|
-
# :street_number
|
89
|
-
# :locality
|
90
|
-
# :neighborhood
|
91
|
-
# :route
|
92
|
-
# :postal_code
|
93
|
-
#
|
94
|
-
def address_components_of_type(type)
|
95
|
-
address_components.select{ |c| c['types'].include?(type.to_s) }
|
96
|
-
end
|
97
|
-
|
98
|
-
def geometry
|
99
|
-
@data['geometry']
|
100
|
-
end
|
101
|
-
|
102
|
-
def precision
|
103
|
-
geometry['location_type'] if geometry
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
data/lib/geocoder/results/ovi.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'geocoder/results/base'
|
2
|
-
|
3
|
-
module Geocoder::Result
|
4
|
-
class Ovi < Base
|
5
|
-
|
6
|
-
##
|
7
|
-
# A string in the given format.
|
8
|
-
#
|
9
|
-
def address(format = :full)
|
10
|
-
address_data['Label']
|
11
|
-
end
|
12
|
-
|
13
|
-
##
|
14
|
-
# A two-element array: [lat, lon].
|
15
|
-
#
|
16
|
-
def coordinates
|
17
|
-
fail unless d = @data['Location']['DisplayPosition']
|
18
|
-
[d['Latitude'].to_f, d['Longitude'].to_f]
|
19
|
-
end
|
20
|
-
|
21
|
-
def state
|
22
|
-
address_data['County']
|
23
|
-
end
|
24
|
-
|
25
|
-
def province
|
26
|
-
address_data['County']
|
27
|
-
end
|
28
|
-
|
29
|
-
def postal_code
|
30
|
-
address_data['PostalCode']
|
31
|
-
end
|
32
|
-
|
33
|
-
def city
|
34
|
-
address_data['City']
|
35
|
-
end
|
36
|
-
|
37
|
-
def state_code
|
38
|
-
address_data['State']
|
39
|
-
end
|
40
|
-
|
41
|
-
def province_code
|
42
|
-
address_data['State']
|
43
|
-
end
|
44
|
-
|
45
|
-
def country
|
46
|
-
fail unless d = address_data['AdditionalData']
|
47
|
-
if v = d.find{|ad| ad['key']=='CountryName'}
|
48
|
-
return v['value']
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def country_code
|
53
|
-
address_data['Country']
|
54
|
-
end
|
55
|
-
|
56
|
-
private # ----------------------------------------------------------------
|
57
|
-
|
58
|
-
def address_data
|
59
|
-
@data['Location']['Address'] || fail
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'geocoder/results/base'
|
2
|
-
|
3
|
-
module Geocoder::Result
|
4
|
-
class Yahoo < Base
|
5
|
-
|
6
|
-
def address(format = :full)
|
7
|
-
(1..4).to_a.map{ |i| @data["line#{i}"] }.reject{ |i| i.nil? or i == "" }.join(", ")
|
8
|
-
end
|
9
|
-
|
10
|
-
def city
|
11
|
-
@data['city']
|
12
|
-
end
|
13
|
-
|
14
|
-
def state
|
15
|
-
@data['state']
|
16
|
-
end
|
17
|
-
|
18
|
-
def state_code
|
19
|
-
@data['statecode']
|
20
|
-
end
|
21
|
-
|
22
|
-
def country
|
23
|
-
@data['country']
|
24
|
-
end
|
25
|
-
|
26
|
-
def country_code
|
27
|
-
@data['countrycode']
|
28
|
-
end
|
29
|
-
|
30
|
-
def postal_code
|
31
|
-
@data['postal']
|
32
|
-
end
|
33
|
-
|
34
|
-
def address_hash
|
35
|
-
@data['hash']
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.response_attributes
|
39
|
-
%w[quality offsetlat offsetlon radius boundingbox name
|
40
|
-
line1 line2 line3 line4 cross house street xstreet unittype unit
|
41
|
-
city state statecode country countrycode postal
|
42
|
-
neighborhood county countycode
|
43
|
-
level0 level1 level2 level3 level4 level0code level1code level2code
|
44
|
-
timezone areacode uzip hash woeid woetype]
|
45
|
-
end
|
46
|
-
|
47
|
-
response_attributes.each do |a|
|
48
|
-
unless method_defined?(a)
|
49
|
-
define_method a do
|
50
|
-
@data[a]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/lib/oauth_util.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
# A utility for signing an url using OAuth in a way that's convenient for debugging
|
2
|
-
# Note: the standard Ruby OAuth lib is here http://github.com/mojodna/oauth
|
3
|
-
# Source: http://gist.github.com/383159
|
4
|
-
# License: http://gist.github.com/375593
|
5
|
-
# Usage: see example.rb below
|
6
|
-
#
|
7
|
-
# NOTE: This file has been modified from the original Gist:
|
8
|
-
#
|
9
|
-
# 1. Fix to prevent param-array conversion, as mentioned in Gist comment.
|
10
|
-
# 2. Query string escaping has been changed. See:
|
11
|
-
# https://github.com/alexreisner/geocoder/pull/360
|
12
|
-
#
|
13
|
-
|
14
|
-
require 'uri'
|
15
|
-
require 'cgi'
|
16
|
-
require 'openssl'
|
17
|
-
require 'base64'
|
18
|
-
|
19
|
-
class OauthUtil
|
20
|
-
|
21
|
-
attr_accessor :consumer_key, :consumer_secret, :token, :token_secret, :req_method,
|
22
|
-
:sig_method, :oauth_version, :callback_url, :params, :req_url, :base_str
|
23
|
-
|
24
|
-
def initialize
|
25
|
-
@consumer_key = ''
|
26
|
-
@consumer_secret = ''
|
27
|
-
@token = ''
|
28
|
-
@token_secret = ''
|
29
|
-
@req_method = 'GET'
|
30
|
-
@sig_method = 'HMAC-SHA1'
|
31
|
-
@oauth_version = '1.0'
|
32
|
-
@callback_url = ''
|
33
|
-
end
|
34
|
-
|
35
|
-
# openssl::random_bytes returns non-word chars, which need to be removed. using alt method to get length
|
36
|
-
# ref http://snippets.dzone.com/posts/show/491
|
37
|
-
def nonce
|
38
|
-
Array.new( 5 ) { rand(256) }.pack('C*').unpack('H*').first
|
39
|
-
end
|
40
|
-
|
41
|
-
def percent_encode( string )
|
42
|
-
|
43
|
-
# ref http://snippets.dzone.com/posts/show/1260
|
44
|
-
return URI.escape( string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]") ).gsub('*', '%2A')
|
45
|
-
end
|
46
|
-
|
47
|
-
# @ref http://oauth.net/core/1.0/#rfc.section.9.2
|
48
|
-
def signature
|
49
|
-
key = percent_encode( @consumer_secret ) + '&' + percent_encode( @token_secret )
|
50
|
-
|
51
|
-
# ref: http://blog.nathanielbibler.com/post/63031273/openssl-hmac-vs-ruby-hmac-benchmarks
|
52
|
-
digest = OpenSSL::Digest.new( 'sha1' )
|
53
|
-
hmac = OpenSSL::HMAC.digest( digest, key, @base_str )
|
54
|
-
|
55
|
-
# ref http://groups.google.com/group/oauth-ruby/browse_thread/thread/9110ed8c8f3cae81
|
56
|
-
Base64.encode64( hmac ).chomp.gsub( /\n/, '' )
|
57
|
-
end
|
58
|
-
|
59
|
-
# sort (very important as it affects the signature), concat, and percent encode
|
60
|
-
# @ref http://oauth.net/core/1.0/#rfc.section.9.1.1
|
61
|
-
# @ref http://oauth.net/core/1.0/#9.2.1
|
62
|
-
# @ref http://oauth.net/core/1.0/#rfc.section.A.5.1
|
63
|
-
def query_string
|
64
|
-
pairs = []
|
65
|
-
@params.sort.each { | key, val |
|
66
|
-
pairs.push( "#{ CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack('H*') } }=#{ CGI.escape(val.to_s) }" )
|
67
|
-
}
|
68
|
-
pairs.join '&'
|
69
|
-
end
|
70
|
-
|
71
|
-
# organize params & create signature
|
72
|
-
def sign( parsed_url )
|
73
|
-
|
74
|
-
@params = {
|
75
|
-
'oauth_consumer_key' => @consumer_key,
|
76
|
-
'oauth_nonce' => nonce,
|
77
|
-
'oauth_signature_method' => @sig_method,
|
78
|
-
'oauth_timestamp' => Time.now.to_i.to_s,
|
79
|
-
'oauth_version' => @oauth_version
|
80
|
-
}
|
81
|
-
|
82
|
-
# if url has query, merge key/values into params obj overwriting defaults
|
83
|
-
if parsed_url.query
|
84
|
-
CGI.parse( parsed_url.query ).each do |k,v|
|
85
|
-
if v.is_a?(Array) && v.count == 1
|
86
|
-
@params[k] = v.first
|
87
|
-
else
|
88
|
-
@params[k] = v
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# @ref http://oauth.net/core/1.0/#rfc.section.9.1.2
|
94
|
-
@req_url = parsed_url.scheme + '://' + parsed_url.host + parsed_url.path
|
95
|
-
|
96
|
-
# create base str. make it an object attr for ez debugging
|
97
|
-
# ref http://oauth.net/core/1.0/#anchor14
|
98
|
-
@base_str = [
|
99
|
-
@req_method,
|
100
|
-
percent_encode( req_url ),
|
101
|
-
|
102
|
-
# normalization is just x-www-form-urlencoded
|
103
|
-
percent_encode( query_string )
|
104
|
-
|
105
|
-
].join( '&' )
|
106
|
-
|
107
|
-
# add signature
|
108
|
-
@params[ 'oauth_signature' ] = signature
|
109
|
-
|
110
|
-
return self
|
111
|
-
end
|
112
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
{"results":[],"status":5,"msg":"AK Illegal or Not Exist:"}
|
@@ -1,19 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"address": "CN|北京|北京|None|CHINANET|1|None",
|
3
|
-
"content": {
|
4
|
-
"address": "北京市",
|
5
|
-
"address_detail": {
|
6
|
-
"city": "北京市",
|
7
|
-
"city_code": 131,
|
8
|
-
"district": "",
|
9
|
-
"province": "北京市",
|
10
|
-
"street": "",
|
11
|
-
"street_number": ""
|
12
|
-
},
|
13
|
-
"point": {
|
14
|
-
"x": "116.39564504",
|
15
|
-
"y": "39.92998578"
|
16
|
-
}
|
17
|
-
},
|
18
|
-
"status": 0
|
19
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":5,"uid":null,"sk":null,"logformat":null}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0, "content":{}}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"result":[]}
|
data/test/fixtures/baidu_reverse
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"result":{"location":{"lng":121.48789948569,"lat":31.249161555654},"formatted_address":"上海市闸北区天潼路619号","business":"七浦路,海宁路,北京东路","addressComponent":{"city":"上海市","district":"闸北区","province":"上海市","street":"天潼路","street_number":"619号"},"cityCode":289}}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"authenticationResultCode":"InvalidCredentials","brandLogoUri":"http:\\/\\/dev.virtualearth.net\\/Branding\\/logo_powered_by.png","copyright":"Copyright \xC2\xA9 2012 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","errorDetails":["Access was denied. You may have entered your credentials incorrectly, or you might not have access to the requested resource or operation."],"resourceSets":[],"statusCode":401,"statusDescription":"Unauthorized","traceId":"5c539f6e70c44b2e858741b6c932318e|EWRM001670|02.00.83.1900|"}
|
@@ -1,40 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"authenticationResultCode":"ValidCredentials",
|
3
|
-
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
|
4
|
-
"copyright":"Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
|
5
|
-
"resourceSets":[
|
6
|
-
{
|
7
|
-
"estimatedTotal":1,
|
8
|
-
"resources":[
|
9
|
-
{
|
10
|
-
"__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1",
|
11
|
-
"bbox":[
|
12
|
-
40.744944289326668,
|
13
|
-
-74.002353921532631,
|
14
|
-
40.755675807595253,
|
15
|
-
-73.983625397086143
|
16
|
-
],
|
17
|
-
"name":"Madison Square Garden, NY",
|
18
|
-
"point":{
|
19
|
-
"type":"Point",
|
20
|
-
"coordinates":[
|
21
|
-
40.75031,
|
22
|
-
-73.99299
|
23
|
-
]
|
24
|
-
},
|
25
|
-
"address":{
|
26
|
-
"adminDistrict":"NY",
|
27
|
-
"countryRegion":"United States",
|
28
|
-
"formattedAddress":"Madison Square Garden, NY",
|
29
|
-
"locality":"New York"
|
30
|
-
},
|
31
|
-
"confidence":"High",
|
32
|
-
"entityType":"Stadium"
|
33
|
-
}
|
34
|
-
]
|
35
|
-
}
|
36
|
-
],
|
37
|
-
"statusCode":200,
|
38
|
-
"statusDescription":"OK",
|
39
|
-
"traceId":"55094ee53c8d45e789794014666328cd|CH1M001466|02.00.82.2800|CH1MSNVM001396, CH1MSNVM001370, CH1MSNVM001397"
|
40
|
-
}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"authenticationResultCode":"ValidCredentials",
|
3
|
-
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
|
4
|
-
"copyright":"Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
|
5
|
-
"resourceSets":[
|
6
|
-
{
|
7
|
-
"estimatedTotal":0,
|
8
|
-
"resources":[
|
9
|
-
|
10
|
-
]
|
11
|
-
}
|
12
|
-
],
|
13
|
-
"statusCode":200,
|
14
|
-
"statusDescription":"OK",
|
15
|
-
"traceId":"907b76a307bc49129a489de3d4c992ea|CH1M001463|02.00.82.2800|CH1MSNVM001383, CH1MSNVM001358, CH1MSNVM001397"
|
16
|
-
}
|
data/test/fixtures/bing_reverse
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"authenticationResultCode":"ValidCredentials",
|
3
|
-
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
|
4
|
-
"copyright":"Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
|
5
|
-
"resourceSets":[
|
6
|
-
{
|
7
|
-
"estimatedTotal":1,
|
8
|
-
"resources":[
|
9
|
-
{
|
10
|
-
"__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1",
|
11
|
-
"bbox":[
|
12
|
-
45.419835111675845,
|
13
|
-
-75.683656128790716,
|
14
|
-
45.4275605468172,
|
15
|
-
-75.66898098334994
|
16
|
-
],
|
17
|
-
"name":"291 Rue Somerset E, Ottawa, ON, K1N",
|
18
|
-
"point":{
|
19
|
-
"type":"Point",
|
20
|
-
"coordinates":[
|
21
|
-
45.423697829246521,
|
22
|
-
-75.676318556070328
|
23
|
-
]
|
24
|
-
},
|
25
|
-
"address":{
|
26
|
-
"addressLine":"291 Rue Somerset E",
|
27
|
-
"adminDistrict":"ON",
|
28
|
-
"countryRegion":"Canada",
|
29
|
-
"formattedAddress":"291 Rue Somerset E, Ottawa, ON, K1N",
|
30
|
-
"locality":"Ottawa",
|
31
|
-
"postalCode":"K1N"
|
32
|
-
},
|
33
|
-
"confidence":"Medium",
|
34
|
-
"entityType":"Address"
|
35
|
-
}
|
36
|
-
]
|
37
|
-
}
|
38
|
-
],
|
39
|
-
"statusCode":200,
|
40
|
-
"statusDescription":"OK",
|
41
|
-
"traceId":"27bd5ed659e64ba6970c4144f1d4ea94|CH1M001470|02.00.82.2800|CH1MSNVM001396, CH1MSNVM001374"
|
42
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
Forbidden request
|