Class: Faraday::ParseDates::Middleware
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::ParseDates::Middleware
- Defined in:
- lib/faraday/parse_dates/middleware.rb
Overview
This class provides the main implementation for your middleware. Your middleware can implement any of the following methods:
-
on_request - called when the request is being prepared
-
on_complete - called when the response is being processed
Optionally, you can also override the following methods from Faraday::Middleware
-
initialize(app, options = {}) - the initializer method
-
call(env) - the main middleware invocation method. This already calls on_request and on_complete, so you normally don’t need to override it. You may need to in case you need to “wrap” the request or need more control (see “retry” middleware: github.com/lostisland/faraday/blob/main/lib/faraday/request/retry.rb#L142). IMPORTANT: Remember to call ‘@app.call(env)` or `super` to not interrupt the middleware chain!
Constant Summary collapse
- ISO_DATE_FORMAT =
/\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|((\+|-)\d{2}:?\d{2}))\Z/xm.freeze
Instance Method Summary collapse
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
-
#on_complete(env) ⇒ Object
This method will be called when the response is being processed.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
22 23 24 25 |
# File 'lib/faraday/parse_dates/middleware.rb', line 22 def initialize(app, = {}) @regexp = [:match] || ISO_DATE_FORMAT super(app) end |
Instance Method Details
#on_complete(env) ⇒ Object
This method will be called when the response is being processed. You can alter it as you like, accessing things like response_body, response_headers, and more. Refer to Faraday::Env for a list of accessible fields: github.com/lostisland/faraday/blob/main/lib/faraday/options/env.rb
33 34 35 |
# File 'lib/faraday/parse_dates/middleware.rb', line 33 def on_complete(env) parse_dates! env[:body] end |