geokit 1.10.0 → 1.11.0
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 +4 -4
- data/.gitignore +2 -0
- data/.hound.yml +2 -0
- data/.rubocop.yml +358 -0
- data/.travis.yml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile +3 -3
- data/README.markdown +19 -4
- data/Rakefile +11 -16
- data/fixtures/keys.yml +9 -0
- data/fixtures/vcr_cassettes/google_postal_town.yml +117 -0
- data/fixtures/vcr_cassettes/mapbox_forward_geocode.yml +30 -30
- data/fixtures/vcr_cassettes/mapbox_forward_geocode_city_only.yml +25 -25
- data/fixtures/vcr_cassettes/mapbox_forward_geocode_state_only.yml +71 -0
- data/fixtures/vcr_cassettes/mapbox_reverse_geocode.yml +25 -25
- data/fixtures/vcr_cassettes/test_component_filtering_off.yml +390 -0
- data/fixtures/vcr_cassettes/test_component_filtering_on.yml +164 -0
- data/fixtures/vcr_cassettes/test_component_filtering_on_without_filter.yml +404 -0
- data/geokit.gemspec +24 -23
- data/lib/geokit.rb +7 -7
- data/lib/geokit/core_ext.rb +1 -1
- data/lib/geokit/geo_loc.rb +25 -19
- data/lib/geokit/geocoders.rb +21 -30
- data/lib/geokit/geocoders/bing.rb +5 -4
- data/lib/geokit/geocoders/ca_geocoder.rb +10 -11
- data/lib/geokit/geocoders/fcc.rb +9 -9
- data/lib/geokit/geocoders/free_geo_ip.rb +8 -8
- data/lib/geokit/geocoders/geo_plugin.rb +7 -7
- data/lib/geokit/geocoders/geobytes.rb +10 -10
- data/lib/geokit/geocoders/geocodio.rb +14 -14
- data/lib/geokit/geocoders/geonames.rb +12 -12
- data/lib/geokit/geocoders/google.rb +89 -61
- data/lib/geokit/geocoders/ip.rb +9 -14
- data/lib/geokit/geocoders/mapbox.rb +30 -30
- data/lib/geokit/geocoders/mapquest.rb +12 -12
- data/lib/geokit/geocoders/maxmind.rb +1 -1
- data/lib/geokit/geocoders/opencage.rb +19 -19
- data/lib/geokit/geocoders/openstreetmap.rb +21 -19
- data/lib/geokit/geocoders/ripe.rb +7 -7
- data/lib/geokit/geocoders/us_geocoder.rb +5 -5
- data/lib/geokit/geocoders/yahoo.rb +46 -46
- data/lib/geokit/geocoders/yandex.rb +18 -17
- data/lib/geokit/inflectors.rb +5 -5
- data/lib/geokit/lat_lng.rb +5 -4
- data/lib/geokit/multi_geocoder.rb +4 -2
- data/lib/geokit/net_adapter/net_http.rb +3 -2
- data/lib/geokit/net_adapter/typhoeus.rb +2 -1
- data/lib/geokit/version.rb +1 -1
- data/test/coverage_loader.rb +25 -0
- data/test/helper.rb +18 -87
- data/test/test_base_geocoder.rb +44 -11
- data/test/test_bing_geocoder.rb +40 -48
- data/test/test_bounds.rb +1 -1
- data/test/test_ca_geocoder.rb +15 -15
- data/test/test_fcc_geocoder.rb +8 -9
- data/test/test_free_geo_ip_geocoder.rb +8 -10
- data/test/test_geo_plugin_geocoder.rb +21 -22
- data/test/test_geobytes_geocoder.rb +9 -11
- data/test/test_geocodio_geocoder.rb +12 -14
- data/test/test_geoloc.rb +48 -49
- data/test/test_geonames_geocoder.rb +19 -23
- data/test/test_google_geocoder.rb +197 -189
- data/test/test_inflector.rb +7 -7
- data/test/test_ipgeocoder.rb +32 -31
- data/test/test_latlng.rb +28 -28
- data/test/test_map_quest.rb +23 -27
- data/test/test_mapbox_geocoder.rb +38 -28
- data/test/test_mappable.rb +2 -2
- data/test/test_maxmind_geocoder.rb +16 -16
- data/test/test_multi_geocoder.rb +5 -5
- data/test/test_multi_ip_geocoder.rb +3 -3
- data/test/test_net_adapter.rb +4 -4
- data/test/test_opencage_geocoder.rb +58 -67
- data/test/test_openstreetmap_geocoder.rb +67 -65
- data/test/test_polygon.rb +4 -22
- data/test/test_ripe_geocoder.rb +21 -26
- data/test/test_us_geocoder.rb +21 -21
- data/test/test_useragent.rb +46 -0
- data/test/test_yahoo_geocoder.rb +35 -47
- data/test/test_yandex_geocoder.rb +29 -27
- data/test/vcr_loader.rb +18 -0
- metadata +20 -6
data/lib/geokit.rb
CHANGED
@@ -22,10 +22,10 @@ end
|
|
22
22
|
|
23
23
|
path = File.expand_path(File.dirname(__FILE__))
|
24
24
|
$:.unshift path unless $:.include?(path)
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
25
|
+
require 'geokit/core_ext'
|
26
|
+
require 'geokit/geocoders'
|
27
|
+
require 'geokit/mappable'
|
28
|
+
require 'geokit/bounds'
|
29
|
+
require 'geokit/lat_lng'
|
30
|
+
require 'geokit/geo_loc'
|
31
|
+
require 'geokit/polygon'
|
data/lib/geokit/core_ext.rb
CHANGED
data/lib/geokit/geo_loc.rb
CHANGED
@@ -25,16 +25,16 @@ module Geokit
|
|
25
25
|
# 100 Spear St, San Francisco, CA, 94101, US
|
26
26
|
# Street number and street name are extracted from the street address
|
27
27
|
# attribute if they don't exist
|
28
|
-
attr_accessor :
|
29
|
-
|
30
|
-
attr_accessor :full_address, :all, :district, :province, :sub_premise,
|
28
|
+
attr_accessor :state_name, :state_code, :zip, :country_code, :country
|
29
|
+
attr_accessor :all, :district, :sub_premise,
|
31
30
|
:neighborhood
|
31
|
+
attr_writer :state, :full_address, :street_number, :street_name, :formatted_address
|
32
|
+
attr_reader :city, :street_address
|
32
33
|
# Attributes set upon return from geocoding. Success will be true for
|
33
34
|
# successful geocode lookups. The provider will be set to the name of the
|
34
35
|
# providing geocoder. Finally, precision is an indicator of the accuracy of
|
35
36
|
# the geocoding.
|
36
|
-
attr_accessor :success, :provider, :precision, :suggested_bounds, :place_id
|
37
|
-
:formatted_address
|
37
|
+
attr_accessor :success, :provider, :precision, :suggested_bounds, :place_id
|
38
38
|
# accuracy is set for Yahoo and Google geocoders, it is a numeric value of
|
39
39
|
# the precision. see
|
40
40
|
# http://code.google.com/apis/maps/documentation/geocoding/#GeocodingAccuracy
|
@@ -42,10 +42,17 @@ module Geokit
|
|
42
42
|
# FCC Attributes
|
43
43
|
attr_accessor :district_fips, :state_fips, :block_fips
|
44
44
|
|
45
|
+
def province
|
46
|
+
state
|
47
|
+
end
|
48
|
+
|
45
49
|
# Constructor expects a hash of symbols to correspond with attributes.
|
46
50
|
def initialize(h = {})
|
47
51
|
@all = [self]
|
48
|
-
|
52
|
+
|
53
|
+
# sanatises the GeoLoc object so that it conforms to []
|
54
|
+
h = h.to_hash
|
55
|
+
|
49
56
|
@street_address = h[:street_address]
|
50
57
|
@sub_premise = nil
|
51
58
|
@street_number = nil
|
@@ -56,9 +63,8 @@ module Geokit
|
|
56
63
|
@state_name = h[:state_name]
|
57
64
|
@zip = h[:zip]
|
58
65
|
@country_code = h[:country_code]
|
59
|
-
@province = h[:province]
|
60
66
|
@success = false
|
61
|
-
@precision =
|
67
|
+
@precision = 'unknown'
|
62
68
|
@full_address = nil
|
63
69
|
super(h[:lat], h[:lng])
|
64
70
|
end
|
@@ -69,7 +75,7 @@ module Geokit
|
|
69
75
|
|
70
76
|
# Returns true if geocoded to the United States.
|
71
77
|
def is_us?
|
72
|
-
country_code ==
|
78
|
+
country_code == 'US'
|
73
79
|
end
|
74
80
|
|
75
81
|
def success?
|
@@ -104,7 +110,7 @@ module Geokit
|
|
104
110
|
def hash
|
105
111
|
res = {}
|
106
112
|
fields = [:success, :lat, :lng, :country_code, :city, :state, :zip,
|
107
|
-
:street_address, :
|
113
|
+
:street_address, :district, :provider, :full_address, :is_us?,
|
108
114
|
:ll, :precision, :district_fips, :state_fips, :block_fips, :sub_premise]
|
109
115
|
fields.each { |s| res[s] = send(s.to_s) }
|
110
116
|
res
|
@@ -119,24 +125,24 @@ module Geokit
|
|
119
125
|
# Sets the street address after capitalizing each word within the street
|
120
126
|
# address.
|
121
127
|
def street_address=(address)
|
122
|
-
@street_address = if address && provider !=
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
128
|
+
@street_address = if address && provider != 'google'
|
129
|
+
Geokit::Inflector.titleize(address)
|
130
|
+
else
|
131
|
+
address
|
132
|
+
end
|
127
133
|
end
|
128
134
|
|
129
135
|
# Returns a comma-delimited string consisting of the street address, city,
|
130
136
|
# state, zip, and country code. Only includes those attributes that are
|
131
137
|
# non-blank.
|
132
138
|
def to_geocodeable_s
|
133
|
-
a = [street_address, district, city,
|
134
|
-
a.delete_if { |e| !e || e ==
|
135
|
-
a.join(
|
139
|
+
a = [street_address, district, city, state, zip, country_code].compact
|
140
|
+
a.delete_if { |e| !e || e == '' }
|
141
|
+
a.join(', ')
|
136
142
|
end
|
137
143
|
|
138
144
|
def to_yaml_properties
|
139
|
-
(instance_variables - [
|
145
|
+
(instance_variables - ['@all', :@all]).sort
|
140
146
|
end
|
141
147
|
|
142
148
|
def encode_with(coder)
|
data/lib/geokit/geocoders.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
1
|
+
require 'geokit/net_adapter/net_http'
|
2
|
+
require 'geokit/net_adapter/typhoeus'
|
3
|
+
require 'ipaddr'
|
4
|
+
require 'json'
|
5
|
+
require 'logger'
|
6
|
+
require 'net/http'
|
7
|
+
require 'openssl'
|
8
|
+
require 'rexml/document'
|
9
|
+
require 'timeout'
|
10
|
+
require 'yaml'
|
11
11
|
|
12
12
|
module Geokit
|
13
|
-
require File.join(File.dirname(__FILE__),
|
13
|
+
require File.join(File.dirname(__FILE__), 'inflectors')
|
14
14
|
|
15
15
|
# Contains a range of geocoders:
|
16
16
|
#
|
@@ -33,6 +33,7 @@ module Geokit
|
|
33
33
|
# Some of these geocoders require configuration. You don't have to provide it here. See the README.
|
34
34
|
module Geocoders
|
35
35
|
@@proxy = nil
|
36
|
+
@@useragent = nil
|
36
37
|
@@request_timeout = nil
|
37
38
|
@@provider_order = [:google, :us]
|
38
39
|
@@ip_provider_order = [:geo_plugin, :ip]
|
@@ -45,7 +46,7 @@ module Geokit
|
|
45
46
|
|
46
47
|
def self.__define_accessors
|
47
48
|
class_variables.each do |v|
|
48
|
-
sym = v.to_s.delete(
|
49
|
+
sym = v.to_s.delete('@').to_sym
|
49
50
|
next if self.respond_to? sym
|
50
51
|
module_eval <<-EOS, __FILE__, __LINE__
|
51
52
|
def self.#{sym}
|
@@ -138,14 +139,14 @@ module Geokit
|
|
138
139
|
def self.call_geocoder_service(url)
|
139
140
|
Timeout.timeout(Geokit::Geocoders.request_timeout) { return do_get(url) } if Geokit::Geocoders.request_timeout
|
140
141
|
do_get(url)
|
141
|
-
rescue
|
142
|
+
rescue Timeout::Error
|
142
143
|
nil
|
143
144
|
end
|
144
145
|
|
145
146
|
# Not all geocoders can do reverse geocoding. So, unless the subclass explicitly overrides this method,
|
146
147
|
# a call to reverse_geocode will return an empty GeoLoc. If you happen to be using MultiGeocoder,
|
147
148
|
# this will cause it to failover to the next geocoder, which will hopefully be one which supports reverse geocoding.
|
148
|
-
def self.do_reverse_geocode(
|
149
|
+
def self.do_reverse_geocode(_latlng)
|
149
150
|
GeoLoc.new
|
150
151
|
end
|
151
152
|
|
@@ -154,7 +155,7 @@ module Geokit
|
|
154
155
|
end
|
155
156
|
|
156
157
|
def self.protocol
|
157
|
-
use_https? ?
|
158
|
+
use_https? ? 'https' : 'http'
|
158
159
|
end
|
159
160
|
|
160
161
|
# Wraps the geocoder call around a proxy if necessary.
|
@@ -167,7 +168,7 @@ module Geokit
|
|
167
168
|
end
|
168
169
|
|
169
170
|
def self.provider_name
|
170
|
-
name.split(
|
171
|
+
name.split('::').last.gsub(/Geocoder$/, '')
|
171
172
|
end
|
172
173
|
|
173
174
|
def self.parse(format, body, *args)
|
@@ -176,7 +177,7 @@ module Geokit
|
|
176
177
|
when :json then parse_json(JSON.load(body), *args)
|
177
178
|
when :xml then parse_xml(REXML::Document.new(body), *args)
|
178
179
|
when :yaml then parse_yaml(YAML.load(body), *args)
|
179
|
-
when :csv then parse_csv(body.chomp.split(
|
180
|
+
when :csv then parse_csv(body.chomp.split(','), *args)
|
180
181
|
end
|
181
182
|
end
|
182
183
|
|
@@ -191,24 +192,14 @@ module Geokit
|
|
191
192
|
return GeoLoc.new unless net_adapter.success?(res)
|
192
193
|
parse format, res.body, *args
|
193
194
|
end
|
194
|
-
|
195
|
-
def self.transcode_to_utf8(body)
|
196
|
-
require "iconv" unless String.method_defined?(:encode)
|
197
|
-
if String.method_defined?(:encode)
|
198
|
-
body.encode!("UTF-8", "UTF-8", invalid: :replace)
|
199
|
-
else
|
200
|
-
ic = Iconv.new("UTF-8", "UTF-8//IGNORE")
|
201
|
-
ic.iconv(body)
|
202
|
-
end
|
203
|
-
end
|
204
195
|
end
|
205
196
|
|
206
197
|
# -------------------------------------------------------------------------------------------
|
207
198
|
# "Regular" Address geocoders
|
208
199
|
# -------------------------------------------------------------------------------------------
|
209
|
-
require File.join(File.dirname(__FILE__),
|
210
|
-
Dir[File.join(File.dirname(__FILE__),
|
200
|
+
require File.join(File.dirname(__FILE__), 'geocoders/base_ip')
|
201
|
+
Dir[File.join(File.dirname(__FILE__), '/geocoders/*.rb')].each { |f| require f }
|
211
202
|
|
212
|
-
require File.join(File.dirname(__FILE__),
|
203
|
+
require File.join(File.dirname(__FILE__), 'multi_geocoder')
|
213
204
|
end
|
214
205
|
end
|
@@ -9,11 +9,11 @@ module Geokit
|
|
9
9
|
private
|
10
10
|
|
11
11
|
# Template method which does the geocode lookup.
|
12
|
-
def self.do_geocode(address)
|
12
|
+
def self.do_geocode(address, _=nil)
|
13
13
|
url = submit_url(address)
|
14
14
|
res = call_geocoder_service(url)
|
15
15
|
return GeoLoc.new unless net_adapter.success?(res)
|
16
|
-
xml =
|
16
|
+
xml = res.body.encode!('UTF-8', 'UTF-8', invalid: :replace)
|
17
17
|
parse :xml, xml
|
18
18
|
end
|
19
19
|
|
@@ -51,7 +51,7 @@ module Geokit
|
|
51
51
|
full_address: 'Address/FormattedAddress',
|
52
52
|
city: 'Address/Locality',
|
53
53
|
state: 'Address/AdminDistrict',
|
54
|
-
|
54
|
+
district: 'Address/AdminDistrict2',
|
55
55
|
zip: 'Address/PostalCode',
|
56
56
|
country: 'Address/CountryRegion',
|
57
57
|
lat: 'Point/Latitude',
|
@@ -91,7 +91,8 @@ module Geokit
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def self.set_bounds(loc, xml)
|
94
|
-
|
94
|
+
suggested_bounds = xml.elements['.//BoundingBox']
|
95
|
+
if suggested_bounds
|
95
96
|
bounds = suggested_bounds.elements
|
96
97
|
loc.suggested_bounds = Bounds.normalize(
|
97
98
|
[bounds['.//SouthLatitude'].text, bounds['.//WestLongitude'].text],
|
@@ -17,19 +17,18 @@ module Geokit
|
|
17
17
|
private
|
18
18
|
|
19
19
|
# Template method which does the geocode lookup.
|
20
|
-
def self.do_geocode(loc)
|
20
|
+
def self.do_geocode(loc, _=nil)
|
21
21
|
process :xml, submit_url(loc), GeoLoc.new
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.parse_xml(xml, loc)
|
25
|
-
loc.lat = xml.elements[
|
26
|
-
loc.lng = xml.elements[
|
27
|
-
loc.city = xml.elements[
|
28
|
-
loc.street_number = xml.elements[
|
29
|
-
loc.street_address = xml.elements[
|
30
|
-
loc.state = xml.elements[
|
31
|
-
loc.
|
32
|
-
loc.zip = xml.elements["//postal"].text
|
25
|
+
loc.lat = xml.elements['//latt'].text
|
26
|
+
loc.lng = xml.elements['//longt'].text
|
27
|
+
loc.city = xml.elements['//city'].text
|
28
|
+
loc.street_number = xml.elements['//stnumber'].text
|
29
|
+
loc.street_address = xml.elements['//staddress'].text
|
30
|
+
loc.state = xml.elements['//prov'].text
|
31
|
+
loc.zip = xml.elements['//postal'].text
|
33
32
|
loc.success = true
|
34
33
|
loc
|
35
34
|
end
|
@@ -38,8 +37,8 @@ module Geokit
|
|
38
37
|
def self.submit_url(loc)
|
39
38
|
args = ["locate=#{Geokit::Inflector.url_escape(loc)}"]
|
40
39
|
args << "auth=#{key}" if key
|
41
|
-
args <<
|
42
|
-
|
40
|
+
args << 'geoit=xml'
|
41
|
+
'http://geocoder.ca/?' + args.join('&')
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
data/lib/geokit/geocoders/fcc.rb
CHANGED
@@ -26,21 +26,21 @@ module Geokit
|
|
26
26
|
# "status"=>"OK"}
|
27
27
|
|
28
28
|
def self.parse_json(results)
|
29
|
-
if results.key?(
|
29
|
+
if results.key?('Err') && results['Err']['msg'] == 'There are no results for this location'
|
30
30
|
return GeoLoc.new
|
31
31
|
end
|
32
32
|
# this should probably be smarter.
|
33
|
-
raise Geokit::Geocoders::GeocodeError if !results[
|
33
|
+
raise Geokit::Geocoders::GeocodeError if !results['status'] == 'OK'
|
34
34
|
|
35
35
|
loc = new_loc
|
36
36
|
loc.success = true
|
37
|
-
loc.precision =
|
38
|
-
loc.country_code =
|
39
|
-
loc.district = results[
|
40
|
-
loc.district_fips = results[
|
41
|
-
loc.state = results[
|
42
|
-
loc.state_fips = results[
|
43
|
-
loc.block_fips = results[
|
37
|
+
loc.precision = 'block'
|
38
|
+
loc.country_code = 'US'
|
39
|
+
loc.district = results['County']['name']
|
40
|
+
loc.district_fips = results['County']['FIPS']
|
41
|
+
loc.state = results['State']['code']
|
42
|
+
loc.state_fips = results['State']['FIPS']
|
43
|
+
loc.block_fips = results['Block']['FIPS']
|
44
44
|
loc
|
45
45
|
end
|
46
46
|
end
|
@@ -4,7 +4,7 @@ module Geokit
|
|
4
4
|
class FreeGeoIpGeocoder < BaseIpGeocoder
|
5
5
|
private
|
6
6
|
|
7
|
-
def self.do_geocode(ip)
|
7
|
+
def self.do_geocode(ip, _=nil)
|
8
8
|
process :xml, ip
|
9
9
|
end
|
10
10
|
|
@@ -13,17 +13,17 @@ module Geokit
|
|
13
13
|
end
|
14
14
|
|
15
15
|
XML_MAPPINGS = {
|
16
|
-
city:
|
17
|
-
state:
|
18
|
-
zip:
|
19
|
-
country_code:
|
20
|
-
lat:
|
21
|
-
lng:
|
16
|
+
city: 'City',
|
17
|
+
state: 'RegionCode',
|
18
|
+
zip: 'ZipCode',
|
19
|
+
country_code: 'CountryCode',
|
20
|
+
lat: 'Latitude',
|
21
|
+
lng: 'Longitude',
|
22
22
|
}
|
23
23
|
|
24
24
|
def self.parse_xml(xml)
|
25
25
|
loc = new_loc
|
26
|
-
set_mappings(loc, xml.elements[
|
26
|
+
set_mappings(loc, xml.elements['Response'], XML_MAPPINGS)
|
27
27
|
loc.success = !!loc.city && !loc.city.empty?
|
28
28
|
loc
|
29
29
|
end
|
@@ -4,7 +4,7 @@ module Geokit
|
|
4
4
|
class GeoPluginGeocoder < BaseIpGeocoder
|
5
5
|
private
|
6
6
|
|
7
|
-
def self.do_geocode(ip)
|
7
|
+
def self.do_geocode(ip, _=nil)
|
8
8
|
process :xml, ip
|
9
9
|
end
|
10
10
|
|
@@ -13,16 +13,16 @@ module Geokit
|
|
13
13
|
end
|
14
14
|
|
15
15
|
XML_MAPPINGS = {
|
16
|
-
city:
|
17
|
-
state:
|
18
|
-
country_code:
|
19
|
-
lat:
|
20
|
-
lng:
|
16
|
+
city: 'geoplugin_city',
|
17
|
+
state: 'geoplugin_region',
|
18
|
+
country_code: 'geoplugin_countryCode',
|
19
|
+
lat: 'geoplugin_latitude',
|
20
|
+
lng: 'geoplugin_longitude',
|
21
21
|
}
|
22
22
|
|
23
23
|
def self.parse_xml(xml)
|
24
24
|
loc = new_loc
|
25
|
-
set_mappings(loc, xml.elements[
|
25
|
+
set_mappings(loc, xml.elements['geoPlugin'], XML_MAPPINGS)
|
26
26
|
loc.success = !!loc.city && !loc.city.empty?
|
27
27
|
loc
|
28
28
|
end
|
@@ -2,7 +2,7 @@ module Geokit
|
|
2
2
|
module Geocoders
|
3
3
|
# Provides geocoding based upon an IP address. The underlying web service is GeoSelect
|
4
4
|
class GeobytesGeocoder < BaseIpGeocoder
|
5
|
-
def self.do_geocode(ip)
|
5
|
+
def self.do_geocode(ip, _=nil)
|
6
6
|
process :json, ip
|
7
7
|
end
|
8
8
|
|
@@ -12,15 +12,15 @@ module Geokit
|
|
12
12
|
|
13
13
|
def self.parse_json(json)
|
14
14
|
loc = new_loc
|
15
|
-
loc.city = json[
|
16
|
-
loc.country_code = json[
|
17
|
-
loc.full_address = json[
|
18
|
-
loc.lat = json[
|
19
|
-
loc.lng = json[
|
20
|
-
loc.state = json[
|
21
|
-
loc.precision = json[
|
22
|
-
loc.state_name = json[
|
23
|
-
loc.success = !json[
|
15
|
+
loc.city = json['geobytescity']
|
16
|
+
loc.country_code = json['geobytesinternet']
|
17
|
+
loc.full_address = json['geobytesfqcn']
|
18
|
+
loc.lat = json['geobyteslatitude']
|
19
|
+
loc.lng = json['geobyteslongitude']
|
20
|
+
loc.state = json['geobytescode']
|
21
|
+
loc.precision = json['geobytescertainty']
|
22
|
+
loc.state_name = json['geobytesregion']
|
23
|
+
loc.success = !json['geobytescity'].empty?
|
24
24
|
loc
|
25
25
|
end
|
26
26
|
end
|
@@ -5,7 +5,7 @@ module Geokit
|
|
5
5
|
|
6
6
|
private
|
7
7
|
|
8
|
-
def self.do_geocode(address)
|
8
|
+
def self.do_geocode(address, _=nil)
|
9
9
|
process :json, submit_url(address)
|
10
10
|
end
|
11
11
|
|
@@ -13,15 +13,15 @@ module Geokit
|
|
13
13
|
params = [
|
14
14
|
"q=#{Geokit::Inflector.url_escape(address)}",
|
15
15
|
"api_key=#{key}",
|
16
|
-
].join(
|
16
|
+
].join('&')
|
17
17
|
|
18
|
-
[
|
18
|
+
['http://api.geocod.io/v1/geocode', params].join('?')
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.parse_json(json)
|
22
22
|
loc = nil
|
23
23
|
|
24
|
-
json[
|
24
|
+
json['results'].each do |address|
|
25
25
|
if loc.nil?
|
26
26
|
loc = create_new_loc(address)
|
27
27
|
else
|
@@ -40,19 +40,19 @@ module Geokit
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.set_address_components(json, loc)
|
43
|
-
loc.street_address = json[
|
44
|
-
loc.street_number = json[
|
45
|
-
loc.sub_premise = json[
|
46
|
-
loc.street_name = json[
|
47
|
-
loc.city = json[
|
48
|
-
loc.state = json[
|
49
|
-
loc.zip = json[
|
50
|
-
loc.full_address = json[
|
43
|
+
loc.street_address = json['address_components']['street']
|
44
|
+
loc.street_number = json['address_components']['number']
|
45
|
+
loc.sub_premise = json['address_components']['suffix']
|
46
|
+
loc.street_name = json['address_components']['street']
|
47
|
+
loc.city = json['address_components']['city']
|
48
|
+
loc.state = json['address_components']['state']
|
49
|
+
loc.zip = json['address_components']['zip']
|
50
|
+
loc.full_address = json['formatted_address']
|
51
51
|
end
|
52
52
|
|
53
53
|
def self.set_coordinates(json, loc)
|
54
|
-
loc.lat = json[
|
55
|
-
loc.lng = json[
|
54
|
+
loc.lat = json['location']['lat']
|
55
|
+
loc.lng = json['location']['lng']
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|