really-broken-geocoder 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +557 -0
- data/LICENSE +20 -0
- data/README.md +3 -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 +22 -0
- data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +30 -0
- data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +30 -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/generators/geocoder/migration_version.rb +15 -0
- data/lib/geocoder.rb +48 -0
- data/lib/geocoder/cache.rb +94 -0
- data/lib/geocoder/calculations.rb +420 -0
- data/lib/geocoder/cli.rb +121 -0
- data/lib/geocoder/configuration.rb +137 -0
- data/lib/geocoder/configuration_hash.rb +11 -0
- data/lib/geocoder/esri_token.rb +38 -0
- data/lib/geocoder/exceptions.rb +40 -0
- data/lib/geocoder/ip_address.rb +26 -0
- data/lib/geocoder/kernel_logger.rb +25 -0
- data/lib/geocoder/logger.rb +47 -0
- data/lib/geocoder/lookup.rb +118 -0
- data/lib/geocoder/lookups/amap.rb +63 -0
- data/lib/geocoder/lookups/baidu.rb +63 -0
- data/lib/geocoder/lookups/baidu_ip.rb +30 -0
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +130 -0
- data/lib/geocoder/lookups/base.rb +348 -0
- data/lib/geocoder/lookups/bing.rb +82 -0
- data/lib/geocoder/lookups/db_ip_com.rb +52 -0
- data/lib/geocoder/lookups/dstk.rb +22 -0
- data/lib/geocoder/lookups/esri.rb +95 -0
- data/lib/geocoder/lookups/freegeoip.rb +60 -0
- data/lib/geocoder/lookups/geocoder_ca.rb +53 -0
- data/lib/geocoder/lookups/geocoder_us.rb +51 -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 +95 -0
- data/lib/geocoder/lookups/google_places_details.rb +50 -0
- data/lib/geocoder/lookups/google_places_search.rb +33 -0
- data/lib/geocoder/lookups/google_premier.rb +57 -0
- data/lib/geocoder/lookups/here.rb +77 -0
- data/lib/geocoder/lookups/ip2location.rb +75 -0
- data/lib/geocoder/lookups/ipapi_com.rb +82 -0
- data/lib/geocoder/lookups/ipdata_co.rb +62 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +44 -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 +58 -0
- data/lib/geocoder/lookups/maxmind.rb +90 -0
- data/lib/geocoder/lookups/maxmind_geoip2.rb +70 -0
- data/lib/geocoder/lookups/maxmind_local.rb +65 -0
- data/lib/geocoder/lookups/nominatim.rb +64 -0
- data/lib/geocoder/lookups/opencagedata.rb +65 -0
- data/lib/geocoder/lookups/pelias.rb +63 -0
- data/lib/geocoder/lookups/pickpoint.rb +41 -0
- data/lib/geocoder/lookups/pointpin.rb +69 -0
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +50 -0
- data/lib/geocoder/lookups/postcodes_io.rb +31 -0
- data/lib/geocoder/lookups/smarty_streets.rb +63 -0
- data/lib/geocoder/lookups/telize.rb +75 -0
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/test.rb +44 -0
- data/lib/geocoder/lookups/yandex.rb +62 -0
- data/lib/geocoder/models/active_record.rb +51 -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 +125 -0
- data/lib/geocoder/railtie.rb +26 -0
- data/lib/geocoder/request.rb +114 -0
- data/lib/geocoder/results/amap.rb +87 -0
- data/lib/geocoder/results/baidu.rb +79 -0
- data/lib/geocoder/results/baidu_ip.rb +62 -0
- data/lib/geocoder/results/ban_data_gouv_fr.rb +257 -0
- data/lib/geocoder/results/base.rb +79 -0
- data/lib/geocoder/results/bing.rb +52 -0
- data/lib/geocoder/results/db_ip_com.rb +58 -0
- data/lib/geocoder/results/dstk.rb +6 -0
- data/lib/geocoder/results/esri.rb +75 -0
- data/lib/geocoder/results/freegeoip.rb +40 -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 +78 -0
- data/lib/geocoder/results/geoip2.rb +76 -0
- data/lib/geocoder/results/geoportail_lu.rb +71 -0
- data/lib/geocoder/results/google.rb +150 -0
- data/lib/geocoder/results/google_places_details.rb +39 -0
- data/lib/geocoder/results/google_places_search.rb +52 -0
- data/lib/geocoder/results/google_premier.rb +6 -0
- data/lib/geocoder/results/here.rb +79 -0
- 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/ipinfo_io.rb +48 -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 +48 -0
- data/lib/geocoder/results/maxmind.rb +130 -0
- data/lib/geocoder/results/maxmind_geoip2.rb +9 -0
- data/lib/geocoder/results/maxmind_local.rb +44 -0
- data/lib/geocoder/results/nominatim.rb +109 -0
- data/lib/geocoder/results/opencagedata.rb +100 -0
- data/lib/geocoder/results/pelias.rb +58 -0
- data/lib/geocoder/results/pickpoint.rb +6 -0
- data/lib/geocoder/results/pointpin.rb +40 -0
- data/lib/geocoder/results/postcode_anywhere_uk.rb +42 -0
- data/lib/geocoder/results/postcodes_io.rb +40 -0
- data/lib/geocoder/results/smarty_streets.rb +142 -0
- data/lib/geocoder/results/telize.rb +40 -0
- data/lib/geocoder/results/tencent.rb +72 -0
- data/lib/geocoder/results/test.rb +33 -0
- data/lib/geocoder/results/yandex.rb +134 -0
- data/lib/geocoder/sql.rb +110 -0
- data/lib/geocoder/stores/active_record.rb +328 -0
- data/lib/geocoder/stores/base.rb +115 -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 +54 -0
- data/lib/tasks/maxmind.rake +73 -0
- metadata +186 -0
@@ -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,44 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class MaxmindLocal < Base
|
5
|
+
|
6
|
+
def coordinates
|
7
|
+
[@data[:latitude], @data[:longitude]]
|
8
|
+
end
|
9
|
+
|
10
|
+
def city
|
11
|
+
@data[:city_name]
|
12
|
+
end
|
13
|
+
|
14
|
+
def state
|
15
|
+
@data[:region_name]
|
16
|
+
end
|
17
|
+
|
18
|
+
def state_code
|
19
|
+
"" # Not available in Maxmind's database
|
20
|
+
end
|
21
|
+
|
22
|
+
def country
|
23
|
+
@data[:country_name]
|
24
|
+
end
|
25
|
+
|
26
|
+
def country_code
|
27
|
+
@data[:country_code2]
|
28
|
+
end
|
29
|
+
|
30
|
+
def postal_code
|
31
|
+
@data[:postal_code]
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.response_attributes
|
35
|
+
%w[ip]
|
36
|
+
end
|
37
|
+
|
38
|
+
response_attributes.each do |a|
|
39
|
+
define_method a do
|
40
|
+
@data[a]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Nominatim < Base
|
5
|
+
|
6
|
+
def poi
|
7
|
+
return @data['address'][place_type] if @data['address'].key?(place_type)
|
8
|
+
return nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def house_number
|
12
|
+
@data['address']['house_number']
|
13
|
+
end
|
14
|
+
|
15
|
+
def address
|
16
|
+
@data['display_name']
|
17
|
+
end
|
18
|
+
|
19
|
+
def street
|
20
|
+
%w[road pedestrian highway].each do |key|
|
21
|
+
return @data['address'][key] if @data['address'].key?(key)
|
22
|
+
end
|
23
|
+
return nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def city
|
27
|
+
%w[city town village hamlet].each do |key|
|
28
|
+
return @data['address'][key] if @data['address'].key?(key)
|
29
|
+
end
|
30
|
+
return nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def village
|
34
|
+
@data['address']['village']
|
35
|
+
end
|
36
|
+
|
37
|
+
def town
|
38
|
+
@data['address']['town']
|
39
|
+
end
|
40
|
+
|
41
|
+
def state
|
42
|
+
@data['address']['state']
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :state_code, :state
|
46
|
+
|
47
|
+
def postal_code
|
48
|
+
@data['address']['postcode']
|
49
|
+
end
|
50
|
+
|
51
|
+
def county
|
52
|
+
@data['address']['county']
|
53
|
+
end
|
54
|
+
|
55
|
+
def country
|
56
|
+
@data['address']['country']
|
57
|
+
end
|
58
|
+
|
59
|
+
def country_code
|
60
|
+
@data['address']['country_code']
|
61
|
+
end
|
62
|
+
|
63
|
+
def suburb
|
64
|
+
@data['address']['suburb']
|
65
|
+
end
|
66
|
+
|
67
|
+
def city_district
|
68
|
+
@data['address']['city_district']
|
69
|
+
end
|
70
|
+
|
71
|
+
def state_district
|
72
|
+
@data['address']['state_district']
|
73
|
+
end
|
74
|
+
|
75
|
+
def neighbourhood
|
76
|
+
@data['address']['neighbourhood']
|
77
|
+
end
|
78
|
+
|
79
|
+
def coordinates
|
80
|
+
[@data['lat'].to_f, @data['lon'].to_f]
|
81
|
+
end
|
82
|
+
|
83
|
+
def place_class
|
84
|
+
@data['class']
|
85
|
+
end
|
86
|
+
|
87
|
+
def place_type
|
88
|
+
@data['type']
|
89
|
+
end
|
90
|
+
|
91
|
+
def viewport
|
92
|
+
south, north, west, east = @data['boundingbox'].map(&:to_f)
|
93
|
+
[south, west, north, east]
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.response_attributes
|
97
|
+
%w[place_id osm_type osm_id boundingbox license
|
98
|
+
polygonpoints display_name class type stadium]
|
99
|
+
end
|
100
|
+
|
101
|
+
response_attributes.each do |a|
|
102
|
+
unless method_defined?(a)
|
103
|
+
define_method a do
|
104
|
+
@data[a]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Opencagedata < Base
|
5
|
+
|
6
|
+
def poi
|
7
|
+
%w[stadium bus_stop tram_stop].each do |key|
|
8
|
+
return @data['components'][key] if @data['components'].key?(key)
|
9
|
+
end
|
10
|
+
return nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def house_number
|
14
|
+
@data['components']['house_number']
|
15
|
+
end
|
16
|
+
|
17
|
+
def address
|
18
|
+
@data['formatted']
|
19
|
+
end
|
20
|
+
|
21
|
+
def street
|
22
|
+
%w[road pedestrian highway].each do |key|
|
23
|
+
return @data['components'][key] if @data['components'].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['components'][key] if @data['components'].key?(key)
|
31
|
+
end
|
32
|
+
return nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def village
|
36
|
+
@data['components']['village']
|
37
|
+
end
|
38
|
+
|
39
|
+
def state
|
40
|
+
@data['components']['state']
|
41
|
+
end
|
42
|
+
|
43
|
+
def state_code
|
44
|
+
@data['components']['state_code']
|
45
|
+
end
|
46
|
+
|
47
|
+
def postal_code
|
48
|
+
@data['components']['postcode'].to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
def county
|
52
|
+
@data['components']['county']
|
53
|
+
end
|
54
|
+
|
55
|
+
def country
|
56
|
+
@data['components']['country']
|
57
|
+
end
|
58
|
+
|
59
|
+
def country_code
|
60
|
+
@data['components']['country_code']
|
61
|
+
end
|
62
|
+
|
63
|
+
def suburb
|
64
|
+
@data['components']['suburb']
|
65
|
+
end
|
66
|
+
|
67
|
+
def coordinates
|
68
|
+
[@data['geometry']['lat'].to_f, @data['geometry']['lng'].to_f]
|
69
|
+
end
|
70
|
+
|
71
|
+
def viewport
|
72
|
+
bounds = @data['bounds'] || fail
|
73
|
+
south, west = %w(lat lng).map { |i| bounds['southwest'][i] }
|
74
|
+
north, east = %w(lat lng).map { |i| bounds['northeast'][i] }
|
75
|
+
[south, west, north, east]
|
76
|
+
end
|
77
|
+
|
78
|
+
def time_zone
|
79
|
+
# The OpenCage API documentation states that `annotations` is available
|
80
|
+
# "when possible" https://geocoder.opencagedata.com/api#annotations
|
81
|
+
@data
|
82
|
+
.fetch('annotations', {})
|
83
|
+
.fetch('timezone', {})
|
84
|
+
.fetch('name', nil)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.response_attributes
|
88
|
+
%w[boundingbox license
|
89
|
+
formatted stadium]
|
90
|
+
end
|
91
|
+
|
92
|
+
response_attributes.each do |a|
|
93
|
+
unless method_defined?(a)
|
94
|
+
define_method a do
|
95
|
+
@data[a]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Pelias < Base
|
5
|
+
def address(format = :full)
|
6
|
+
properties['label']
|
7
|
+
end
|
8
|
+
|
9
|
+
def city
|
10
|
+
locality
|
11
|
+
end
|
12
|
+
|
13
|
+
def coordinates
|
14
|
+
geometry['coordinates'].reverse
|
15
|
+
end
|
16
|
+
|
17
|
+
def country_code
|
18
|
+
properties['country_a']
|
19
|
+
end
|
20
|
+
|
21
|
+
def postal_code
|
22
|
+
properties['postalcode'].to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def province
|
26
|
+
state
|
27
|
+
end
|
28
|
+
|
29
|
+
def state
|
30
|
+
properties['region']
|
31
|
+
end
|
32
|
+
|
33
|
+
def state_code
|
34
|
+
properties['region_a']
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.response_attributes
|
38
|
+
%w[county confidence country gid id layer localadmin locality neighborhood]
|
39
|
+
end
|
40
|
+
|
41
|
+
response_attributes.each do |a|
|
42
|
+
define_method a do
|
43
|
+
properties[a]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def geometry
|
50
|
+
@data.fetch('geometry', {})
|
51
|
+
end
|
52
|
+
|
53
|
+
def properties
|
54
|
+
@data.fetch('properties', {})
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Pointpin < Base
|
5
|
+
|
6
|
+
def address
|
7
|
+
[ city_name, state, postal_code, country ].select{ |i| i.to_s != "" }.join(", ")
|
8
|
+
end
|
9
|
+
|
10
|
+
def city
|
11
|
+
@data['city_name']
|
12
|
+
end
|
13
|
+
|
14
|
+
def state
|
15
|
+
@data['region_name']
|
16
|
+
end
|
17
|
+
|
18
|
+
def state_code
|
19
|
+
@data['region_code']
|
20
|
+
end
|
21
|
+
|
22
|
+
def country
|
23
|
+
@data['country_name']
|
24
|
+
end
|
25
|
+
|
26
|
+
def postal_code
|
27
|
+
@data['postcode']
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.response_attributes
|
31
|
+
%w[continent_code ip country_code country_name region_name city_name postcode latitude longitude time_zone languages]
|
32
|
+
end
|
33
|
+
|
34
|
+
response_attributes.each do |a|
|
35
|
+
define_method a do
|
36
|
+
@data[a]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class PostcodeAnywhereUk < Base
|
5
|
+
|
6
|
+
def coordinates
|
7
|
+
[@data['Latitude'].to_f, @data['Longitude'].to_f]
|
8
|
+
end
|
9
|
+
|
10
|
+
def blank_result
|
11
|
+
''
|
12
|
+
end
|
13
|
+
alias_method :state, :blank_result
|
14
|
+
alias_method :state_code, :blank_result
|
15
|
+
alias_method :postal_code, :blank_result
|
16
|
+
|
17
|
+
def address
|
18
|
+
@data['Location']
|
19
|
+
end
|
20
|
+
|
21
|
+
def city
|
22
|
+
# is this too big a jump to assume that the API always
|
23
|
+
# returns a City, County as the last elements?
|
24
|
+
city = @data['Location'].split(',')[-2] || blank_result
|
25
|
+
city.strip
|
26
|
+
end
|
27
|
+
|
28
|
+
def os_grid
|
29
|
+
@data['OsGrid']
|
30
|
+
end
|
31
|
+
|
32
|
+
# This is a UK only API; all results are UK specific and
|
33
|
+
# so ommitted from API response.
|
34
|
+
def country
|
35
|
+
'United Kingdom'
|
36
|
+
end
|
37
|
+
|
38
|
+
def country_code
|
39
|
+
'UK'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class PostcodesIo < Base
|
5
|
+
|
6
|
+
def coordinates
|
7
|
+
[@data['latitude'].to_f, @data['longitude'].to_f]
|
8
|
+
end
|
9
|
+
|
10
|
+
def quality
|
11
|
+
@data['quality']
|
12
|
+
end
|
13
|
+
|
14
|
+
def postal_code
|
15
|
+
@data['postcode']
|
16
|
+
end
|
17
|
+
alias address postal_code
|
18
|
+
|
19
|
+
def city
|
20
|
+
@data['admin_ward']
|
21
|
+
end
|
22
|
+
|
23
|
+
def county
|
24
|
+
@data['admin_county']
|
25
|
+
end
|
26
|
+
alias state county
|
27
|
+
|
28
|
+
def state_code
|
29
|
+
@data['codes']['admin_county']
|
30
|
+
end
|
31
|
+
|
32
|
+
def country
|
33
|
+
'United Kingdom'
|
34
|
+
end
|
35
|
+
|
36
|
+
def country_code
|
37
|
+
'UK'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|