Sha256: 4da72c2b764f003db542efdf661946373c6185b8c2428b49215cd2efef3ee590

Contents?: true

Size: 450 Bytes

Versions: 5

Compression:

Stored size: 450 Bytes

Contents

require "rack/utils"

# Adds preview param to all requests to Flex API.
module FlexCommerceApi
  module JsonApiClientExtension
    class PreviewedRequestMiddleware < ::Faraday::Middleware
      def call(env)
        env.url.tap do |url|
          parsed_query = Rack::Utils.parse_nested_query url.query
          parsed_query[:preview] = true
          url.query = parsed_query.to_param
        end
        @app.call(env)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flex_commerce_api-0.8.3 lib/flex_commerce_api/json_api_client_extension/previewed_request_middleware.rb
flex_commerce_api-0.8.2 lib/flex_commerce_api/json_api_client_extension/previewed_request_middleware.rb
flex_commerce_api-0.8.1 lib/flex_commerce_api/json_api_client_extension/previewed_request_middleware.rb
flex_commerce_api-0.7 lib/flex_commerce_api/json_api_client_extension/previewed_request_middleware.rb
flex_commerce_api-0.6.57 lib/flex_commerce_api/json_api_client_extension/previewed_request_middleware.rb