Class: ChimeraHttpClient::Queue

Inherits:
Base
  • Object
show all
Defined in:
lib/chimera_http_client/queue.rb

Constant Summary

Constants inherited from Base

Base::USER_AGENT

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from ChimeraHttpClient::Base

Instance Method Details

#add(method, endpoint, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/chimera_http_client/queue.rb', line 3

def add(method, endpoint, options = {})
  http_method = method.downcase.to_sym
  options[:body_optional] = true if %i[get delete].include?(http_method)

  body = extract_body(options)
  headers = extract_headers(options, default_headers)

  req = Request.new(logger: @logger).create(
    url: url(endpoint),
    method: http_method,
    body: body,
    options: augmented_options(options),
    headers: headers
  )

  queued_requests << req
end

#emptyObject



35
36
37
# File 'lib/chimera_http_client/queue.rb', line 35

def empty
  @queued_requests = []
end

#executeObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chimera_http_client/queue.rb', line 21

def execute
  queued_requests.each do |request|
    hydra.queue(request.request)
  end

  hydra.run

  responses = queued_requests.map { |request| request.result }

  empty

  responses
end

#queued_requestsObject



39
40
41
# File 'lib/chimera_http_client/queue.rb', line 39

def queued_requests
  @queued_requests ||= []
end