geocoder 1.6.7 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +312 -203
- data/lib/geocoder/cache.rb +5 -1
- data/lib/geocoder/configuration.rb +1 -0
- data/lib/geocoder/ip_address.rb +6 -0
- data/lib/geocoder/lookup.rb +15 -2
- data/lib/geocoder/lookups/amazon_location_service.rb +53 -0
- data/lib/geocoder/lookups/bing.rb +1 -1
- data/lib/geocoder/lookups/geoapify.rb +72 -0
- data/lib/geocoder/lookups/geoip2.rb +4 -0
- data/lib/geocoder/lookups/ip2location.rb +10 -6
- data/lib/geocoder/lookups/ipqualityscore.rb +50 -0
- data/lib/geocoder/lookups/melissa_street.rb +41 -0
- data/lib/geocoder/lookups/photon.rb +89 -0
- data/lib/geocoder/results/amazon_location_service.rb +57 -0
- data/lib/geocoder/results/esri.rb +5 -2
- data/lib/geocoder/results/geoapify.rb +179 -0
- data/lib/geocoder/results/ipqualityscore.rb +54 -0
- data/lib/geocoder/results/mapbox.rb +10 -4
- data/lib/geocoder/results/melissa_street.rb +46 -0
- data/lib/geocoder/results/photon.rb +119 -0
- data/lib/geocoder/version.rb +1 -1
- metadata +12 -2
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder
|
4
|
+
module Result
|
5
|
+
class Ipqualityscore < Base
|
6
|
+
|
7
|
+
def self.key_method_mappings
|
8
|
+
{
|
9
|
+
'request_id' => :request_id,
|
10
|
+
'success' => :success?,
|
11
|
+
'message' => :message,
|
12
|
+
'city' => :city,
|
13
|
+
'region' => :state,
|
14
|
+
'country_code' => :country_code,
|
15
|
+
'mobile' => :mobile?,
|
16
|
+
'fraud_score' => :fraud_score,
|
17
|
+
'ISP' => :isp,
|
18
|
+
'ASN' => :asn,
|
19
|
+
'organization' => :organization,
|
20
|
+
'is_crawler' => :crawler?,
|
21
|
+
'host' => :host,
|
22
|
+
'proxy' => :proxy?,
|
23
|
+
'vpn' => :vpn?,
|
24
|
+
'tor' => :tor?,
|
25
|
+
'active_vpn' => :active_vpn?,
|
26
|
+
'active_tor' => :active_tor?,
|
27
|
+
'recent_abuse' => :recent_abuse?,
|
28
|
+
'bot_status' => :bot?,
|
29
|
+
'connection_type' => :connection_type,
|
30
|
+
'abuse_velocity' => :abuse_velocity,
|
31
|
+
'timezone' => :timezone,
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
key_method_mappings.each_pair do |key, meth|
|
36
|
+
define_method meth do
|
37
|
+
@data[key]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
alias_method :state_code, :state
|
42
|
+
alias_method :country, :country_code
|
43
|
+
|
44
|
+
def postal_code
|
45
|
+
'' # No suitable fallback
|
46
|
+
end
|
47
|
+
|
48
|
+
def address
|
49
|
+
[city, state, country_code].compact.reject(&:empty?).join(', ')
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -23,7 +23,10 @@ module Geocoder::Result
|
|
23
23
|
context_part('region')
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
def state_code
|
27
|
+
value = context_part('region', 'short_code')
|
28
|
+
value.split('-').last unless value.nil?
|
29
|
+
end
|
27
30
|
|
28
31
|
def postal_code
|
29
32
|
context_part('postcode')
|
@@ -33,7 +36,10 @@ module Geocoder::Result
|
|
33
36
|
context_part('country')
|
34
37
|
end
|
35
38
|
|
36
|
-
|
39
|
+
def country_code
|
40
|
+
value = context_part('country', 'short_code')
|
41
|
+
value.upcase unless value.nil?
|
42
|
+
end
|
37
43
|
|
38
44
|
def neighborhood
|
39
45
|
context_part('neighborhood')
|
@@ -45,8 +51,8 @@ module Geocoder::Result
|
|
45
51
|
|
46
52
|
private
|
47
53
|
|
48
|
-
def context_part(name)
|
49
|
-
context.
|
54
|
+
def context_part(name, key = 'text')
|
55
|
+
(context.detect { |c| c['id'] =~ Regexp.new(name) } || {})[key]
|
50
56
|
end
|
51
57
|
|
52
58
|
def context
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class MelissaStreet < Base
|
5
|
+
def address(format = :full)
|
6
|
+
@data['FormattedAddress']
|
7
|
+
end
|
8
|
+
|
9
|
+
def street_address
|
10
|
+
@data['AddressLine1']
|
11
|
+
end
|
12
|
+
|
13
|
+
def suffix
|
14
|
+
@data['ThoroughfareTrailingType']
|
15
|
+
end
|
16
|
+
|
17
|
+
def number
|
18
|
+
@data['PremisesNumber']
|
19
|
+
end
|
20
|
+
|
21
|
+
def city
|
22
|
+
@data['Locality']
|
23
|
+
end
|
24
|
+
|
25
|
+
def state_code
|
26
|
+
@data['AdministrativeArea']
|
27
|
+
end
|
28
|
+
alias_method :state, :state_code
|
29
|
+
|
30
|
+
def country
|
31
|
+
@data['CountryName']
|
32
|
+
end
|
33
|
+
|
34
|
+
def country_code
|
35
|
+
@data['CountryISO3166_1_Alpha2']
|
36
|
+
end
|
37
|
+
|
38
|
+
def postal_code
|
39
|
+
@data['PostalCode']
|
40
|
+
end
|
41
|
+
|
42
|
+
def coordinates
|
43
|
+
[@data['Latitude'].to_f, @data['Longitude'].to_f]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Photon < Base
|
5
|
+
def name
|
6
|
+
properties['name']
|
7
|
+
end
|
8
|
+
|
9
|
+
def address(_format = :full)
|
10
|
+
parts = []
|
11
|
+
parts << name if name
|
12
|
+
parts << street_address if street_address
|
13
|
+
parts << city
|
14
|
+
parts << state if state
|
15
|
+
parts << postal_code
|
16
|
+
parts << country
|
17
|
+
|
18
|
+
parts.join(', ')
|
19
|
+
end
|
20
|
+
|
21
|
+
def street_address
|
22
|
+
return unless street
|
23
|
+
return street unless house_number
|
24
|
+
|
25
|
+
"#{house_number} #{street}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def house_number
|
29
|
+
properties['housenumber']
|
30
|
+
end
|
31
|
+
|
32
|
+
def street
|
33
|
+
properties['street']
|
34
|
+
end
|
35
|
+
|
36
|
+
def postal_code
|
37
|
+
properties['postcode']
|
38
|
+
end
|
39
|
+
|
40
|
+
def city
|
41
|
+
properties['city']
|
42
|
+
end
|
43
|
+
|
44
|
+
def state
|
45
|
+
properties['state']
|
46
|
+
end
|
47
|
+
|
48
|
+
def state_code
|
49
|
+
''
|
50
|
+
end
|
51
|
+
|
52
|
+
def country
|
53
|
+
properties['country']
|
54
|
+
end
|
55
|
+
|
56
|
+
def country_code
|
57
|
+
''
|
58
|
+
end
|
59
|
+
|
60
|
+
def coordinates
|
61
|
+
return unless geometry
|
62
|
+
return unless geometry[:coordinates]
|
63
|
+
|
64
|
+
geometry[:coordinates].reverse
|
65
|
+
end
|
66
|
+
|
67
|
+
def geometry
|
68
|
+
return unless data['geometry']
|
69
|
+
|
70
|
+
symbol_hash data['geometry']
|
71
|
+
end
|
72
|
+
|
73
|
+
def bounds
|
74
|
+
properties['extent']
|
75
|
+
end
|
76
|
+
|
77
|
+
# Type of the result (OSM object type), one of:
|
78
|
+
#
|
79
|
+
# :node
|
80
|
+
# :way
|
81
|
+
# :relation
|
82
|
+
#
|
83
|
+
def type
|
84
|
+
{
|
85
|
+
'N' => :node,
|
86
|
+
'W' => :way,
|
87
|
+
'R' => :relation
|
88
|
+
}[properties['osm_type']]
|
89
|
+
end
|
90
|
+
|
91
|
+
def osm_id
|
92
|
+
properties['osm_id']
|
93
|
+
end
|
94
|
+
|
95
|
+
# See: https://wiki.openstreetmap.org/wiki/Tags
|
96
|
+
def osm_tag
|
97
|
+
return unless properties['osm_key']
|
98
|
+
return properties['osm_key'] unless properties['osm_value']
|
99
|
+
|
100
|
+
"#{properties['osm_key']}=#{properties['osm_value']}"
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def properties
|
106
|
+
@properties ||= data['properties'] || {}
|
107
|
+
end
|
108
|
+
|
109
|
+
def symbol_hash(orig_hash)
|
110
|
+
{}.tap do |result|
|
111
|
+
orig_hash.each_key do |key|
|
112
|
+
next unless orig_hash[key]
|
113
|
+
|
114
|
+
result[key.to_sym] = orig_hash[key]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/lib/geocoder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geocoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Reisner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Object geocoding (by street or IP address), reverse geocoding (coordinates
|
14
14
|
to street address), distance queries for ActiveRecord and Mongoid, result caching,
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/geocoder/lookup.rb
|
52
52
|
- lib/geocoder/lookups/abstract_api.rb
|
53
53
|
- lib/geocoder/lookups/amap.rb
|
54
|
+
- lib/geocoder/lookups/amazon_location_service.rb
|
54
55
|
- lib/geocoder/lookups/baidu.rb
|
55
56
|
- lib/geocoder/lookups/baidu_ip.rb
|
56
57
|
- lib/geocoder/lookups/ban_data_gouv_fr.rb
|
@@ -60,6 +61,7 @@ files:
|
|
60
61
|
- lib/geocoder/lookups/dstk.rb
|
61
62
|
- lib/geocoder/lookups/esri.rb
|
62
63
|
- lib/geocoder/lookups/freegeoip.rb
|
64
|
+
- lib/geocoder/lookups/geoapify.rb
|
63
65
|
- lib/geocoder/lookups/geocoder_ca.rb
|
64
66
|
- lib/geocoder/lookups/geocodio.rb
|
65
67
|
- lib/geocoder/lookups/geoip2.rb
|
@@ -74,6 +76,7 @@ files:
|
|
74
76
|
- lib/geocoder/lookups/ipdata_co.rb
|
75
77
|
- lib/geocoder/lookups/ipgeolocation.rb
|
76
78
|
- lib/geocoder/lookups/ipinfo_io.rb
|
79
|
+
- lib/geocoder/lookups/ipqualityscore.rb
|
77
80
|
- lib/geocoder/lookups/ipregistry.rb
|
78
81
|
- lib/geocoder/lookups/ipstack.rb
|
79
82
|
- lib/geocoder/lookups/latlon.rb
|
@@ -83,11 +86,13 @@ files:
|
|
83
86
|
- lib/geocoder/lookups/maxmind.rb
|
84
87
|
- lib/geocoder/lookups/maxmind_geoip2.rb
|
85
88
|
- lib/geocoder/lookups/maxmind_local.rb
|
89
|
+
- lib/geocoder/lookups/melissa_street.rb
|
86
90
|
- lib/geocoder/lookups/nationaal_georegister_nl.rb
|
87
91
|
- lib/geocoder/lookups/nominatim.rb
|
88
92
|
- lib/geocoder/lookups/opencagedata.rb
|
89
93
|
- lib/geocoder/lookups/osmnames.rb
|
90
94
|
- lib/geocoder/lookups/pelias.rb
|
95
|
+
- lib/geocoder/lookups/photon.rb
|
91
96
|
- lib/geocoder/lookups/pickpoint.rb
|
92
97
|
- lib/geocoder/lookups/pointpin.rb
|
93
98
|
- lib/geocoder/lookups/postcode_anywhere_uk.rb
|
@@ -108,6 +113,7 @@ files:
|
|
108
113
|
- lib/geocoder/request.rb
|
109
114
|
- lib/geocoder/results/abstract_api.rb
|
110
115
|
- lib/geocoder/results/amap.rb
|
116
|
+
- lib/geocoder/results/amazon_location_service.rb
|
111
117
|
- lib/geocoder/results/baidu.rb
|
112
118
|
- lib/geocoder/results/baidu_ip.rb
|
113
119
|
- lib/geocoder/results/ban_data_gouv_fr.rb
|
@@ -117,6 +123,7 @@ files:
|
|
117
123
|
- lib/geocoder/results/dstk.rb
|
118
124
|
- lib/geocoder/results/esri.rb
|
119
125
|
- lib/geocoder/results/freegeoip.rb
|
126
|
+
- lib/geocoder/results/geoapify.rb
|
120
127
|
- lib/geocoder/results/geocoder_ca.rb
|
121
128
|
- lib/geocoder/results/geocodio.rb
|
122
129
|
- lib/geocoder/results/geoip2.rb
|
@@ -131,6 +138,7 @@ files:
|
|
131
138
|
- lib/geocoder/results/ipdata_co.rb
|
132
139
|
- lib/geocoder/results/ipgeolocation.rb
|
133
140
|
- lib/geocoder/results/ipinfo_io.rb
|
141
|
+
- lib/geocoder/results/ipqualityscore.rb
|
134
142
|
- lib/geocoder/results/ipregistry.rb
|
135
143
|
- lib/geocoder/results/ipstack.rb
|
136
144
|
- lib/geocoder/results/latlon.rb
|
@@ -140,11 +148,13 @@ files:
|
|
140
148
|
- lib/geocoder/results/maxmind.rb
|
141
149
|
- lib/geocoder/results/maxmind_geoip2.rb
|
142
150
|
- lib/geocoder/results/maxmind_local.rb
|
151
|
+
- lib/geocoder/results/melissa_street.rb
|
143
152
|
- lib/geocoder/results/nationaal_georegister_nl.rb
|
144
153
|
- lib/geocoder/results/nominatim.rb
|
145
154
|
- lib/geocoder/results/opencagedata.rb
|
146
155
|
- lib/geocoder/results/osmnames.rb
|
147
156
|
- lib/geocoder/results/pelias.rb
|
157
|
+
- lib/geocoder/results/photon.rb
|
148
158
|
- lib/geocoder/results/pickpoint.rb
|
149
159
|
- lib/geocoder/results/pointpin.rb
|
150
160
|
- lib/geocoder/results/postcode_anywhere_uk.rb
|