broken-geocoder 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +467 -0
- data/LICENSE +20 -0
- data/README.md +1193 -0
- data/bin/geocode +5 -0
- data/examples/autoexpire_cache_dalli.rb +62 -0
- data/examples/autoexpire_cache_redis.rb +28 -0
- data/examples/cache_bypass.rb +48 -0
- data/examples/reverse_geocode_job.rb +40 -0
- data/lib/generators/geocoder/config/config_generator.rb +14 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +21 -0
- data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +28 -0
- data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +28 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +30 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +17 -0
- data/lib/geocoder.rb +48 -0
- data/lib/geocoder/cache.rb +90 -0
- data/lib/geocoder/calculations.rb +431 -0
- data/lib/geocoder/cli.rb +121 -0
- data/lib/geocoder/configuration.rb +129 -0
- data/lib/geocoder/configuration_hash.rb +11 -0
- data/lib/geocoder/esri_token.rb +38 -0
- data/lib/geocoder/exceptions.rb +37 -0
- data/lib/geocoder/ip_address.rb +13 -0
- data/lib/geocoder/kernel_logger.rb +25 -0
- data/lib/geocoder/logger.rb +47 -0
- data/lib/geocoder/lookup.rb +110 -0
- data/lib/geocoder/lookups/baidu.rb +59 -0
- data/lib/geocoder/lookups/baidu_ip.rb +59 -0
- data/lib/geocoder/lookups/base.rb +325 -0
- data/lib/geocoder/lookups/bing.rb +80 -0
- data/lib/geocoder/lookups/dstk.rb +20 -0
- data/lib/geocoder/lookups/esri.rb +64 -0
- data/lib/geocoder/lookups/freegeoip.rb +51 -0
- data/lib/geocoder/lookups/geocoder_ca.rb +53 -0
- data/lib/geocoder/lookups/geocoder_us.rb +43 -0
- data/lib/geocoder/lookups/geocodio.rb +42 -0
- data/lib/geocoder/lookups/geoip2.rb +45 -0
- data/lib/geocoder/lookups/geoportail_lu.rb +65 -0
- data/lib/geocoder/lookups/google.rb +91 -0
- data/lib/geocoder/lookups/google_places_details.rb +50 -0
- data/lib/geocoder/lookups/google_premier.rb +47 -0
- data/lib/geocoder/lookups/here.rb +62 -0
- data/lib/geocoder/lookups/ipapi_com.rb +86 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +55 -0
- data/lib/geocoder/lookups/latlon.rb +59 -0
- data/lib/geocoder/lookups/mapbox.rb +53 -0
- data/lib/geocoder/lookups/mapquest.rb +59 -0
- data/lib/geocoder/lookups/mapzen.rb +15 -0
- data/lib/geocoder/lookups/maxmind.rb +90 -0
- data/lib/geocoder/lookups/maxmind_geoip2.rb +69 -0
- data/lib/geocoder/lookups/maxmind_local.rb +65 -0
- data/lib/geocoder/lookups/nominatim.rb +52 -0
- data/lib/geocoder/lookups/okf.rb +44 -0
- data/lib/geocoder/lookups/opencagedata.rb +58 -0
- data/lib/geocoder/lookups/ovi.rb +62 -0
- data/lib/geocoder/lookups/pelias.rb +64 -0
- data/lib/geocoder/lookups/pointpin.rb +68 -0
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +51 -0
- data/lib/geocoder/lookups/smarty_streets.rb +50 -0
- data/lib/geocoder/lookups/telize.rb +55 -0
- data/lib/geocoder/lookups/test.rb +44 -0
- data/lib/geocoder/lookups/yandex.rb +58 -0
- data/lib/geocoder/models/active_record.rb +50 -0
- data/lib/geocoder/models/base.rb +39 -0
- data/lib/geocoder/models/mongo_base.rb +62 -0
- data/lib/geocoder/models/mongo_mapper.rb +26 -0
- data/lib/geocoder/models/mongoid.rb +32 -0
- data/lib/geocoder/query.rb +111 -0
- data/lib/geocoder/railtie.rb +26 -0
- data/lib/geocoder/request.rb +83 -0
- data/lib/geocoder/results/baidu.rb +79 -0
- data/lib/geocoder/results/baidu_ip.rb +62 -0
- data/lib/geocoder/results/base.rb +67 -0
- data/lib/geocoder/results/bing.rb +52 -0
- data/lib/geocoder/results/dstk.rb +6 -0
- data/lib/geocoder/results/esri.rb +75 -0
- data/lib/geocoder/results/freegeoip.rb +45 -0
- data/lib/geocoder/results/geocoder_ca.rb +60 -0
- data/lib/geocoder/results/geocoder_us.rb +39 -0
- data/lib/geocoder/results/geocodio.rb +70 -0
- data/lib/geocoder/results/geoip2.rb +62 -0
- data/lib/geocoder/results/geoportail_lu.rb +69 -0
- data/lib/geocoder/results/google.rb +139 -0
- data/lib/geocoder/results/google_places_details.rb +35 -0
- data/lib/geocoder/results/google_premier.rb +6 -0
- data/lib/geocoder/results/here.rb +71 -0
- data/lib/geocoder/results/ipapi_com.rb +45 -0
- data/lib/geocoder/results/ipinfo_io.rb +48 -0
- data/lib/geocoder/results/latlon.rb +71 -0
- data/lib/geocoder/results/mapbox.rb +47 -0
- data/lib/geocoder/results/mapquest.rb +48 -0
- data/lib/geocoder/results/mapzen.rb +5 -0
- data/lib/geocoder/results/maxmind.rb +135 -0
- data/lib/geocoder/results/maxmind_geoip2.rb +9 -0
- data/lib/geocoder/results/maxmind_local.rb +49 -0
- data/lib/geocoder/results/nominatim.rb +99 -0
- data/lib/geocoder/results/okf.rb +106 -0
- data/lib/geocoder/results/opencagedata.rb +90 -0
- data/lib/geocoder/results/ovi.rb +71 -0
- data/lib/geocoder/results/pelias.rb +58 -0
- data/lib/geocoder/results/pointpin.rb +40 -0
- data/lib/geocoder/results/postcode_anywhere_uk.rb +42 -0
- data/lib/geocoder/results/smarty_streets.rb +106 -0
- data/lib/geocoder/results/telize.rb +45 -0
- data/lib/geocoder/results/test.rb +33 -0
- data/lib/geocoder/results/yandex.rb +92 -0
- data/lib/geocoder/sql.rb +107 -0
- data/lib/geocoder/stores/active_record.rb +305 -0
- data/lib/geocoder/stores/base.rb +116 -0
- data/lib/geocoder/stores/mongo_base.rb +58 -0
- data/lib/geocoder/stores/mongo_mapper.rb +13 -0
- data/lib/geocoder/stores/mongoid.rb +13 -0
- data/lib/geocoder/version.rb +3 -0
- data/lib/hash_recursive_merge.rb +74 -0
- data/lib/maxmind_database.rb +109 -0
- data/lib/tasks/geocoder.rake +38 -0
- data/lib/tasks/maxmind.rake +73 -0
- metadata +167 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder
|
4
|
+
module Result
|
5
|
+
class Geoip2 < Base
|
6
|
+
def address(format = :full)
|
7
|
+
s = state.to_s == '' ? '' : ", #{state_code}"
|
8
|
+
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '')
|
9
|
+
end
|
10
|
+
|
11
|
+
def coordinates
|
12
|
+
%w[latitude longitude].map do |l|
|
13
|
+
data.fetch('location', {}).fetch(l, 0.0)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def city
|
18
|
+
data.fetch('city', {}).fetch('names', {}).fetch(locale, '')
|
19
|
+
end
|
20
|
+
|
21
|
+
def state
|
22
|
+
data.fetch('subdivisions', []).fetch(0, {}).fetch('names', {}).fetch(locale, '')
|
23
|
+
end
|
24
|
+
|
25
|
+
def state_code
|
26
|
+
data.fetch('subdivisions', []).fetch(0, {}).fetch('iso_code', '')
|
27
|
+
end
|
28
|
+
|
29
|
+
def country
|
30
|
+
data.fetch('country', {}).fetch('names', {}).fetch(locale, '')
|
31
|
+
end
|
32
|
+
|
33
|
+
def country_code
|
34
|
+
data.fetch('country', {}).fetch('iso_code', '')
|
35
|
+
end
|
36
|
+
|
37
|
+
def postal_code
|
38
|
+
data.fetch('postal', {}).fetch('code', '')
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.response_attributes
|
42
|
+
%w[ip]
|
43
|
+
end
|
44
|
+
|
45
|
+
response_attributes.each do |a|
|
46
|
+
define_method a do
|
47
|
+
@data[a]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def data
|
54
|
+
@data.to_hash
|
55
|
+
end
|
56
|
+
|
57
|
+
def locale
|
58
|
+
@locale ||= Geocoder.config[:language].to_s
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class GeoportailLu < Base
|
5
|
+
|
6
|
+
def coordinates
|
7
|
+
geomlonlat['coordinates'].reverse if geolocalized?
|
8
|
+
end
|
9
|
+
|
10
|
+
def address
|
11
|
+
full_address
|
12
|
+
end
|
13
|
+
|
14
|
+
def city
|
15
|
+
try_to_extract 'locality', detailled_address
|
16
|
+
end
|
17
|
+
|
18
|
+
def state
|
19
|
+
'Luxembourg'
|
20
|
+
end
|
21
|
+
|
22
|
+
def state_code
|
23
|
+
'LU'
|
24
|
+
end
|
25
|
+
|
26
|
+
def postal_code
|
27
|
+
try_to_extract 'zip', detailled_address
|
28
|
+
end
|
29
|
+
|
30
|
+
def street_address
|
31
|
+
[street_number, street].compact.join(' ')
|
32
|
+
end
|
33
|
+
|
34
|
+
def street_number
|
35
|
+
try_to_extract 'postnumber', detailled_address
|
36
|
+
end
|
37
|
+
|
38
|
+
def street
|
39
|
+
try_to_extract 'street', detailled_address
|
40
|
+
end
|
41
|
+
|
42
|
+
def full_address
|
43
|
+
data['address']
|
44
|
+
end
|
45
|
+
|
46
|
+
def geomlonlat
|
47
|
+
data['geomlonlat']
|
48
|
+
end
|
49
|
+
|
50
|
+
def detailled_address
|
51
|
+
data['AddressDetails']
|
52
|
+
end
|
53
|
+
|
54
|
+
alias_method :country, :state
|
55
|
+
alias_method :province, :state
|
56
|
+
alias_method :country_code, :state_code
|
57
|
+
alias_method :province_code, :state_code
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def geolocalized?
|
62
|
+
try_to_extract('coordinates', geomlonlat).present?
|
63
|
+
end
|
64
|
+
|
65
|
+
def try_to_extract(key, nullable_hash)
|
66
|
+
nullable_hash.try(:[], key)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Google < Base
|
5
|
+
|
6
|
+
def coordinates
|
7
|
+
['lat', 'lng'].map{ |i| geometry['location'][i] }
|
8
|
+
end
|
9
|
+
|
10
|
+
def address(format = :full)
|
11
|
+
formatted_adadress
|
12
|
+
end
|
13
|
+
|
14
|
+
def neighborhood
|
15
|
+
if neighborhood = address_components_of_type(:neighborhood).first
|
16
|
+
neighborhood['long_name']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def city
|
21
|
+
fields = [:locality, :sublocality,
|
22
|
+
:administrative_area_level_3,
|
23
|
+
:administrative_area_level_2]
|
24
|
+
fields.each do |f|
|
25
|
+
if entity = address_components_of_type(f).first
|
26
|
+
return entity['long_name']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
return nil # no appropriate components found
|
30
|
+
end
|
31
|
+
|
32
|
+
def state
|
33
|
+
if state = address_components_of_type(:administrative_area_level_1).first
|
34
|
+
state['long_name']
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def state_code
|
39
|
+
if state = address_components_of_type(:administrative_area_level_1).first
|
40
|
+
state['short_name']
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def sub_state
|
45
|
+
if state = address_components_of_type(:administrative_area_level_2).first
|
46
|
+
state['long_name']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def sub_state_code
|
51
|
+
if state = address_components_of_type(:administrative_area_level_2).first
|
52
|
+
state['short_name']
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def country
|
57
|
+
if country = address_components_of_type(:country).first
|
58
|
+
country['long_name']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def country_code
|
63
|
+
if country = address_components_of_type(:country).first
|
64
|
+
country['short_name']
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def postal_code
|
69
|
+
if postal = address_components_of_type(:postal_code).first
|
70
|
+
postal['long_name']
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def route
|
75
|
+
if route = address_components_of_type(:route).first
|
76
|
+
route['long_name']
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def street_number
|
81
|
+
if street_number = address_components_of_type(:street_number).first
|
82
|
+
street_number['long_name']
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def street_address
|
87
|
+
[street_number, route].compact.join(' ')
|
88
|
+
end
|
89
|
+
|
90
|
+
def types
|
91
|
+
@data['types']
|
92
|
+
end
|
93
|
+
|
94
|
+
def formatted_address
|
95
|
+
@data['formatted_address']
|
96
|
+
end
|
97
|
+
|
98
|
+
def address_components
|
99
|
+
@data['address_components']
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# Get address components of a given type. Valid types are defined in
|
104
|
+
# Google's Geocoding API documentation and include (among others):
|
105
|
+
#
|
106
|
+
# :street_number
|
107
|
+
# :locality
|
108
|
+
# :neighborhood
|
109
|
+
# :route
|
110
|
+
# :postal_code
|
111
|
+
#
|
112
|
+
def address_components_of_type(type)
|
113
|
+
address_components.select{ |c| c['types'].include?(type.to_s) }
|
114
|
+
end
|
115
|
+
|
116
|
+
def geometry
|
117
|
+
@data['geometry']
|
118
|
+
end
|
119
|
+
|
120
|
+
def precision
|
121
|
+
geometry['location_type'] if geometry
|
122
|
+
end
|
123
|
+
|
124
|
+
def partial_match
|
125
|
+
@data['partial_match']
|
126
|
+
end
|
127
|
+
|
128
|
+
def place_id
|
129
|
+
@data['place_id']
|
130
|
+
end
|
131
|
+
|
132
|
+
def viewport
|
133
|
+
viewport = geometry['viewport'] || fail
|
134
|
+
south, west = %w(lat lng).map { |c| viewport['southwest'][c] }
|
135
|
+
north, east = %w(lat lng).map { |c| viewport['northeast'][c] }
|
136
|
+
[south, west, north, east]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "geocoder/results/google"
|
2
|
+
|
3
|
+
module Geocoder
|
4
|
+
module Result
|
5
|
+
class GooglePlacesDetails < Google
|
6
|
+
def place_id
|
7
|
+
@data["place_id"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def types
|
11
|
+
@data["types"] || []
|
12
|
+
end
|
13
|
+
|
14
|
+
def reviews
|
15
|
+
@data["reviews"] || []
|
16
|
+
end
|
17
|
+
|
18
|
+
def rating
|
19
|
+
@data["rating"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def rating_count
|
23
|
+
@data["user_ratings_total"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def phone_number
|
27
|
+
@data["international_phone_number"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def website
|
31
|
+
@data["website"]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Here < 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
|
+
def viewport
|
57
|
+
map_view = data['Location']['MapView'] || fail
|
58
|
+
south = map_view['BottomRight']['Latitude']
|
59
|
+
west = map_view['TopLeft']['Longitude']
|
60
|
+
north = map_view['TopLeft']['Latitude']
|
61
|
+
east = map_view['BottomRight']['Longitude']
|
62
|
+
[south, west, north, east]
|
63
|
+
end
|
64
|
+
|
65
|
+
private # ----------------------------------------------------------------
|
66
|
+
|
67
|
+
def address_data
|
68
|
+
@data['Location']['Address'] || fail
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class IpapiCom < Base
|
5
|
+
|
6
|
+
def coordinates
|
7
|
+
[lat, lon]
|
8
|
+
end
|
9
|
+
|
10
|
+
def address
|
11
|
+
"#{city}, #{state_code} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
12
|
+
end
|
13
|
+
|
14
|
+
def state
|
15
|
+
region_name
|
16
|
+
end
|
17
|
+
|
18
|
+
def state_code
|
19
|
+
region
|
20
|
+
end
|
21
|
+
|
22
|
+
def postal_code
|
23
|
+
zip
|
24
|
+
end
|
25
|
+
|
26
|
+
def country_code
|
27
|
+
@data['countryCode']
|
28
|
+
end
|
29
|
+
|
30
|
+
def region_name
|
31
|
+
@data['regionName']
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.response_attributes
|
35
|
+
%w[country region city zip timezone isp org as reverse query status message mobile proxy lat lon]
|
36
|
+
end
|
37
|
+
|
38
|
+
response_attributes.each do |attribute|
|
39
|
+
define_method attribute do
|
40
|
+
@data[attribute]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class IpinfoIo < Base
|
5
|
+
|
6
|
+
def address(format = :full)
|
7
|
+
"#{city} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
8
|
+
end
|
9
|
+
|
10
|
+
def coordinates
|
11
|
+
@data['loc'].split(",").map(&:to_f)
|
12
|
+
end
|
13
|
+
|
14
|
+
def city
|
15
|
+
@data['city']
|
16
|
+
end
|
17
|
+
|
18
|
+
def state
|
19
|
+
@data['region']
|
20
|
+
end
|
21
|
+
|
22
|
+
def country
|
23
|
+
@data['country']
|
24
|
+
end
|
25
|
+
|
26
|
+
def postal_code
|
27
|
+
@data['postal']
|
28
|
+
end
|
29
|
+
|
30
|
+
def country_code
|
31
|
+
@data.fetch('country', '')
|
32
|
+
end
|
33
|
+
|
34
|
+
def state_code
|
35
|
+
@data.fetch('region_code', '')
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.response_attributes
|
39
|
+
%w['ip', 'region', 'postal']
|
40
|
+
end
|
41
|
+
|
42
|
+
response_attributes.each do |a|
|
43
|
+
define_method a do
|
44
|
+
@data[a]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|