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

Methods included from StringToSymbol

#string_keys_to_symbols

Methods included from UrlHelpers

#encode_param

Constructor Details

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

Instance Method Details

#get(options) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/pact_broker/client/pacts.rb', line 24

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



39
40
41
42
43
44
45
# File 'lib/pact_broker/client/pacts.rb', line 39

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



32
33
34
35
36
37
# File 'lib/pact_broker/client/pacts.rb', line 32

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

#publish(options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pact_broker/client/pacts.rb', line 9

def publish options
  consumer_version = options[:consumer_version]
  pact_string = options[:pact_json]
  consumer_contract = ::Pact::ConsumerContract.from_json pact_string
  url = save_consumer_contract_url consumer_contract, consumer_version
  response = self.class.put(url, body: pact_string, headers: default_put_headers)
  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