Class: ActiveResource::Connection

### Home Classes Methods

### In Files

- lib/active_resource/http_mock.rb
- lib/active_resource/connection.rb

### Parent

Object

### Methods

- ::new
- ::requests
- #auth_type=
- #delete
- #get
- #head
- #password=
- #post
- #proxy=
- #put
- #site=
- #ssl_options=
- #timeout=
- #user=

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- ActiveResource
- ActiveResource::BadRequest
- ActiveResource::Base
- ActiveResource::ClientError
- ActiveResource::Connection
- ActiveResource::CustomMethods
- ActiveResource::CustomMethods::ClassMethods
- ActiveResource::CustomMethods::InstanceMethods
- ActiveResource::Errors
- ActiveResource::ForbiddenAccess
- ActiveResource::Formats
- ActiveResource::Formats::JsonFormat
- ActiveResource::Formats::XmlFormat
- ActiveResource::HttpMock
- ActiveResource::InvalidRequestError
- ActiveResource::LogSubscriber
- ActiveResource::Observing
- ActiveResource::Railtie
- ActiveResource::Request
- ActiveResource::ResourceConflict
- ActiveResource::ResourceGone
- ActiveResource::ResourceNotFound
- ActiveResource::Response
- ActiveResource::SSLError
- ActiveResource::ServerError
- ActiveResource::TimeoutError
- ActiveResource::UnauthorizedAccess
- ActiveResource::Validations

No matching classes.

# ActiveResource::Connection

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

### Constants

HTTP_FORMAT_HEADER_NAMES

### Attributes

auth_type[R]
format[RW]
password[R]
proxy[R]
site[R]
ssl_options[R]
timeout[R]
user[R]

### Public Class Methods

new(site, format = ActiveResource::Formats::XmlFormat) click to toggle source

The `site` parameter is required and will set the `site` attribute to the URI for the remote resource service.

    # File 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

requests() click to toggle source

    # File lib/active_resource/connection.rb, line 24
    def requests
      @@requests ||= []
    end

### Public Instance Methods

auth_type=(auth_type) click to toggle source

Sets the auth type for remote service.

    # File lib/active_resource/connection.rb, line 62
    def auth_type=(auth_type)
      @auth_type = legitimize_auth_type(auth_type)
    end

delete(path, headers = {}) click to toggle source

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

    # File 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

get(path, headers = {}) click to toggle source

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

    # File 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

head(path, headers = {}) click to toggle source

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

    # File 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

password=(password) click to toggle source

Sets the password for remote service.

    # File lib/active_resource/connection.rb, line 57
    def password=(password)
      @password = password
    end

post(path, body = '', headers = {}) click to toggle source

Executes a POST request. Used to create new resources.

    # File 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

proxy=(proxy) click to toggle source

Set the proxy for remote service.

    # File lib/active_resource/connection.rb, line 47
    def proxy=(proxy)
      @proxy = proxy.is_a?(URI) ? proxy : @uri_parser.parse(proxy)
    end

put(path, body = '', headers = {}) click to toggle source

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

    # File 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

site=(site) click to toggle source

Set URI for remote service.

    # File lib/active_resource/connection.rb, line 40
    def site=(site)
      @site = site.is_a?(URI) ? site : @uri_parser.parse(site)
      @user = @uri_parser.unescape(@site.user) if @site.user
      @password = @uri_parser.unescape(@site.password) if @site.password
    end

ssl_options=(opts={}) click to toggle source

Hash of options applied to Net::HTTP instance when `site` protocol is ‘https’.

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

timeout=(timeout) click to toggle source

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

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

user=(user) click to toggle source

Sets the user for remote service.

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.