Class: Rester::Client::Adapters::Adapter
- Inherits:
-
Object
- Object
- Rester::Client::Adapters::Adapter
- Defined in:
- lib/rester/client/adapters/adapter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#timeout ⇒ Object
readonly
Class Methods.
Class Method Summary collapse
-
.can_connect_to?(service) ⇒ Boolean
Returns whether or not the Adapter can connect to the service.
Instance Method Summary collapse
-
#connect(*args) ⇒ Object
Connect to a service.
-
#connected? ⇒ Boolean
Returns whether or not the Adapter is connected to a service.
-
#headers(new_headers = {}) ⇒ Object
Returns the headers defined for this Adapter.
-
#initialize(service = nil, opts = {}) ⇒ Adapter
constructor
A new instance of Adapter.
-
#request(verb, path, params = nil) ⇒ Object
Sends a request (using one of the subclass adapters) to the service.
-
#request!(verb, path, encoded_data) ⇒ Object
Sends an HTTP request to the service.
Constructor Details
#initialize(service = nil, opts = {}) ⇒ Adapter
Returns a new instance of Adapter.
14 15 16 17 |
# File 'lib/rester/client/adapters/adapter.rb', line 14 def initialize(service = nil, opts = {}) @timeout = opts[:timeout] connect(service) if service end |
Instance Attribute Details
#timeout ⇒ Object (readonly)
Class Methods
12 13 14 |
# File 'lib/rester/client/adapters/adapter.rb', line 12 def timeout @timeout end |
Class Method Details
.can_connect_to?(service) ⇒ Boolean
Returns whether or not the Adapter can connect to the service
7 8 9 |
# File 'lib/rester/client/adapters/adapter.rb', line 7 def can_connect_to?(service) raise NotImplementedError end |
Instance Method Details
#connect(*args) ⇒ Object
Connect to a service. The specific arguments depend on the Adapter subclass.
29 30 31 |
# File 'lib/rester/client/adapters/adapter.rb', line 29 def connect(*args) raise NotImplementedError end |
#connected? ⇒ Boolean
Returns whether or not the Adapter is connected to a service.
35 36 37 |
# File 'lib/rester/client/adapters/adapter.rb', line 35 def connected? raise NotImplementedError end |
#headers(new_headers = {}) ⇒ Object
Returns the headers defined for this Adapter. Optionally, you may also define additional headers you’d like to add/override.
22 23 24 |
# File 'lib/rester/client/adapters/adapter.rb', line 22 def headers(new_headers = {}) (@headers ||= {}).merge!(new_headers) end |
#request(verb, path, params = nil) ⇒ Object
Sends a request (using one of the subclass adapters) to the service.
‘params` should be a hash if specified.
43 44 45 46 |
# 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) ⇒ Object
Sends an HTTP request to the service.
‘encoded_data` should be URL encoded set of parameters (e.g., “key1=value1&key2=value2”)
53 54 55 |
# File 'lib/rester/client/adapters/adapter.rb', line 53 def request!(verb, path, encoded_data) fail NotImplementedError end |