class ChimeraHttpClient::Queue

Public Instance Methods

add(method, endpoint, options = {}) click to toggle source
# 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 head options trace).include?(http_method)

  queued_requests << create_request(
    method: http_method,
    url: url(endpoint),
    body: extract_body(options),
    headers: extract_headers(options, default_headers),
    options: augmented_options(options)
  )
end
empty() click to toggle source
# File lib/chimera_http_client/queue.rb, line 30
def empty
  @queued_requests = []
end
execute() click to toggle source
# File lib/chimera_http_client/queue.rb, line 16
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_requests() click to toggle source
# File lib/chimera_http_client/queue.rb, line 34
def queued_requests
  @queued_requests ||= []
end

Private Instance Methods

create_request(method:, url:, body:, headers:, options:) click to toggle source
# File lib/chimera_http_client/queue.rb, line 40
def create_request(method:, url:, body:, headers:, options:)
  instance_options = {
    deserializer: @deserializer,
    logger: @logger,
    monitor: @monitor,
  }

  Request.new(instance_options).create(
    method: method,
    url: url,
    body: body,
    headers: headers,
    options: options
  )
end
hydra() click to toggle source
# File lib/chimera_http_client/queue.rb, line 56
def hydra
  @hydra ||= Typhoeus::Hydra.new
end