class 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
Public Class Methods
Source
# File lib/active_resource/connection.rb, line 33 def initialize(site, format = ActiveResource::Formats::JsonFormat, logger: nil) raise ArgumentError, "Missing site URI" unless site @proxy = @user = @password = @bearer_token = nil self.site = site self.format = format self.logger = logger end
The site parameter is required and will set the site attribute to the URI for the remote resource service.
Source
# File lib/active_resource/connection.rb, line 26 def requests @@requests ||= [] end
Public Instance Methods
Source
# File lib/active_resource/connection.rb, line 64 def auth_type=(auth_type) @auth_type = legitimize_auth_type(auth_type) end
Sets the auth type for remote service.
Source
# File lib/active_resource/connection.rb, line 88 def delete(path, headers = {}) with_auth { request(:delete, path, build_request_headers(headers, :delete, self.site.merge(path))) } end
Executes a DELETE request (see HTTP protocol documentation if unfamiliar). Used to delete resources.
Source
# File lib/active_resource/connection.rb, line 82 def get(path, headers = {}) with_auth { request(:get, path, build_request_headers(headers, :get, self.site.merge(path))) } end
Executes a GET request. Used to get (find) resources.
Source
# File lib/active_resource/connection.rb, line 112 def head(path, headers = {}) with_auth { request(:head, path, build_request_headers(headers, :head, self.site.merge(path))) } end
Executes a HEAD request. Used to obtain meta-information about resources, such as whether they exist and their size (via response headers).
Source
# File lib/active_resource/connection.rb, line 94 def patch(path, body = "", headers = {}) with_auth { request(:patch, path, body.to_s, build_request_headers(headers, :patch, self.site.merge(path))) } end
Executes a PATCH request (see HTTP protocol documentation if unfamiliar). Used to update resources.
Source
# File lib/active_resource/connection.rb, line 106 def post(path, body = "", headers = {}) with_auth { request(:post, path, body.to_s, build_request_headers(headers, :post, self.site.merge(path))) } end
Executes a POST request. Used to create new resources.
Source
# File lib/active_resource/connection.rb, line 50 def proxy=(proxy) @proxy = proxy.is_a?(URI) ? proxy : URI.parse(proxy) end
Set the proxy for remote service.
Source
# File lib/active_resource/connection.rb, line 100 def put(path, body = "", headers = {}) with_auth { request(:put, path, body.to_s, build_request_headers(headers, :put, self.site.merge(path))) } end
Executes a PUT request (see HTTP protocol documentation if unfamiliar). Used to update resources.
Source
# File lib/active_resource/connection.rb, line 42 def site=(site) @site = site.is_a?(URI) ? site : URI.parse(site) @ssl_options ||= {} if @site.is_a?(URI::HTTPS) @user = URI_PARSER.unescape(@site.user) if @site.user @password = URI_PARSER.unescape(@site.password) if @site.password end
Set URI for remote service.