Method: VCAP::Services::Api::AsyncHttpRequest.request

Defined in:
lib/services/api/async_requests.rb

.request(url, token, verb, timeout, msg = VCAP::Services::Api::EMPTY_REQUEST) ⇒ Object

Raises:

  • (UnexpectedResponse)


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/services/api/async_requests.rb', line 35

def request(url, token, verb, timeout, msg=VCAP::Services::Api::EMPTY_REQUEST)
  req = new(url, token, verb, timeout, msg)
  f = Fiber.current
  req.callback { f.resume(req) }
  req.errback  { f.resume(req) }
  http = Fiber.yield
  raise UnexpectedResponse, "Error sending request #{msg.extract.to_json} to gateway #{@url}: #{http.error}" unless http.error.empty?
  code = http.response_header.status.to_i
  body = http.response
  [code, body]
end