Class: ActiveCouch::Connection
- Inherits:
-
Object
- Object
- ActiveCouch::Connection
- Defined in:
- lib/active_couch/connection.rb
Overview
Class to handle connections to remote web services. This class is used by ActiveCouch::Base to interface with REST services.
Instance Attribute Summary collapse
-
#site ⇒ Object
Returns the value of attribute site.
Class Method Summary collapse
Instance Method Summary collapse
-
#delete(path, headers = {}) ⇒ Object
Execute a DELETE request (see HTTP protocol documentation if unfamiliar).
-
#get(path, headers = {}) ⇒ Object
Execute a GET request.
-
#initialize(site) ⇒ Connection
constructor
The
site
parameter is required and will set thesite
attribute to the URI for the remote resource service. -
#post(path, body = '', headers = {}) ⇒ Object
Execute a POST request.
-
#put(path, body = '', headers = {}) ⇒ Object
Execute a PUT request (see HTTP protocol documentation if unfamiliar).
Constructor Details
#initialize(site) ⇒ Connection
The site
parameter is required and will set the site
attribute to the URI for the remote resource service.
60 61 62 63 |
# File 'lib/active_couch/connection.rb', line 60 def initialize(site) raise ArgumentError, 'Missing site URI' unless site init_site_with_path(site) end |
Instance Attribute Details
#site ⇒ Object
Returns the value of attribute site.
50 51 52 |
# File 'lib/active_couch/connection.rb', line 50 def site @site end |
Class Method Details
.requests ⇒ Object
53 54 55 |
# File 'lib/active_couch/connection.rb', line 53 def requests @@requests ||= [] end |
Instance Method Details
#delete(path, headers = {}) ⇒ Object
Execute a DELETE request (see HTTP protocol documentation if unfamiliar). Used to delete resources.
78 79 80 |
# File 'lib/active_couch/connection.rb', line 78 def delete(path, headers = {}) request(:delete, path, build_request_headers(headers)) end |
#get(path, headers = {}) ⇒ Object
Execute a GET request. Used to get (find) resources.
72 73 74 |
# File 'lib/active_couch/connection.rb', line 72 def get(path, headers = {}) request(:get, path, build_request_headers(headers)).body end |
#post(path, body = '', headers = {}) ⇒ Object
Execute a POST request. Used to create new resources.
90 91 92 |
# File 'lib/active_couch/connection.rb', line 90 def post(path, body = '', headers = {}) request(:post, path, body.to_s, build_request_headers(headers)) end |
#put(path, body = '', headers = {}) ⇒ Object
Execute a PUT request (see HTTP protocol documentation if unfamiliar). Used to update resources.
84 85 86 |
# File 'lib/active_couch/connection.rb', line 84 def put(path, body = '', headers = {}) request(:put, path, body.to_s, build_request_headers(headers)) end |