Class: PactBroker::Client::Pacts
Instance Attribute Summary
Attributes inherited from BaseClient
#base_url, #client_options
Instance Method Summary
collapse
Methods inherited from BaseClient
#default_get_headers, #default_patch_headers, #default_put_headers, #default_request_headers, #handle_response, #initialize, #patch, #put, #url_for_relation, #verbose?
#string_keys_to_symbols
Methods included from UrlHelpers
#encode_param, #encode_query_param
Instance Method Details
#get(options) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/pact_broker/client/pacts.rb', line 33
def get options
url = get_consumer_contract_url(options)
response = self.class.get(url, headers: )
handle_response(response) do
response.body
end
end
|
#latest(options) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/pact_broker/client/pacts.rb', line 56
def latest options
url = get_latest_consumer_contract_url(options)
response = self.class.get(url, headers: )
handle_response(response) do
response.body
end
end
|
#list_latest ⇒ Object
41
42
43
44
45
46
|
# File 'lib/pact_broker/client/pacts.rb', line 41
def list_latest
response = self.class.get("/pacts/latest", headers: )
handle_response(response) do
map_pact_list_to_hash JSON.parse(response.body)["pacts"]
end
end
|
#list_latest_for_provider(options) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/pact_broker/client/pacts.rb', line 48
def list_latest_for_provider options
url = get_latest_provider_contracts(options)
response = self.class.get(url, headers: {})
handle_response(response) do
map_latest_provider_pacts_to_hash(pact_links(response))
end
end
|
#publish(options) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/pact_broker/client/pacts.rb', line 8
def publish options
consumer_version = options[:consumer_version]
pact_hash = options[:pact_hash]
pact_string = pact_hash.to_json
url = save_consumer_contract_url pact_hash, consumer_version
if @client_options[:write] == :merge
response = self.class.patch(url, body: pact_string, headers: )
else
response = self.class.put(url, body: pact_string, headers: )
end
handle_response(response) do
latest_link = find_latest_link JSON.parse(response.body)
if latest_link.nil?
"Please upgrade to the latest version of the pact broker to see the URL of the latest pact!"
end
latest_link
end
end
|
#version_published?(args) ⇒ Boolean
29
30
31
|
# File 'lib/pact_broker/client/pacts.rb', line 29
def version_published?(args)
!get(consumer: args.fetch(:consumer), provider: args.fetch(:provider), consumer_version: args.fetch(:consumer_version)).nil?
end
|