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,71 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Latlon < Base
|
5
|
+
|
6
|
+
def city
|
7
|
+
address_components["city"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def coordinates
|
11
|
+
[@data['lat'].to_f, @data['lon'].to_f]
|
12
|
+
end
|
13
|
+
|
14
|
+
def country
|
15
|
+
"United States" # LatLon.io only supports the US
|
16
|
+
end
|
17
|
+
|
18
|
+
def country_code
|
19
|
+
"US" # LatLon.io only supports the US
|
20
|
+
end
|
21
|
+
|
22
|
+
def formatted_address(format = :full)
|
23
|
+
address_components["address"]
|
24
|
+
end
|
25
|
+
alias_method :address, :formatted_address
|
26
|
+
|
27
|
+
def number
|
28
|
+
address_components["number"]
|
29
|
+
end
|
30
|
+
|
31
|
+
def prefix
|
32
|
+
address_components["prefix"]
|
33
|
+
end
|
34
|
+
|
35
|
+
def state
|
36
|
+
address_components["state"]
|
37
|
+
end
|
38
|
+
alias_method :state_code, :state
|
39
|
+
|
40
|
+
def street
|
41
|
+
[street_name, street_type].compact.join(' ')
|
42
|
+
end
|
43
|
+
|
44
|
+
def street_name
|
45
|
+
address_components["street_name"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def street_type
|
49
|
+
address_components["street_type"]
|
50
|
+
end
|
51
|
+
|
52
|
+
def suffix
|
53
|
+
address_components["suffix"]
|
54
|
+
end
|
55
|
+
|
56
|
+
def unit
|
57
|
+
address_components["unit"]
|
58
|
+
end
|
59
|
+
|
60
|
+
def zip
|
61
|
+
address_components["zip"]
|
62
|
+
end
|
63
|
+
alias_method :postal_code, :zip
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def address_components
|
68
|
+
@data["address"] || {}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Mapbox < Base
|
5
|
+
|
6
|
+
def coordinates
|
7
|
+
@data["geometry"]["coordinates"].reverse.map(&:to_f)
|
8
|
+
end
|
9
|
+
|
10
|
+
def place_name
|
11
|
+
@data['text']
|
12
|
+
end
|
13
|
+
|
14
|
+
def street
|
15
|
+
@data['properties']['address']
|
16
|
+
end
|
17
|
+
|
18
|
+
def city
|
19
|
+
@data['context'].map { |c| c['text'] if c['id'] =~ /place/ }.compact.first
|
20
|
+
end
|
21
|
+
|
22
|
+
def state
|
23
|
+
@data['context'].map { |c| c['text'] if c['id'] =~ /region/ }.compact.first
|
24
|
+
end
|
25
|
+
|
26
|
+
alias_method :state_code, :state
|
27
|
+
|
28
|
+
def postal_code
|
29
|
+
@data['context'].map { |c| c['text'] if c['id'] =~ /postcode/ }.compact.first
|
30
|
+
end
|
31
|
+
|
32
|
+
def country
|
33
|
+
@data['context'].map { |c| c['text'] if c['id'] =~ /country/ }.compact.first
|
34
|
+
end
|
35
|
+
|
36
|
+
alias_method :country_code, :country
|
37
|
+
|
38
|
+
def neighborhood
|
39
|
+
@data['context'].map { |c| c['text'] if c['id'] =~ /neighborhood/ }.compact.first
|
40
|
+
end
|
41
|
+
|
42
|
+
def address
|
43
|
+
[place_name, street, city, state, postal_code, country].compact.join(", ")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Mapquest < Base
|
5
|
+
|
6
|
+
def coordinates
|
7
|
+
%w[lat lng].map{ |l| @data["latLng"][l] }
|
8
|
+
end
|
9
|
+
|
10
|
+
def city
|
11
|
+
@data['adminArea5']
|
12
|
+
end
|
13
|
+
|
14
|
+
def street
|
15
|
+
@data['street']
|
16
|
+
end
|
17
|
+
|
18
|
+
def state
|
19
|
+
@data['adminArea3']
|
20
|
+
end
|
21
|
+
|
22
|
+
def county
|
23
|
+
@data['adminArea4']
|
24
|
+
end
|
25
|
+
|
26
|
+
alias_method :state_code, :state
|
27
|
+
|
28
|
+
#FIXME: these might not be right, unclear with MQ documentation
|
29
|
+
alias_method :province, :state
|
30
|
+
alias_method :province_code, :state
|
31
|
+
|
32
|
+
def postal_code
|
33
|
+
@data['postalCode'].to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def country
|
37
|
+
@data['adminArea1']
|
38
|
+
end
|
39
|
+
|
40
|
+
def country_code
|
41
|
+
country
|
42
|
+
end
|
43
|
+
|
44
|
+
def address
|
45
|
+
[street, city, state, postal_code, country].reject{|s| s.length == 0 }.join(", ")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Maxmind < Base
|
5
|
+
|
6
|
+
##
|
7
|
+
# Hash mapping service names to names of returned fields.
|
8
|
+
#
|
9
|
+
def self.field_names
|
10
|
+
{
|
11
|
+
:country => [
|
12
|
+
:country_code,
|
13
|
+
:error
|
14
|
+
],
|
15
|
+
|
16
|
+
:city => [
|
17
|
+
:country_code,
|
18
|
+
:region_code,
|
19
|
+
:city_name,
|
20
|
+
:latitude,
|
21
|
+
:longitude,
|
22
|
+
:error
|
23
|
+
],
|
24
|
+
|
25
|
+
:city_isp_org => [
|
26
|
+
:country_code,
|
27
|
+
:region_code,
|
28
|
+
:city_name,
|
29
|
+
:postal_code,
|
30
|
+
:latitude,
|
31
|
+
:longitude,
|
32
|
+
:metro_code,
|
33
|
+
:area_code,
|
34
|
+
:isp_name,
|
35
|
+
:organization_name,
|
36
|
+
:error
|
37
|
+
],
|
38
|
+
|
39
|
+
:omni => [
|
40
|
+
:country_code,
|
41
|
+
:country_name,
|
42
|
+
:region_code,
|
43
|
+
:region_name,
|
44
|
+
:city_name,
|
45
|
+
:latitude,
|
46
|
+
:longitude,
|
47
|
+
:metro_code,
|
48
|
+
:area_code,
|
49
|
+
:time_zone,
|
50
|
+
:continent_code,
|
51
|
+
:postal_code,
|
52
|
+
:isp_name,
|
53
|
+
:organization_name,
|
54
|
+
:domain,
|
55
|
+
:as_number,
|
56
|
+
:netspeed,
|
57
|
+
:user_type,
|
58
|
+
:accuracy_radius,
|
59
|
+
:country_confidence_factor,
|
60
|
+
:city_confidence_factor,
|
61
|
+
:region_confidence_factor,
|
62
|
+
:postal_confidence_factor,
|
63
|
+
:error
|
64
|
+
]
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Name of the MaxMind service being used.
|
70
|
+
#
|
71
|
+
def service_name
|
72
|
+
# it would be much better to infer this from the length of the @data
|
73
|
+
# array, but MaxMind seems to send inconsistent and wide-ranging response
|
74
|
+
# lengths (see https://github.com/alexreisner/geocoder/issues/396)
|
75
|
+
Geocoder.config.maxmind[:service]
|
76
|
+
end
|
77
|
+
|
78
|
+
def field_names
|
79
|
+
self.class.field_names[service_name]
|
80
|
+
end
|
81
|
+
|
82
|
+
def data_hash
|
83
|
+
@data_hash ||= Hash[*field_names.zip(@data).flatten]
|
84
|
+
end
|
85
|
+
|
86
|
+
def coordinates
|
87
|
+
[data_hash[:latitude].to_f, data_hash[:longitude].to_f]
|
88
|
+
end
|
89
|
+
|
90
|
+
def address(format = :full)
|
91
|
+
s = state_code.to_s == "" ? "" : ", #{state_code}"
|
92
|
+
"#{city}#{s} #{postal_code}, #{country_code}".sub(/^[ ,]*/, "")
|
93
|
+
end
|
94
|
+
|
95
|
+
def city
|
96
|
+
data_hash[:city_name]
|
97
|
+
end
|
98
|
+
|
99
|
+
def state # not given by MaxMind
|
100
|
+
data_hash[:region_name] || data_hash[:region_code]
|
101
|
+
end
|
102
|
+
|
103
|
+
def state_code
|
104
|
+
data_hash[:region_code]
|
105
|
+
end
|
106
|
+
|
107
|
+
def country #not given by MaxMind
|
108
|
+
data_hash[:country_name] || data_hash[:country_code]
|
109
|
+
end
|
110
|
+
|
111
|
+
def country_code
|
112
|
+
data_hash[:country_code]
|
113
|
+
end
|
114
|
+
|
115
|
+
def postal_code
|
116
|
+
data_hash[:postal_code]
|
117
|
+
end
|
118
|
+
|
119
|
+
def method_missing(method, *args, &block)
|
120
|
+
if field_names.include?(method)
|
121
|
+
data_hash[method]
|
122
|
+
else
|
123
|
+
super
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def respond_to?(method)
|
128
|
+
if field_names.include?(method)
|
129
|
+
true
|
130
|
+
else
|
131
|
+
super
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'geocoder/results/geoip2'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class MaxmindGeoip2 < Geoip2
|
5
|
+
# MindmindGeoip2 has the same results as Geoip2 because both are from MaxMind's GeoIP2 Precision Services
|
6
|
+
# See http://dev.maxmind.com/geoip/geoip2/web-services/ The difference being that Maxmind calls the service
|
7
|
+
# directly while GeoIP2 uses Hive::GeoIP2. See https://github.com/desuwa/hive_geoip2
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class MaxmindLocal < Base
|
5
|
+
|
6
|
+
def address(format = :full)
|
7
|
+
s = state.to_s == "" ? "" : ", #{state}"
|
8
|
+
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
9
|
+
end
|
10
|
+
|
11
|
+
def coordinates
|
12
|
+
[@data[:latitude], @data[:longitude]]
|
13
|
+
end
|
14
|
+
|
15
|
+
def city
|
16
|
+
@data[:city_name]
|
17
|
+
end
|
18
|
+
|
19
|
+
def state
|
20
|
+
@data[:region_name]
|
21
|
+
end
|
22
|
+
|
23
|
+
def state_code
|
24
|
+
"" # Not available in Maxmind's database
|
25
|
+
end
|
26
|
+
|
27
|
+
def country
|
28
|
+
@data[:country_name]
|
29
|
+
end
|
30
|
+
|
31
|
+
def country_code
|
32
|
+
@data[:country_code2]
|
33
|
+
end
|
34
|
+
|
35
|
+
def postal_code
|
36
|
+
@data[:postal_code]
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.response_attributes
|
40
|
+
%w[ip]
|
41
|
+
end
|
42
|
+
|
43
|
+
response_attributes.each do |a|
|
44
|
+
define_method a do
|
45
|
+
@data[a]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Nominatim < Base
|
5
|
+
|
6
|
+
def poi
|
7
|
+
%w[building university school hospital mall hotel restaurant stadium bus_stop tram_stop].each do |key|
|
8
|
+
return @data['address'][key] if @data['address'].key?(key)
|
9
|
+
end
|
10
|
+
return nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def house_number
|
14
|
+
@data['address']['house_number']
|
15
|
+
end
|
16
|
+
|
17
|
+
def address
|
18
|
+
@data['display_name']
|
19
|
+
end
|
20
|
+
|
21
|
+
def street
|
22
|
+
%w[road pedestrian highway].each do |key|
|
23
|
+
return @data['address'][key] if @data['address'].key?(key)
|
24
|
+
end
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def city
|
29
|
+
%w[city town village hamlet].each do |key|
|
30
|
+
return @data['address'][key] if @data['address'].key?(key)
|
31
|
+
end
|
32
|
+
return nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def village
|
36
|
+
@data['address']['village']
|
37
|
+
end
|
38
|
+
|
39
|
+
def town
|
40
|
+
@data['address']['town']
|
41
|
+
end
|
42
|
+
|
43
|
+
def state
|
44
|
+
@data['address']['state']
|
45
|
+
end
|
46
|
+
|
47
|
+
alias_method :state_code, :state
|
48
|
+
|
49
|
+
def postal_code
|
50
|
+
@data['address']['postcode']
|
51
|
+
end
|
52
|
+
|
53
|
+
def county
|
54
|
+
@data['address']['county']
|
55
|
+
end
|
56
|
+
|
57
|
+
def country
|
58
|
+
@data['address']['country']
|
59
|
+
end
|
60
|
+
|
61
|
+
def country_code
|
62
|
+
@data['address']['country_code']
|
63
|
+
end
|
64
|
+
|
65
|
+
def suburb
|
66
|
+
@data['address']['suburb']
|
67
|
+
end
|
68
|
+
|
69
|
+
def coordinates
|
70
|
+
[@data['lat'].to_f, @data['lon'].to_f]
|
71
|
+
end
|
72
|
+
|
73
|
+
def place_class
|
74
|
+
@data['class']
|
75
|
+
end
|
76
|
+
|
77
|
+
def place_type
|
78
|
+
@data['type']
|
79
|
+
end
|
80
|
+
|
81
|
+
def viewport
|
82
|
+
south, north, west, east = @data['boundingbox'].map(&:to_f)
|
83
|
+
[south, west, north, east]
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.response_attributes
|
87
|
+
%w[place_id osm_type osm_id boundingbox license
|
88
|
+
polygonpoints display_name class type stadium]
|
89
|
+
end
|
90
|
+
|
91
|
+
response_attributes.each do |a|
|
92
|
+
unless method_defined?(a)
|
93
|
+
define_method a do
|
94
|
+
@data[a]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|