Class: PactBroker::Api::Resources::Pact
Instance Method Summary
collapse
#webhook_execution_configuration
#potential_duplicate_pacticipants?
Instance Method Details
#allowed_methods ⇒ Object
32
33
34
|
# File 'lib/pact_broker/api/resources/pact.rb', line 32
def allowed_methods
["GET", "PUT", "DELETE", "PATCH", "OPTIONS"]
end
|
#content_types_accepted ⇒ Object
28
29
30
|
# File 'lib/pact_broker/api/resources/pact.rb', line 28
def content_types_accepted
[["application/json", :from_json]]
end
|
#content_types_provided ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/pact_broker/api/resources/pact.rb', line 19
def content_types_provided
[
["application/hal+json", :to_json],
["application/json", :to_json],
["text/html", :to_html],
["application/vnd.pactbrokerextended.v1+json", :to_extended_json]
]
end
|
#delete_resource ⇒ Object
93
94
95
96
97
|
# File 'lib/pact_broker/api/resources/pact.rb', line 93
def delete_resource
pact_service.delete(pact_params)
set_post_deletion_response
true
end
|
#from_json ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/pact_broker/api/resources/pact.rb', line 64
def from_json
response_code = pact ? 200 : 201
if request.patch? && resource_exists?
@pact = pact_service.merge_pact(pact_params, webhook_options)
else
@pact = pact_service.create_or_update_pact(pact_params, webhook_options)
end
response.body = to_json
response_code
end
|
#is_conflict? ⇒ Boolean
36
37
38
39
40
41
|
# File 'lib/pact_broker/api/resources/pact.rb', line 36
def is_conflict?
merge_conflict = request.patch? && resource_exists? &&
Pacts::Merger.conflict?(pact.json_content, pact_params.json_content)
potential_duplicate_pacticipants?(pact_params.pacticipant_names) || merge_conflict
end
|
43
44
45
46
47
48
49
50
|
# File 'lib/pact_broker/api/resources/pact.rb', line 43
def malformed_request?
if request.patch? || request.put?
invalid_json? ||
contract_validation_errors?(Contracts::PutPactParamsContract.new(pact_params), pact_params)
else
false
end
end
|
#policy_resource ⇒ Object
60
61
62
|
# File 'lib/pact_broker/api/resources/pact.rb', line 60
def policy_resource
pact
end
|
#resource_exists? ⇒ Boolean
52
53
54
|
# File 'lib/pact_broker/api/resources/pact.rb', line 52
def resource_exists?
!!pact
end
|
#resource_object ⇒ Object
56
57
58
|
# File 'lib/pact_broker/api/resources/pact.rb', line 56
def resource_object
pact
end
|
#to_extended_json ⇒ Object
81
82
83
|
# File 'lib/pact_broker/api/resources/pact.rb', line 81
def to_extended_json
PactBroker::Api::Decorators::ExtendedPactDecorator.new(pact).to_json(user_options: decorator_context(metadata: identifier_from_path[:metadata]))
end
|
#to_html ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/pact_broker/api/resources/pact.rb', line 85
def to_html
PactBroker.configuration.html_pact_renderer.call(
pact, {
base_url: ui_base_url,
badge_url: badge_url_for_latest_pact(pact, ui_base_url)
})
end
|
#to_json ⇒ Object
77
78
79
|
# File 'lib/pact_broker/api/resources/pact.rb', line 77
def to_json
PactBroker::Api::Decorators::PactDecorator.new(pact).to_json(user_options: decorator_context(metadata: identifier_from_path[:metadata]))
end
|