Class: PactBroker::Client::Pacticipants2::Create

Inherits:
Object
  • Object
show all
Includes:
HalClientMethods
Defined in:
lib/pact_broker/client/pacticipants/create.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HalClientMethods

#create_http_client, #create_index_entry_point, #index_resource, #is_pactflow?, #pact_broker_name

Constructor Details

#initialize(params, pact_broker_base_url, pact_broker_client_options) ⇒ Create

Returns a new instance of Create.



17
18
19
20
21
# File 'lib/pact_broker/client/pacticipants/create.rb', line 17

def initialize(params, pact_broker_base_url, pact_broker_client_options)
  @params = params
  @index_entry_point = create_index_entry_point(pact_broker_base_url, pact_broker_client_options)
  @verbose = pact_broker_client_options[:verbose]
end

Class Method Details

.call(params, pact_broker_base_url, pact_broker_client_options) ⇒ Object



13
14
15
# File 'lib/pact_broker/client/pacticipants/create.rb', line 13

def self.call(params, pact_broker_base_url, pact_broker_client_options)
  new(params, pact_broker_base_url, pact_broker_client_options).call
end

Instance Method Details

#callObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pact_broker/client/pacticipants/create.rb', line 23

def call
  pacticipant_entity = index_entity._link('pb:pacticipant').expand('pacticipant' => params[:name]).get
  message = nil
  response_entity = if pacticipant_entity.does_not_exist?
    message = "Pacticipant \"#{params[:name]}\" created"
    index_entity._link!('pb:pacticipants').post(pacticipant_resource_params)
  else
    message = "Pacticipant \"#{params[:name]}\" updated"
    pacticipant_entity._link!('self').patch(pacticipant_resource_params)
  end

  response_entity.assert_success!
  PactBroker::Client::CommandResult.new(true, message)
rescue StandardError => e
  $stderr.puts("#{e.class} - #{e}\n#{e.backtrace.join("\n")}") if verbose
  PactBroker::Client::CommandResult.new(false, "#{e.class} - #{e}")
end