Class: PriceHubble::Client::Request::DataSanitization

Inherits:
Faraday::Middleware
  • Object
show all
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

Instance Method Details

#call(env) ⇒ Object

Serve the Faraday middleware API.

Parameters:

  • env (Hash{Symbol => Mixed})

    the request



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