Module: Almodovar

Defined in:
lib/almodovar.rb,
lib/almodovar/errors.rb,
lib/almodovar/to_xml.rb,
lib/almodovar/version.rb,
lib/almodovar/resource.rb,
lib/almodovar/digest_auth.rb,
lib/almodovar/http_client.rb,
lib/almodovar/http_accessor.rb,
lib/almodovar/single_resource.rb,
lib/almodovar/resource_collection.rb

Defined Under Namespace

Modules: HttpAccessor, ToXml Classes: AuthContext, ConnectTimeoutError, DigestAuth, HttpClient, HttpError, HttpResponse, ReceiveTimeoutError, Resource, ResourceCollection, SendTimeoutError, SingleResource, TimeoutError, TooManyRequestsError, UnprocessableEntityError

Constant Summary collapse

DEFAULT_SEND_TIMEOUT =
120
DEFAULT_CONNECT_TIMEOUT =
30
DEFAULT_RECEIVE_TIMEOUT =
120
HTTP_ERRORS =
{
  422 => UnprocessableEntityError,
  429 => TooManyRequestsError
}
VERSION =
'2.0.3'

Class Method Summary collapse

Class Method Details

.default_optionsObject

default_options allows to configure some settings on the underlying HTTP client used by Almodovar:

- send_timeout: Request sending timeout in sec. Defaults to 120
- connect_timeout: Connect timeout in sec. Defaults to 30
- receive_timeout: Response receiving timeout in sec. Defaults to 120
- user_agent: User-Agent header in HTTP request. defaults to Almodovar/#{Almodovar::VERSION}
- force_basic_auth: flag for sending Authorization header w/o getting 401 first. Useful during tests
- headers: is for providing default headers Hash that all HTTP
  requests should have, such as custom 'X-Request-Id' header in tracing.
  As Almodovar does not expose http API, this accept a proc which will be
  evaluated per request. You can override :headers with Almodovar::HTTPClient headers method
  or using Hash parameter in HTTP request methods but this is not accessible on default Almodovar usage.


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/almodovar.rb', line 37

def default_options
  default = {
    send_timeout: DEFAULT_SEND_TIMEOUT,
    connect_timeout: DEFAULT_CONNECT_TIMEOUT,
    receive_timeout: DEFAULT_RECEIVE_TIMEOUT,
    user_agent: "Almodovar/#{Almodovar::VERSION}",
    force_basic_auth: false,
    headers: nil,
  }
  default.merge(@default_options || {})
end

.default_options=(options = {}) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/almodovar.rb', line 49

def default_options=(options = {})
  @default_options ||= {}
  # Only assign provided keys too keep defaults when merging
  i(send_timeout connect_timeout receive_timeout force_basic_auth headers).each do |key|
    @default_options[key] = options[key] if options.has_key?(key)
  end
  @default_options
end

.reset_optionsObject



58
59
60
# File 'lib/almodovar.rb', line 58

def reset_options
  @default_options = nil
end

.Resource(url, auth = nil, params = {}) ⇒ Object



52
53
54
# File 'lib/almodovar/resource.rb', line 52

def self.Resource(url, auth = nil, params = {})
  Resource.new(url, auth, nil, params)
end