Class: RestCore::RestClient

Inherits:
Engine
  • Object
show all
Defined in:
lib/rest-core/engine/rest-client.rb

Constant Summary

Constant Summary

Constants included from Middleware

Middleware::UNRESERVED

Constants included from RestCore

ASYNC, CLIENT, DRY, FAIL, HIJACK, LOG, PROMISE, REQUEST_HEADERS, REQUEST_METHOD, REQUEST_PATH, REQUEST_PAYLOAD, REQUEST_QUERY, REQUEST_URI, RESPONSE_BODY, RESPONSE_HEADERS, RESPONSE_KEY, RESPONSE_SOCKET, RESPONSE_STATUS, TIMER, Universal, VERSION

Instance Method Summary (collapse)

Methods inherited from Engine

#call

Methods included from Middleware

#call, contain_binary?, escape, #fail, #id, included, #log, percent_encode, request_uri, #run, string_keys

Methods included from RestCore

eagerload, id

Instance Method Details

- (Object) request(promise, env)



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rest-core/engine/rest-client.rb', line 7

def request promise, env
  open_timeout, read_timeout = calculate_timeout(env[TIMER])
  payload, headers = payload_and_headers(env)
  res = ::RestClient::Request.execute(:method   => env[REQUEST_METHOD],
                                      :url      => env[REQUEST_URI]   ,
                                      :payload  => payload            ,
                                      :headers  => headers            ,
                                      :max_redirects => 0             ,
                                      :open_timeout => open_timeout   ,
                                           :timeout => read_timeout   )
  promise.fulfill(res.body, res.code, normalize_headers(res.raw_headers))
rescue ::RestClient::Exception => e
  if res = e.response
    # we don't want to raise an exception for 404 requests
    promise.fulfill(res.body, res.code, normalize_headers(res.raw_headers))
  else
    promise.reject(e)
  end

rescue Exception => e
  promise.reject(e)
end