Class: ActiveResource::Connection
- Inherits:
-
Object
- Object
- ActiveResource::Connection
- Defined in:
- activeresource/lib/active_resource/connection.rb,
activeresource/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
- HTTP_FORMAT_HEADER_NAMES =
{ :get => 'Accept', :put => 'Content-Type', :post => 'Content-Type', :delete => 'Accept', :head => 'Accept' }
Instance Attribute Summary (collapse)
-
- (Object) auth_type
Returns the value of attribute auth_type.
-
- (Object) format
Returns the value of attribute format.
-
- (Object) password
Returns the value of attribute password.
-
- (Object) proxy
Returns the value of attribute proxy.
-
- (Object) site
Returns the value of attribute site.
-
- (Object) ssl_options
Returns the value of attribute ssl_options.
-
- (Object) timeout
Returns the value of attribute timeout.
-
- (Object) user
Returns the value of attribute user.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Object) delete(path, headers = {})
Executes a DELETE request (see HTTP protocol documentation if unfamiliar).
-
- (Object) get(path, headers = {})
Executes a GET request.
-
- (Object) head(path, headers = {})
Executes a HEAD request.
-
- (Connection) initialize(site, format = ActiveResource::Formats::XmlFormat)
constructor
The site parameter is required and will set the site attribute to the URI for the remote resource service.
-
- (Object) post(path, body = '', headers = {})
Executes a POST request.
-
- (Object) put(path, body = '', headers = {})
Executes a PUT request (see HTTP protocol documentation if unfamiliar).
Constructor Details
- (Connection) initialize(site, format = ActiveResource::Formats::XmlFormat)
The site parameter is required and will set the site attribute to the URI for the remote resource service.
31 32 33 34 35 36 37 |
# File 'activeresource/lib/active_resource/connection.rb', line 31 def initialize(site, format = ActiveResource::Formats::XmlFormat) raise ArgumentError, 'Missing site URI' unless site @user = @password = nil @uri_parser = URI.const_defined?(:Parser) ? URI::Parser.new : URI self.site = site self.format = format end |
Instance Attribute Details
- (Object) auth_type
Returns the value of attribute auth_type
20 21 22 |
# File 'activeresource/lib/active_resource/connection.rb', line 20 def auth_type @auth_type end |
- (Object) format
Returns the value of attribute format
21 22 23 |
# File 'activeresource/lib/active_resource/connection.rb', line 21 def format @format end |
- (Object) password
Returns the value of attribute password
20 21 22 |
# File 'activeresource/lib/active_resource/connection.rb', line 20 def password @password end |
- (Object) proxy
Returns the value of attribute proxy
20 21 22 |
# File 'activeresource/lib/active_resource/connection.rb', line 20 def proxy @proxy end |
- (Object) site
Returns the value of attribute site
20 21 22 |
# File 'activeresource/lib/active_resource/connection.rb', line 20 def site @site end |
- (Object) ssl_options
Returns the value of attribute ssl_options
20 21 22 |
# File 'activeresource/lib/active_resource/connection.rb', line 20 def @ssl_options end |
- (Object) timeout
Returns the value of attribute timeout
20 21 22 |
# File 'activeresource/lib/active_resource/connection.rb', line 20 def timeout @timeout end |
- (Object) user
Returns the value of attribute user
20 21 22 |
# File 'activeresource/lib/active_resource/connection.rb', line 20 def user @user end |
Class Method Details
+ (Object) requests
24 25 26 |
# File 'activeresource/lib/active_resource/connection.rb', line 24 def requests @@requests ||= [] end |
Instance Method Details
- (Object) delete(path, headers = {})
Executes a DELETE request (see HTTP protocol documentation if unfamiliar). Used to delete resources.
84 85 86 |
# File 'activeresource/lib/active_resource/connection.rb', line 84 def delete(path, headers = {}) with_auth { request(:delete, path, build_request_headers(headers, :delete, self.site.merge(path))) } end |
- (Object) get(path, headers = {})
Executes a GET request. Used to get (find) resources.
78 79 80 |
# File 'activeresource/lib/active_resource/connection.rb', line 78 def get(path, headers = {}) with_auth { format.decode(request(:get, path, build_request_headers(headers, :get, self.site.merge(path))).body) } end |
- (Object) head(path, headers = {})
Executes a HEAD request. Used to obtain meta-information about resources, such as whether they exist and their size (via response headers).
102 103 104 |
# File 'activeresource/lib/active_resource/connection.rb', line 102 def head(path, headers = {}) with_auth { request(:head, path, build_request_headers(headers, :head, self.site.merge(path))) } end |
- (Object) post(path, body = '', headers = {})
Executes a POST request. Used to create new resources.
96 97 98 |
# File 'activeresource/lib/active_resource/connection.rb', line 96 def post(path, body = '', headers = {}) with_auth { request(:post, path, body.to_s, build_request_headers(headers, :post, self.site.merge(path))) } end |
- (Object) put(path, body = '', headers = {})
Executes a PUT request (see HTTP protocol documentation if unfamiliar). Used to update resources.
90 91 92 |
# File 'activeresource/lib/active_resource/connection.rb', line 90 def put(path, body = '', headers = {}) with_auth { request(:put, path, body.to_s, build_request_headers(headers, :put, self.site.merge(path))) } end |