Class: OctaSpace::Transport::FaradayTransport
- Defined in:
- lib/octaspace/transport/faraday_transport.rb
Overview
Standard HTTP transport built on Faraday
Features:
-
Automatic JSON request/response encoding
-
Configurable retry with exponential backoff + jitter
-
URL rotation / failover across multiple base_urls
-
on_request / on_response hooks
-
Typed exception hierarchy mapped from HTTP status codes
Direct Known Subclasses
Constant Summary collapse
- RETRY_STATUSES =
[408, 429, 500, 502, 503, 504].freeze
- RETRY_METHODS =
%i[get head options put delete].freeze
Instance Method Summary collapse
- #delete(path, params: {}, headers: {}) ⇒ Object
- #get(path, params: {}, headers: {}) ⇒ Object
-
#initialize(config) ⇒ FaradayTransport
constructor
A new instance of FaradayTransport.
- #patch(path, body: nil, headers: {}) ⇒ Object
- #post(path, body: nil, headers: {}) ⇒ Object
- #put(path, body: nil, headers: {}) ⇒ Object
Constructor Details
#initialize(config) ⇒ FaradayTransport
Returns a new instance of FaradayTransport.
26 27 28 29 30 31 |
# File 'lib/octaspace/transport/faraday_transport.rb', line 26 def initialize(config) @config = config @rotator = (config.urls.size > 1) ? Middleware::UrlRotator.new(config.urls) : nil # Single URL: build one connection upfront for reuse @connection = build_connection(config.urls.first) unless @rotator end |
Instance Method Details
#delete(path, params: {}, headers: {}) ⇒ Object
49 50 51 |
# File 'lib/octaspace/transport/faraday_transport.rb', line 49 def delete(path, params: {}, headers: {}) request(:delete, path, params: params, headers: headers) end |
#get(path, params: {}, headers: {}) ⇒ Object
33 34 35 |
# File 'lib/octaspace/transport/faraday_transport.rb', line 33 def get(path, params: {}, headers: {}) request(:get, path, params: params, headers: headers) end |
#patch(path, body: nil, headers: {}) ⇒ Object
45 46 47 |
# File 'lib/octaspace/transport/faraday_transport.rb', line 45 def patch(path, body: nil, headers: {}) request(:patch, path, body: body, headers: headers) end |
#post(path, body: nil, headers: {}) ⇒ Object
37 38 39 |
# File 'lib/octaspace/transport/faraday_transport.rb', line 37 def post(path, body: nil, headers: {}) request(:post, path, body: body, headers: headers) end |
#put(path, body: nil, headers: {}) ⇒ Object
41 42 43 |
# File 'lib/octaspace/transport/faraday_transport.rb', line 41 def put(path, body: nil, headers: {}) request(:put, path, body: body, headers: headers) end |