Class: PactBroker::Client::Pacts

Inherits:
BaseClient show all
Defined in:
lib/pact_broker/client/pacts.rb

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?

Methods included from StringToSymbol

#string_keys_to_symbols

Methods included from UrlHelpers

#encode_param, #encode_query_param

Constructor Details

This class inherits a constructor from PactBroker::Client::BaseClient

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: default_get_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: default_get_headers)
  handle_response(response) do
    response.body
  end
end

#list_latestObject



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: default_get_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: default_patch_headers)
  else
    response = self.class.put(url, body: pact_string, headers: default_put_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

Returns:

  • (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