Class: Geocoder::Client
- Inherits:
-
Object
- Object
- Geocoder::Client
- Defined in:
- lib/geocoder/client.rb
Class Method Summary collapse
-
.key ⇒ Object
Returns the default key.
-
.key=(key) ⇒ Object
Sets the default key.
Instance Method Summary collapse
-
#first(address) ⇒ Address
Search for the first address that matches a string.
-
#initialize(key = nil) ⇒ Client
constructor
Initialize the Client.
-
#search(address) ⇒ Array<Address>
Search for addresses that match a string.
Constructor Details
#initialize(key = nil) ⇒ Client
Initialize the Client
If the key is passed it will be used in place of the default key
21 22 23 24 25 |
# File 'lib/geocoder/client.rb', line 21 def initialize(key=nil) @key ||= self.class.key @http = Patron::Session.new @http.base_url = 'http://maps.google.com/maps/geo' end |
Class Method Details
.key ⇒ Object
Returns the default key
7 8 9 |
# File 'lib/geocoder/client.rb', line 7 def self.key @key ||= raise(MapKeyError, 'Missing Key: Geocoder::Client.key=(key)') end |
.key=(key) ⇒ Object
Sets the default key
13 14 15 |
# File 'lib/geocoder/client.rb', line 13 def self.key=(key) @key = key end |
Instance Method Details
#first(address) ⇒ Address
Search for the first address that matches a string
52 53 54 |
# File 'lib/geocoder/client.rb', line 52 def first(address) search.first end |
#search(address) ⇒ Array<Address>
Search for addresses that match a string
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/geocoder/client.rb', line 33 def search(address) begin response = @http.get(hash_to_string(:q => address)) rescue StandardError => e raise(ConnectionError, e.) end unless response.status == 200 raise(ConnectionError, "Response Code: #{response.status}") end Response.new(response.body).addresses end |