Class: Graticule::Geocoder::Rest
- Inherits:
-
Object
- Object
- Graticule::Geocoder::Rest
- Defined in:
- lib/graticule/geocoder/rest.rb
Overview
Abstract class for implementing REST APIs.
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.
If you have extra URL paramaters (application id, output type) or need to perform URL customization, override make_url
.
class FakeService < RCRest
class Error < RCRest::Error; end
def initialize(appid)
@appid = appid
@url = URI.parse 'http://example.com/test'
end
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(xml)
# return Location
end
def test(query)
get :q => query
end
end
Direct Known Subclasses
GeocoderCa, GeocoderUs, Google, LocalSearchMaps, MetaCarta, PostcodeAnywhere, Yahoo
Instance Method Summary collapse
-
#initialize ⇒ Rest
constructor
Web services initializer.
Constructor Details
#initialize ⇒ Rest
Web services initializer.
Concrete web services implementations must set the url
instance variable which must be a URI.
53 54 55 |
# File 'lib/graticule/geocoder/rest.rb', line 53 def initialize raise NotImplementedError end |