Class: Dor::Workflow::Client::Requestor

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/workflow/client/requestor.rb

Overview

Makes requests to the workflow service and retries them if necessary.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:) ⇒ Requestor

Returns a new instance of Requestor.



8
9
10
# File 'lib/dor/workflow/client/requestor.rb', line 8

def initialize(connection:)
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



12
13
14
# File 'lib/dor/workflow/client/requestor.rb', line 12

def connection
  @connection
end

Instance Method Details

#request(uri_string, meth = 'get', payload = '', opts = {}) ⇒ Object

calls workflow_resource[uri_string]."#meth" with variable number of optional arguments The point of this is to wrap ALL remote calls with consistent error handling and logging

Parameters:

  • uri_string (String)

    resource to request

  • meth (String) (defaults to: 'get')

    REST method to use on resource (get, put, post, delete, etc.)

  • payload (String) (defaults to: '')

    body for (e.g. put) request

  • opts (Hash) (defaults to: {})

    addtional headers options

Returns:

  • (Object)

    response from method



21
22
23
24
25
26
27
28
# File 'lib/dor/workflow/client/requestor.rb', line 21

def request(uri_string, meth = 'get', payload = '', opts = {})
  response = send_workflow_resource_request(uri_string, meth, payload, opts)
  response.body
rescue Faraday::Error => e
  msg = "Failed to retrieve resource: #{meth} #{base_url}/#{uri_string}"
  msg += " (HTTP status #{e.response[:status]})" if e.respond_to?(:response) && e.response
  raise Dor::WorkflowException, msg
end