Class: ActiveResource::Connection
- Inherits:
-
Object
- Object
- ActiveResource::Connection
- Defined in:
- lib/active_resource/connection.rb,
lib/active_resource/http_mock.rb
Overview
Class to handle connections to remote web services. This class is used by ActiveResource::Base to interface with REST services.
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#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, format = ) ⇒ Connection
constructor
The
siteparameter is required and will set thesiteattribute 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, format = ) ⇒ Connection
The site parameter is required and will set the site attribute to the URI for the remote resource service.
69 70 71 72 73 |
# File 'lib/active_resource/connection.rb', line 69 def initialize(site, format = ActiveResource::Formats[:xml]) raise ArgumentError, 'Missing site URI' unless site self.site = site self.format = format end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
59 60 61 |
# File 'lib/active_resource/connection.rb', line 59 def format @format end |
#site ⇒ Object
Returns the value of attribute site.
58 59 60 |
# File 'lib/active_resource/connection.rb', line 58 def site @site end |
Class Method Details
.requests ⇒ Object
62 63 64 |
# File 'lib/active_resource/connection.rb', line 62 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.
88 89 90 |
# File 'lib/active_resource/connection.rb', line 88 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.
82 83 84 |
# File 'lib/active_resource/connection.rb', line 82 def get(path, headers = {}) format.decode(request(:get, path, build_request_headers(headers)).body) end |
#post(path, body = '', headers = {}) ⇒ Object
Execute a POST request. Used to create new resources.
100 101 102 |
# File 'lib/active_resource/connection.rb', line 100 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.
94 95 96 |
# File 'lib/active_resource/connection.rb', line 94 def put(path, body = '', headers = {}) request(:put, path, body.to_s, build_request_headers(headers)) end |