class PactBroker::Client::Pacticipants2::Create

Attributes

action[R]
response_entity[R]

Private Instance Methods

do_call() click to toggle source
# File lib/pact_broker/client/pacticipants/create.rb, line 12
def do_call
  pacticipant_entity = index_resource._link('pb:pacticipant').expand('pacticipant' => params[:name]).get

  response_entity = if pacticipant_entity.does_not_exist?
    @action = "created"
    index_resource._link!('pb:pacticipants').post!(pacticipant_resource_params)
  elsif pacticipant_entity.success?
    @action = "updated"
    pacticipant_entity._link!('self').patch!(pacticipant_resource_params, { "Content-Type" => "application/json" })
  else
    pacticipant_entity.assert_success!
  end

  response_entity.assert_success!
  PactBroker::Client::CommandResult.new(true, result_message)
end
pacticipant_resource_params() click to toggle source
# File lib/pact_broker/client/pacticipants/create.rb, line 37
def pacticipant_resource_params
  {
    name: params[:name],
    repositoryUrl: params[:repository_url],
    displayName: params[:display_name],
    mainBranch: params[:main_branch]
  }.compact
end
result_message() click to toggle source
# File lib/pact_broker/client/pacticipants/create.rb, line 29
def result_message
  if json_output?
    response_entity.response.raw_body
  else
    green("Pacticipant \"#{params[:name]}\" #{action} in #{pact_broker_name}")
  end
end