Class: PactBroker::Api::Resources::Pact

Inherits:
BaseResource
  • Object
show all
Includes:
PacticipantResourceMethods
Defined in:
lib/pact_broker/api/resources/pact.rb

Constant Summary

Constants included from Logging

Logging::LOG_DIR, Logging::LOG_FILE_NAME

Instance Method Summary collapse

Methods included from PacticipantResourceMethods

#potential_duplicate_pacticipants?

Methods inherited from BaseResource

#base_url, #consumer_name, #decorator_context, #handle_exception, #identifier_from_path, #invalid_json?, #params, #provider_name, #request_body, #resource_url, #set_json_error_message, #set_json_validation_error_messages, #validation_errors?

Methods included from Logging

included, #logger, #logger=

Methods included from PactBrokerUrls

#hal_browser_url, #latest_pact_url, #latest_pacts_url, #latest_version_url, #pact_url, #pact_versions_url, #pacticipant_url, #pacticipants_url, #tag_url, #tags_url, #url_encode, #version_url, #versions_url, #webhook_execution_url, #webhook_url, #webhooks_for_pact_url, #webhooks_url

Methods included from Services

#group_service, #pact_service, #pacticipant_service, #tag_service, #webhook_service

Instance Method Details

#allowed_methodsObject



24
25
26
# File 'lib/pact_broker/api/resources/pact.rb', line 24

def allowed_methods
  ["GET", "PUT"]
end

#content_types_acceptedObject



20
21
22
# File 'lib/pact_broker/api/resources/pact.rb', line 20

def content_types_accepted
  [["application/json", :from_json]]
end

#content_types_providedObject



16
17
18
# File 'lib/pact_broker/api/resources/pact.rb', line 16

def content_types_provided
  [["application/json", :to_json]]
end

#from_jsonObject



41
42
43
44
45
46
# File 'lib/pact_broker/api/resources/pact.rb', line 41

def from_json
  response_code = pact ? 200 : 201
  @pact = pact_service.create_or_update_pact(identifier_from_path.merge(:json_content => request_body))
  response.body = to_json
  response_code
end

#malformed_request?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
# File 'lib/pact_broker/api/resources/pact.rb', line 28

def malformed_request?
  if request.put?
    return invalid_json? ||
      potential_duplicate_pacticipants?([identifier_from_path[:consumer_name], identifier_from_path[:provider_name]])
  else
    false
  end
end

#pactObject



52
53
54
# File 'lib/pact_broker/api/resources/pact.rb', line 52

def pact
  @pact ||= pact_service.find_pact(identifier_from_path)
end

#resource_exists?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/pact_broker/api/resources/pact.rb', line 37

def resource_exists?
  pact
end

#to_jsonObject



48
49
50
# File 'lib/pact_broker/api/resources/pact.rb', line 48

def to_json
  PactBroker::Api::Decorators::PactDecorator.new(pact).to_json(base_url: base_url)
end