Class: Dor::Workflow::Client::ConnectionFactory
- Inherits:
-
Object
- Object
- Dor::Workflow::Client::ConnectionFactory
- Defined in:
- lib/dor/workflow/client/connection_factory.rb
Overview
Builds Faraday connections that follow redirects
Class Method Summary collapse
Instance Method Summary collapse
- #build_connection ⇒ Object
-
#initialize(url, timeout:, logger:) ⇒ ConnectionFactory
constructor
A new instance of ConnectionFactory.
- #user_agent ⇒ Object
Constructor Details
#initialize(url, timeout:, logger:) ⇒ ConnectionFactory
Returns a new instance of ConnectionFactory.
12 13 14 15 16 |
# File 'lib/dor/workflow/client/connection_factory.rb', line 12 def initialize(url, timeout:, logger:) @url = url @timeout = timeout @logger = logger end |
Class Method Details
.build_connection(url, timeout:, logger:) ⇒ Object
8 9 10 |
# File 'lib/dor/workflow/client/connection_factory.rb', line 8 def self.build_connection(url, timeout:, logger:) new(url, timeout: timeout, logger: logger).build_connection end |
Instance Method Details
#build_connection ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dor/workflow/client/connection_factory.rb', line 18 def build_connection Faraday.new(url: url) do |faraday| faraday.use Faraday::Response::RaiseError # raise exceptions on 40x, 50x responses faraday..params_encoder = Faraday::FlatParamsEncoder if timeout faraday..timeout = timeout faraday..open_timeout = timeout end faraday.headers[:user_agent] = user_agent faraday.request :retry, max: 2, interval: 5.0, interval_randomness: 0.01, backoff_factor: 2.0, methods: retriable_methods, exceptions: retriable_exceptions, retry_block: retry_block, retry_statuses: retry_statuses faraday.adapter Faraday.default_adapter # Last middleware must be the adapter end end |
#user_agent ⇒ Object
40 41 42 |
# File 'lib/dor/workflow/client/connection_factory.rb', line 40 def user_agent "dor-workflow-client #{VERSION}" end |