Class: FaradayMiddleware::ParseDates

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/faraday_middleware/response/parse_dates.rb

Overview

Parse dates from response body

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

Constructor Details

#initialize(app, options = {}) ⇒ ParseDates

Returns a new instance of ParseDates.



12
13
14
15
# File 'lib/faraday_middleware/response/parse_dates.rb', line 12

def initialize(app, options = {})
  @regexp = options[:match] || ISO_DATE_FORMAT
  super(app)
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
# File 'lib/faraday_middleware/response/parse_dates.rb', line 17

def call(env)
  response = @app.call(env)
  parse_dates! response.env[:body]
  response
end