Class: ErpIntegration::Middleware::Formatter
- Inherits:
-
Faraday::Logging::Formatter
- Object
- Faraday::Logging::Formatter
- ErpIntegration::Middleware::Formatter
- Defined in:
- lib/erp_integration/middleware/formatter.rb
Overview
The Formatter class is a custom formatter for the Faraday logger. It logs the rate limiter headers in the response.
Instance Method Summary collapse
- #limit(headers) ⇒ Object
-
#rate_limiter_headers(headers) ⇒ Object
Formats the rate limiter headers.
- #remaining(headers) ⇒ Object
- #reset_at(headers) ⇒ Object
- #response(env) ⇒ Object
Instance Method Details
#limit(headers) ⇒ Object
25 26 27 |
# File 'lib/erp_integration/middleware/formatter.rb', line 25 def limit(headers) "Rate Limit #{headers['x-ratelimit-limit']}" end |
#rate_limiter_headers(headers) ⇒ Object
Formats the rate limiter headers.
15 16 17 18 19 20 21 22 23 |
# File 'lib/erp_integration/middleware/formatter.rb', line 15 def rate_limiter_headers(headers) proc do [ limit(headers), remaining(headers), reset_at(headers) ].join(', ') end end |
#remaining(headers) ⇒ Object
29 30 31 |
# File 'lib/erp_integration/middleware/formatter.rb', line 29 def remaining(headers) "Remaining Limit #{headers['x-ratelimit-remaining']}" end |
#reset_at(headers) ⇒ Object
33 34 35 |
# File 'lib/erp_integration/middleware/formatter.rb', line 33 def reset_at(headers) "Rate Limit Reset at #{Time.at(headers['x-ratelimit-reset'].to_i).utc}" end |
#response(env) ⇒ Object
8 9 10 11 |
# File 'lib/erp_integration/middleware/formatter.rb', line 8 def response(env) super public_send(log_level, 'response', &rate_limiter_headers(env.response_headers)) end |