Class: PriceHubble::Client::Request::DataSanitization
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- PriceHubble::Client::Request::DataSanitization
- Defined in:
- lib/price_hubble/client/request/data_sanitization.rb
Overview
We like snake cased attributes here, but the API requires camel cased hash keys, so we take care of it in a generic way here. Furthermore, we perform a deep compaction of the given body hash, to strip nil
values and empty hashes from the request. There is no need to send null-data on a round trip.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Serve the Faraday middleware API.
Instance Method Details
#call(env) ⇒ Object
Serve the Faraday middleware API.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/price_hubble/client/request/data_sanitization.rb', line 15 def call(env) body = env[:body] # Perform the data compaction and the hash key transformation, # when the body is available and a hash env[:body] = body.deep_compact.deep_camelize_keys \ if body.is_a?(Hash) @app.call(env) end |