Class: Pact::MockService::RequestHandlers::InteractionPost

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

Constant Summary

Constants inherited from BaseRequestHandler

BaseRequestHandler::NOT_FOUND_RESPONSE

Constants included from Consumer::RackRequestHelper

Consumer::RackRequestHelper::REQUEST_KEYS

Instance Attribute Summary

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, pact_specification_version) ⇒ InteractionPost

Returns a new instance of InteractionPost.



9
10
11
12
13
# File 'lib/pact/mock_service/request_handlers/interaction_post.rb', line 9

def initialize name, logger, session, pact_specification_version
  super name, logger
  @session = session
  @pact_specification_version = pact_specification_version
end

Instance Method Details

#request_methodObject



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

def request_method
  'POST'
end

#request_pathObject



15
16
17
# File 'lib/pact/mock_service/request_handlers/interaction_post.rb', line 15

def request_path
  '/interactions'
end

#respond(env) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pact/mock_service/request_handlers/interaction_post.rb', line 23

def respond env
  request_body = env['rack.input'].string
  parsing_options = { pact_specification_version: pact_specification_version }
  interaction = Interaction.from_hash(JSON.load(request_body), parsing_options) # Load creates the Pact::XXX classes

  begin
    session.add_expected_interaction interaction
    text_response 'Registered interactions'
  rescue ::Pact::Error => e
    text_response e.message, 500
  end

end