Class: Ashikawa::Core::FaradayFactory
- Inherits:
-
Object
- Object
- Ashikawa::Core::FaradayFactory
- Defined in:
- lib/ashikawa-core/faraday_factory.rb
Overview
Create Faraday objects
Constant Summary collapse
- DEFAULTS =
Defaults for the options of create connection
{ additional_request_middlewares: [], additional_response_middlewares: [], additional_middlewares: [], adapter: Faraday.default_adapter }
- DEFAULT_REQUEST_MIDDLEWARES =
Request middlewares that will be prepended
[:json, :x_arango_version]
- DEFAULT_RESPONSE_MIDDLEWARES =
Response middlewares that will be prepended
[:error_response, :json]
Instance Attribute Summary collapse
-
#debug_headers ⇒ Object
private
Debug headers to be used by Faraday.
Class Method Summary collapse
-
.create_connection(url, options) ⇒ Object
private
Create a Faraday object.
Instance Method Summary collapse
-
#faraday_for(url) ⇒ Faraday
private
Create the Faraday for the given URL.
-
#initialize(adapter, additional_request_middlewares, additional_response_middlewares, additional_middlewares) ⇒ FaradayFactory
constructor
private
Create a new Faraday Factory with additional middlewares.
-
#logger=(logger) ⇒ Object
private
Logger to be used by Faraday.
Constructor Details
#initialize(adapter, additional_request_middlewares, additional_response_middlewares, additional_middlewares) ⇒ FaradayFactory
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new Faraday Factory with additional middlewares
59 60 61 62 63 64 |
# File 'lib/ashikawa-core/faraday_factory.rb', line 59 def initialize(adapter, additional_request_middlewares, additional_response_middlewares, additional_middlewares) @adapter = adapter @request_middlewares = DEFAULT_REQUEST_MIDDLEWARES + additional_request_middlewares @response_middlewares = DEFAULT_RESPONSE_MIDDLEWARES + additional_response_middlewares @additional_middlewares = additional_middlewares end |
Instance Attribute Details
#debug_headers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Debug headers to be used by Faraday
50 51 52 |
# File 'lib/ashikawa-core/faraday_factory.rb', line 50 def debug_headers @debug_headers end |
Class Method Details
.create_connection(url, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a Faraday object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ashikawa-core/faraday_factory.rb', line 34 def self.create_connection(url, ) = DEFAULTS.merge() faraday = new( .fetch(:adapter), .fetch(:additional_request_middlewares), .fetch(:additional_response_middlewares), .fetch(:additional_middlewares) ) faraday.debug_headers = .fetch(:debug_headers) { false } faraday.logger = .fetch(:logger) if .key?(:logger) faraday.faraday_for(url) end |
Instance Method Details
#faraday_for(url) ⇒ Faraday
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create the Faraday for the given URL
79 80 81 82 83 84 85 86 |
# File 'lib/ashikawa-core/faraday_factory.rb', line 79 def faraday_for(url) Faraday.new(url) do |connection| @request_middlewares.each { |middleware| connection.request(*middleware) } @response_middlewares.each { |middleware| connection.response(*middleware) } @additional_middlewares.each { |middleware| connection.use(*middleware) } connection.adapter(*@adapter) end end |
#logger=(logger) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Logger to be used by Faraday
70 71 72 |
# File 'lib/ashikawa-core/faraday_factory.rb', line 70 def logger=(logger) @response_middlewares << [:minimal_logger, logger, debug_headers: debug_headers] end |