Skip to content

Commit

Permalink
Added Google's api key back in. Apparently it is still need on higher…
Browse files Browse the repository at this point in the history
… traffic sites
  • Loading branch information
bkeepers committed Oct 22, 2009
1 parent eaa5475 commit 9ed97db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
10 changes: 7 additions & 3 deletions lib/graticule/geocoder/google.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module Graticule #:nodoc:
module Geocoder #:nodoc:

# gg = Graticule.service(:google).new
# First you need a Google Maps API key. You can register for one here:
# http://www.google.com/apis/maps/signup.html
#
# gg = Graticule.service(:google).new(MAPS_API_KEY)
# location = gg.locate '1600 Amphitheater Pkwy, Mountain View, CA'
# p location.coordinates
# #=> [37.423111, -122.081783
Expand All @@ -23,7 +26,8 @@ class Google < Base
9 => :premise # Premise (building name, property name, shopping center, etc.) level accuracy.
}

def initialize
def initialize(key)
@key = key
@url = URI.parse 'http://maps.google.com/maps/geo'
end

Expand Down Expand Up @@ -116,7 +120,7 @@ def check_error(response) #:nodoc:
# Creates a URL from the Hash +params+.
# sets the output type to 'xml'.
def make_url(params) #:nodoc:
super params.merge(:oe => 'utf8', :output => 'xml', :sensor => false)
super params.merge(:key => @key, :oe => 'utf8', :output => 'xml', :sensor => false)
end
end
end
Expand Down
10 changes: 6 additions & 4 deletions test/config.yml.default
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
google:
key: PUT YOUR KEY HERE
responses:
success.xml: "http://maps.google.com/maps/geo?q=1600+amphitheatre+mtn+view+ca&output=xml"
missing_address.xml: "http://maps.google.com/maps/geo?output=xml"
unknown_address.xml: "http://maps.google.com/maps/geo?q=xxxxx&output=xml"
partial.xml: "http://maps.google.com/maps/geo?q=sf+ca&output=xml"
success.xml: "http://maps.google.com/maps/geo?q=1600+amphitheatre+mtn+view+ca&output=xml&key=:key"
badkey.xml: http://maps.google.com/maps/geo?q=1600+amphitheatre+mtn+view+ca&output=xml&key=this_is_a_bad_key
missing_address.xml: "http://maps.google.com/maps/geo?output=xml&key=:key"
unknown_address.xml: "http://maps.google.com/maps/geo?q=xxxxx&output=xml&key=:key"
partial.xml: "http://maps.google.com/maps/geo?q=sf+ca&output=xml&key=:key"
#unavailable.xml: no way to reproduce this
#limit.xml: no way to reproduce this
#server_error.xml: no way to reproduce this
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/responses/google/badkey.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.1"><Response><name>1600 amphitheatre mtn view ca</name><Status><code>610</code><request>geocode</request></Status></Response></kml>
7 changes: 6 additions & 1 deletion test/graticule/geocoder/google_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class GoogleTest < Test::Unit::TestCase
def setup
URI::HTTP.responses = []
URI::HTTP.uris = []
@geocoder = Google.new
@geocoder = Google.new('APP_ID')
end

def test_success
Expand Down Expand Up @@ -90,6 +90,11 @@ def test_locate_unknown_address
return unless prepare_response(:unknown_address)
assert_raises(AddressError) { @geocoder.locate 'x' }
end

def test_bad_key
return unless prepare_response(:badkey)
assert_raises(CredentialsError) { @geocoder.locate('x') }
end

protected

Expand Down

0 comments on commit 9ed97db

Please sign in to comment.