Sha256: 31fa9055d64e92f533c31ddb26847a34c83f4e3fd577cce09df52ac1e8ea1c0d

Contents?: true

Size: 867 Bytes

Versions: 15

Compression:

Stored size: 867 Bytes

Contents

# frozen_string_literal: true

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pricehubble-1.3.0 lib/price_hubble/client/response/data_sanitization.rb
pricehubble-1.2.5 lib/price_hubble/client/response/data_sanitization.rb
pricehubble-1.2.4 lib/price_hubble/client/response/data_sanitization.rb
pricehubble-1.2.3 lib/price_hubble/client/response/data_sanitization.rb
pricehubble-1.2.2 lib/price_hubble/client/response/data_sanitization.rb
pricehubble-1.2.1 lib/price_hubble/client/response/data_sanitization.rb
pricehubble-1.2.0 lib/price_hubble/client/response/data_sanitization.rb
pricehubble-1.1.0 lib/pricehubble/client/response/data_sanitization.rb
pricehubble-1.0.0 lib/pricehubble/client/response/data_sanitization.rb
pricehubble-0.4.2 lib/pricehubble/client/response/data_sanitization.rb
pricehubble-0.4.1 lib/pricehubble/client/response/data_sanitization.rb
pricehubble-0.4.0 lib/pricehubble/client/response/data_sanitization.rb
pricehubble-0.3.0 lib/pricehubble/client/response/data_sanitization.rb
pricehubble-0.2.0 lib/pricehubble/client/response/data_sanitization.rb
pricehubble-0.1.0 lib/pricehubble/client/response/data_sanitization.rb