class Rester::Client::Adapters::Adapter

Constants

VALID_VERBS

Attributes

timeout[R]

Public Class Methods

can_connect_to?(service) click to toggle source

Returns whether or not the Adapter can connect to the service

# File lib/rester/client/adapters/adapter.rb, line 7
def can_connect_to?(service)
  raise NotImplementedError
end
new(service = nil, opts = {}) click to toggle source
# File lib/rester/client/adapters/adapter.rb, line 14
def initialize(service = nil, opts = {})
  @timeout = opts[:timeout]
  connect(service) if service
end

Public Instance Methods

connect(*args) click to toggle source

Connect to a service. The specific arguments depend on the Adapter subclass.

# File lib/rester/client/adapters/adapter.rb, line 29
def connect(*args)
  raise NotImplementedError
end
connected?() click to toggle source

Returns whether or not the Adapter is connected to a service.

# File lib/rester/client/adapters/adapter.rb, line 35
def connected?
  raise NotImplementedError
end
headers(new_headers = {}) click to toggle source

Returns the headers defined for this Adapter. Optionally, you may also define additional headers you'd like to add/override.

# File lib/rester/client/adapters/adapter.rb, line 22
def headers(new_headers = {})
  (@headers ||= {}).merge!(new_headers)
end
request(verb, path, params = nil) click to toggle source

Sends a request (using one of the subclass adapters) to the service.

`params` should be a hash if specified.

# File lib/rester/client/adapters/adapter.rb, line 43
def request(verb, path, params = nil)
  _validate_verb(verb)
  request!(verb, path.to_s, Utils.encode_www_data(params))
end
request!(verb, path, encoded_data) click to toggle source

Sends an HTTP request to the service.

`encoded_data` should be URL encoded set of parameters (e.g., “key1=value1&key2=value2”)

# File lib/rester/client/adapters/adapter.rb, line 53
def request!(verb, path, encoded_data)
  fail NotImplementedError
end

Protected Instance Methods

headers=(h) click to toggle source
# File lib/rester/client/adapters/adapter.rb, line 67
def headers=(h)
  @headers = h
end

Private Instance Methods

_validate_verb(verb) click to toggle source
# File lib/rester/client/adapters/adapter.rb, line 80
def _validate_verb(verb)
  VALID_VERBS[verb] or
    fail ArgumentError, "Invalid verb: #{verb.inspect}"
end