Class: Graticule::Geocoder::Base
- Inherits:
-
Object
- Object
- Graticule::Geocoder::Base
- Defined in:
- lib/graticule/geocoder/base.rb
Overview
Abstract class for implementing geocoders.
Example
The following methods must be implemented in sublcasses:
initialize
-
Sets @url to the service enpoint.
check_error
-
Checks for errors in the server response.
parse_response
-
Extracts information from the server response.
Optionally, you can also override
prepare_response
-
Convert the string response into a different format
that gets passed on to
check_error
andparse_response
.
If you have extra URL paramaters (application id, output type) or need to perform URL customization, override make_url
.
class FakeGeocoder < Base
def initialize(appid)
@appid = appid
@url = URI.parse 'http://example.com/test'
end
def locate(query)
get :q => query
end
private
def check_error(xml)
raise Error, xml.elements['error'].text if xml.elements['error']
end
def make_url(params)
params[:appid] = @appid
super params
end
def parse_response(response)
# return Location
end
end
Direct Known Subclasses
Constant Summary collapse
- USER_AGENT =
"Mozilla/5.0 (compatible; Graticule/#{Graticule::Version::STRING}; http://graticule.rubyforge.org)"
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
55 56 57 |
# File 'lib/graticule/geocoder/base.rb', line 55 def initialize raise NotImplementedError end |