Class: PriceHubble::Client::Response::DataSanitization
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- PriceHubble::Client::Response::DataSanitization
- Defined in:
- lib/price_hubble/client/response/data_sanitization.rb
Overview
We like snake cased attributes here, but the API sends camel cased hash keys on responses, so we take care of it in a generic way here.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Serve the Faraday middleware API.
Instance Method Details
#call(env) ⇒ Object
Serve the Faraday middleware API.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/price_hubble/client/response/data_sanitization.rb', line 12 def call(env) @app.call(env).on_complete do |res| body = res[:body] # Skip string bodies, they are unparsed or contain binary data next if body.is_a? String # Skip non-hash bodies, we cannot handle them here next unless body.is_a? Hash # Perform the key transformation res[:body] = body.deep_underscore_keys end end |