Class to handle connections to remote web services. This class is used by
ActiveResource::Base to interface with REST
services.
Methods
Constants
| HTTP_FORMAT_HEADER_NAMES |
= |
{ :get => 'Accept', :put => 'Content-Type', :post => 'Content-Type', :delete => 'Accept' |
Attributes
|
[RW]
|
format |
|
|
[R]
|
password |
|
|
[R]
|
site |
|
|
[R]
|
timeout |
|
|
[R]
|
user |
|
Public Class methods
new(site, format = ActiveResource::Formats[:xml])
The site parameter is required and will set the site
attribute to the URI for the remote resource service.
Source: show
| on GitHub
84: def initialize(site, format = ActiveResource::Formats[:xml])
85: raise ArgumentError, 'Missing site URI' unless site
86: @user = @password = nil
87: self.site = site
88: self.format = format
89: end
Source: show
| on GitHub
77: def requests
78: @@requests ||= []
79: end
Public Instance methods
delete(path, headers = {})
Execute a DELETE request (see HTTP protocol documentation if unfamiliar).
Used to delete resources.
Source: show
| on GitHub
121: def delete(path, headers = {})
122: request(:delete, path, build_request_headers(headers, :delete))
123: end
Execute a GET request. Used to get
(find) resources.
Source: show
| on GitHub
115: def get(path, headers = {})
116: format.decode(request(:get, path, build_request_headers(headers, :get)).body)
117: end
Execute a HEAD request. Used to obtain meta-information about resources,
such as whether they exist and their size (via response headers).
Source: show
| on GitHub
139: def head(path, headers = {})
140: request(:head, path, build_request_headers(headers))
141: end
Set password for remote service.
Source: show
| on GitHub
104: def password=(password)
105: @password = password
106: end
post(path, body = '', headers = {})
Execute a POST request. Used to create new resources.
Source: show
| on GitHub
133: def post(path, body = '', headers = {})
134: request(:post, path, body.to_s, build_request_headers(headers, :post))
135: end
put(path, body = '', headers = {})
Execute a PUT request (see HTTP protocol documentation if unfamiliar). Used
to update resources.
Source: show
| on GitHub
127: def put(path, body = '', headers = {})
128: request(:put, path, body.to_s, build_request_headers(headers, :put))
129: end
Set URI for remote service.
Source: show
| on GitHub
92: def site=(site)
93: @site = site.is_a?(URI) ? site : URI.parse(site)
94: @user = URI.decode(@site.user) if @site.user
95: @password = URI.decode(@site.password) if @site.password
96: end
Set the number of seconds after which HTTP requests to the remote service should
time out.
Source: show
| on GitHub
109: def timeout=(timeout)
110: @timeout = timeout
111: end
Set user for remote service.
Source: show
| on GitHub
99: def user=(user)
100: @user = user
101: end