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



34
35
36
37
38
39
40
# File 'lib/pact_broker/client/pacts.rb', line 34

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



49
50
51
52
53
54
55
# File 'lib/pact_broker/client/pacts.rb', line 49

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



42
43
44
45
46
47
# File 'lib/pact_broker/client/pacts.rb', line 42

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
23
24
25
26
27
28
# 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

  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)


30
31
32
# File 'lib/pact_broker/client/pacts.rb', line 30

def version_published?(args)
  !get(consumer: args.fetch(:consumer), provider: args.fetch(:provider), consumer_version: args.fetch(:consumer_version)).nil?
end