Sha256: a7baca02fe93f5edf6bb381ed307544f0999813b20a5dfbb7c7d534e35fa2fad

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

require 'pact/mock_service/request_handlers/base_administration_request_handler'
require 'pact/consumer_contract/consumer_contract_writer'

module Pact
  module MockService
    module RequestHandlers
      class PactPost < BaseAdministrationRequestHandler

        attr_accessor :consumer_contract, :verified_interactions, :default_options, :session

        def initialize name, logger, session
          super name, logger
          @verified_interactions = session.verified_interactions
          @default_options = {}
          @default_options.merge!(session.consumer_contract_details)
          @session = session
        end

        def request_path
          '/pact'
        end

        def request_method
          'POST'
        end

        def respond env
          body = env['rack.input'].read
          consumer_contract_details = body.size > 0 ? JSON.parse(body, symbolize_names: true) : {}
          consumer_contract_params = default_options.merge(consumer_contract_details.merge(interactions: verified_interactions))
          consumer_contract_writer = ConsumerContractWriter.new(consumer_contract_params, logger)
          session.record_pact_written
          json_response(consumer_contract_writer.write)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pact-mock_service-3.12.3 lib/pact/mock_service/request_handlers/pact_post.rb
pact-mock_service-3.12.2 lib/pact/mock_service/request_handlers/pact_post.rb
pact-mock_service-3.12.1 lib/pact/mock_service/request_handlers/pact_post.rb