Class: Dor::Workflow::Client::Requestor
- Inherits:
-
Object
- Object
- Dor::Workflow::Client::Requestor
- Defined in:
- lib/dor/workflow/client/requestor.rb
Overview
Makes requests to the workflow service and retries them if necessary.
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize(connection:) ⇒ Requestor
constructor
A new instance of Requestor.
-
#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.
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
#connection ⇒ Object (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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dor/workflow/client/requestor.rb', line 22 def request(uri_string, meth = 'get', payload = '', opts = {}) response = send_workflow_resource_request(uri_string, meth, payload, opts) response.body rescue Faraday::Error => e # `status` is set to `nil` if: # * `e` does not respond to `:response` # * `e` responds to `:response` and: # * `e.response` is `nil` # * `e.response` is a hash missing the `:status` key # else it is set to the value of `e.response[:status]` status = e.try(:response)&.fetch(:status, nil) msg = "Failed to retrieve resource: #{meth} #{base_url}/#{uri_string}" msg += " (HTTP status #{status})" unless status.nil? raise (status == 404 ? Dor::MissingWorkflowException : Dor::WorkflowException), msg end |