Class: Pact::MockService::RequestHandlers::InteractionsPut

Inherits:
BaseAdministrationRequestHandler show all
Defined in:
lib/pact/mock_service/request_handlers/interactions_put.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) ⇒ InteractionsPut

Returns a new instance of InteractionsPut.



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

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



21
22
23
# File 'lib/pact/mock_service/request_handlers/interactions_put.rb', line 21

def request_method
  'PUT'
end

#request_pathObject



17
18
19
# File 'lib/pact/mock_service/request_handlers/interactions_put.rb', line 17

def request_path
  '/interactions'
end

#respond(env) ⇒ Object



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

def respond env
  request_body = JSON.load(env['rack.input'].string)
  parsing_options = { pact_specification_version: pact_specification_version }
  interactions = request_body['interactions'].collect { | hash | Interaction.from_hash(hash, parsing_options) }
  begin
    session.set_expected_interactions interactions
    text_response('Registered interactions')
  rescue Pact::Error => e
    text_response(e.message, 500)
  end
end