Class to handle connections to remote web services. This class is used by ActiveResource::Base to interface with REST services.

Methods
D
G
H
N
P
R
S
T
U
Constants
HTTP_FORMAT_HEADER_NAMES = { :get => 'Accept', :put => 'Content-Type', :post => 'Content-Type', :delete => 'Accept', :head => 'Accept' }
 
Attributes
[RW] format
[R] password
[R] proxy
[R] site
[R] ssl_options
[R] timeout
[R] user
Class Public methods
new(site, format = ActiveResource::Formats[:xml])

The siteparameter is required and will set the siteattribute to the URI for the remote resource service.

# File activeresource/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
requests()
# File activeresource/lib/active_resource/connection.rb, line 89
def requests
  @@requests ||= []
end
Instance Public methods
delete(path, headers = {})

Execute a DELETE request (see HTTP protocol documentation if unfamiliar). Used to delete resources.

# File activeresource/lib/active_resource/connection.rb, line 143
def delete(path, headers = {})
  request(:delete, path, build_request_headers(headers, :delete))
end
get(path, headers = {})

Execute a GET request. Used to get (find) resources.

# File activeresource/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 = {})

Execute a HEAD request. Used to obtain meta-information about resources, such as whether they exist and their size (via response headers).

# File activeresource/lib/active_resource/connection.rb, line 161
def head(path, headers = {})
  request(:head, path, build_request_headers(headers, :head))
end
password=(password)

Set password for remote service.

# File activeresource/lib/active_resource/connection.rb, line 121
def password=(password)
  @password = password
end
post(path, body = '', headers = {})

Execute a POST request. Used to create new resources.

# File activeresource/lib/active_resource/connection.rb, line 155
def post(path, body = '', headers = {})
  request(:post, path, body.to_s, build_request_headers(headers, :post))
end
proxy=(proxy)

Set the proxy for remote service.

# File activeresource/lib/active_resource/connection.rb, line 111
def proxy=(proxy)
  @proxy = proxy.is_a?(URI) ? proxy : URI.parse(proxy)
end
put(path, body = '', headers = {})

Execute a PUT request (see HTTP protocol documentation if unfamiliar). Used to update resources.

# File activeresource/lib/active_resource/connection.rb, line 149
def put(path, body = '', headers = {})
  request(:put, path, body.to_s, build_request_headers(headers, :put))
end
site=(site)

Set URI for remote service.

# File activeresource/lib/active_resource/connection.rb, line 104
def site=(site)
  @site = site.is_a?(URI) ? site : URI.parse(site)
  @user = URI.decode(@site.user) if @site.user
  @password = URI.decode(@site.password) if @site.password
end
ssl_options=(opts={})

Hash of options applied to Net::HTTP instance when siteprotocol is 'https'.

# File activeresource/lib/active_resource/connection.rb, line 131
def ssl_options=(opts={})
  @ssl_options = opts
end
timeout=(timeout)

Set the number of seconds after which HTTP requests to the remote service should time out.

# File activeresource/lib/active_resource/connection.rb, line 126
def timeout=(timeout)
  @timeout = timeout
end
user=(user)

Set the user for remote service.

# File activeresource/lib/active_resource/connection.rb, line 116
def user=(user)
  @user = user
end