Class: Pact::MockService::RequestHandlers::PactPost

Inherits:
BaseAdministrationRequestHandler show all
Defined in:
lib/pact/mock_service/request_handlers/pact_post.rb

Constant Summary

Constants inherited from BaseRequestHandler

BaseRequestHandler::NOT_FOUND_RESPONSE

Constants included from Consumer::RackRequestHelper

Consumer::RackRequestHelper::REQUEST_KEYS

Instance Attribute Summary collapse

Attributes inherited from BaseAdministrationRequestHandler

#logger, #name

Instance Method Summary collapse

Methods inherited from BaseAdministrationRequestHandler

#has_mock_service_header?, #match?, #method_matches?, #path_matches?

Methods inherited from BaseRequestHandler

#call, #json_response, #match?, #text_response

Methods included from Consumer::RackRequestHelper

#params_hash, #request_as_hash_from

Constructor Details

#initialize(name, logger, session) ⇒ PactPost

Returns a new instance of PactPost.



11
12
13
14
15
16
17
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 11

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

Instance Attribute Details

#consumer_contractObject

Returns the value of attribute consumer_contract.



9
10
11
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 9

def consumer_contract
  @consumer_contract
end

#default_optionsObject

Returns the value of attribute default_options.



9
10
11
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 9

def default_options
  @default_options
end

#sessionObject

Returns the value of attribute session.



9
10
11
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 9

def session
  @session
end

#verified_interactionsObject

Returns the value of attribute verified_interactions.



9
10
11
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 9

def verified_interactions
  @verified_interactions
end

Instance Method Details

#request_methodObject



23
24
25
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 23

def request_method
  'POST'
end

#request_pathObject



19
20
21
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 19

def request_path
  '/pact'
end

#respond(env) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 27

def respond env
  body = env['rack.input'].string
  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