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.
Constant Summary collapse
- HTTP_FORMAT_HEADER_NAMES =
{ :get => 'Accept', :put => 'Content-Type', :post => 'Content-Type', :delete => 'Accept', :head => 'Accept' }
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#password ⇒ Object
Returns the value of attribute password.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#site ⇒ Object
Returns the value of attribute site.
-
#ssl_options ⇒ Object
Returns the value of attribute ssl_options.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#user ⇒ Object
Returns the value of attribute user.
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.
-
#head(path, headers = {}) ⇒ Object
Execute a HEAD request.
-
#initialize(site, format = ) ⇒ 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, format = ) ⇒ Connection
The site
parameter is required and will set the site
attribute to the URI for the remote resource service.
96 97 98 99 100 101 |
# File 'lib/active_resource/connection.rb', line 96 def initialize(site, format = ActiveResource::Formats[:xml]) raise ArgumentError, 'Missing site URI' unless site @user = @password = nil self.site = site self.format = format end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
86 87 88 |
# File 'lib/active_resource/connection.rb', line 86 def format @format end |
#password ⇒ Object
Returns the value of attribute password.
85 86 87 |
# File 'lib/active_resource/connection.rb', line 85 def password @password end |
#proxy ⇒ Object
Returns the value of attribute proxy.
85 86 87 |
# File 'lib/active_resource/connection.rb', line 85 def proxy @proxy end |
#site ⇒ Object
Returns the value of attribute site.
85 86 87 |
# File 'lib/active_resource/connection.rb', line 85 def site @site end |
#ssl_options ⇒ Object
Returns the value of attribute ssl_options.
85 86 87 |
# File 'lib/active_resource/connection.rb', line 85 def @ssl_options end |
#timeout ⇒ Object
Returns the value of attribute timeout.
85 86 87 |
# File 'lib/active_resource/connection.rb', line 85 def timeout @timeout end |
#user ⇒ Object
Returns the value of attribute user.
85 86 87 |
# File 'lib/active_resource/connection.rb', line 85 def user @user end |
Class Method Details
.requests ⇒ Object
89 90 91 |
# File 'lib/active_resource/connection.rb', line 89 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.
143 144 145 |
# File 'lib/active_resource/connection.rb', line 143 def delete(path, headers = {}) request(:delete, path, build_request_headers(headers, :delete)) end |
#get(path, headers = {}) ⇒ Object
Execute a GET request. Used to get (find) resources.
137 138 139 |
# File 'lib/active_resource/connection.rb', line 137 def get(path, headers = {}) format.decode(request(:get, path, build_request_headers(headers, :get)).body) end |
#head(path, headers = {}) ⇒ Object
Execute a HEAD request. Used to obtain meta-information about resources, such as whether they exist and their size (via response headers).
161 162 163 |
# File 'lib/active_resource/connection.rb', line 161 def head(path, headers = {}) request(:head, path, build_request_headers(headers, :head)) end |
#post(path, body = '', headers = {}) ⇒ Object
Execute a POST request. Used to create new resources.
155 156 157 |
# File 'lib/active_resource/connection.rb', line 155 def post(path, body = '', headers = {}) request(:post, path, body.to_s, build_request_headers(headers, :post)) end |
#put(path, body = '', headers = {}) ⇒ Object
Execute a PUT request (see HTTP protocol documentation if unfamiliar). Used to update resources.
149 150 151 |
# File 'lib/active_resource/connection.rb', line 149 def put(path, body = '', headers = {}) request(:put, path, body.to_s, build_request_headers(headers, :put)) end |