Sha256: 3c432397b32586df652d829ce181d72cfbe8c109e0ac7707d591887456521d0e

Contents?: true

Size: 923 Bytes

Versions: 6

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

module PriceHubble
  module Client
    module Request
      # 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.
      class DataSanitization < Faraday::Middleware
        # Serve the Faraday middleware API.
        #
        # @param env [Hash{Symbol => Mixed}] the request
        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
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pricehubble-0.4.2 lib/pricehubble/client/request/data_sanitization.rb
pricehubble-0.4.1 lib/pricehubble/client/request/data_sanitization.rb
pricehubble-0.4.0 lib/pricehubble/client/request/data_sanitization.rb
pricehubble-0.3.0 lib/pricehubble/client/request/data_sanitization.rb
pricehubble-0.2.0 lib/pricehubble/client/request/data_sanitization.rb
pricehubble-0.1.0 lib/pricehubble/client/request/data_sanitization.rb