Class: Graticule::Geocoder::Rest

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeRest

Web services initializer.

Concrete web services implementations must set the url instance variable which must be a URI.

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/graticule/geocoder/rest.rb', line 53

def initialize
  raise NotImplementedError
end