Skip to content

Commit

Permalink
Merge 4b936df into 7fa4b06
Browse files Browse the repository at this point in the history
  • Loading branch information
nicnilov committed Aug 12, 2015
2 parents 7fa4b06 + 4b936df commit 138999c
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 1 deletion.
123 changes: 123 additions & 0 deletions fixtures/vcr_cassettes/google_full_v3_20.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion lib/geokit/geo_loc.rb
Expand Up @@ -33,7 +33,8 @@ class GeoLoc < LatLng
# successful geocode lookups. The provider will be set to the name of the
# providing geocoder. Finally, precision is an indicator of the accuracy of
# the geocoding.
attr_accessor :success, :provider, :precision, :suggested_bounds
attr_accessor :success, :provider, :precision, :suggested_bounds, :place_id,
:formatted_address
# accuracy is set for Yahoo and Google geocoders, it is a numeric value of
# the precision. see
# http://code.google.com/apis/maps/documentation/geocoding/#GeocodingAccuracy
Expand Down Expand Up @@ -94,6 +95,11 @@ def street_name
@street_name
end

# Returns Google-supplied normalized address string or concatenation of address parts
def formatted_address
@formatted_address ||= full_address
end

# gives you all the important fields as key-value pairs
def hash
res = {}
Expand Down
3 changes: 3 additions & 0 deletions lib/geokit/geocoders/google.rb
Expand Up @@ -150,6 +150,9 @@ def self.single_json_to_geoloc(addr)

set_bounds(loc, addr)

loc.place_id = addr['place_id']
loc.formatted_address = addr['formatted_address']

loc
end

Expand Down
9 changes: 9 additions & 0 deletions test/test_geoloc.rb
Expand Up @@ -44,6 +44,15 @@ def test_full_address
assert_equal "Irving, TX, 75063, US", @loc.full_address
end

def test_formatted_address
@loc.formatted_address = nil
@loc.full_address = "Irving, TX, 75063, US"
assert_equal "Irving, TX, 75063, US", @loc.formatted_address
@loc.formatted_address = "San Francisco, CA, 94105, US"
@loc.full_address = "Irving, TX, 75063, US"
assert_equal "San Francisco, CA, 94105, US", @loc.formatted_address
end

def test_hash
@loc.city = "San Francisco"
@loc.state = "CA"
Expand Down
18 changes: 18 additions & 0 deletions test/test_google_geocoder.rb
Expand Up @@ -190,6 +190,24 @@ def test_google_suggested_bounds_url
Geokit::Geocoders::GoogleGeocoder.geocode("Winnetka", bias: bounds)
end

def test_google_place_id
VCR.use_cassette("google_full_v3_20") do
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@full_address_short_zip)}"
TestHelper.expects(:last_url).with(url)
res = Geokit::Geocoders::GoogleGeocoder.geocode(@full_address_short_zip)
assert_equal 'EjExMDAgU3BlYXIgU3RyZWV0ICM1LCBTYW4gRnJhbmNpc2NvLCBDQSA5NDEwNSwgVVNB', res.place_id
end
end

def test_google_formatted_address
VCR.use_cassette("google_full_v3_20") do
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@full_address_short_zip)}"
TestHelper.expects(:last_url).with(url)
res = Geokit::Geocoders::GoogleGeocoder.geocode(@full_address_short_zip)
assert_equal '100 Spear Street #5, San Francisco, CA 94105, USA', res.formatted_address
end
end

def test_service_unavailable
response = MockFailure.new
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
Expand Down

0 comments on commit 138999c

Please sign in to comment.