Class: GoogleGeocoding::Geocoder
- Inherits:
-
Object
- Object
- GoogleGeocoding::Geocoder
- Defined in:
- lib/google_geocoding/geocoder.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Geocoder
constructor
Creates a new geocoder instance.
-
#query(address) ⇒ Response
Performs a geocoding request against google for the given address.
Constructor Details
#initialize(options = {}) ⇒ Geocoder
Creates a new geocoder instance.
9 10 11 12 13 14 15 |
# File 'lib/google_geocoding/geocoder.rb', line 9 def initialize( = {}) @options = @sess = Patron::Session.new @sess.timeout = [:timeout] || 10 @sess.base_url = "http://maps.google.com/maps/geo" @sess.headers['User-Agent'] = [:user_agent] end |
Class Method Details
.query(address, options = {}) ⇒ Object
3 4 5 |
# File 'lib/google_geocoding/geocoder.rb', line 3 def self.query(address, = {}) self.new().query(address) end |
Instance Method Details
#query(address) ⇒ Response
Performs a geocoding request against google for the given address.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/google_geocoding/geocoder.rb', line 21 def query(address) params = "?q=#{URI.encode(address.to_s)}" params << "&key=#{@options[:api_key]}" if @options[:api_key] resp = @sess.get(params) if (200...300).include?(resp.status) Response.new(resp.body) else raise Errors::HttpError.new(address, resp) end end |