Sha256: 64397ea9dd6c83b5f4ab99827e65079131302037ba76994192fe113e421f2348

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require 'pact_broker/client/base_command'

module PactBroker
  module Client
    module Pacticipants2
      class Create < PactBroker::Client::BaseCommand

        private

        attr_reader :action, :response_entity

        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)
          else
            pacticipant_entity.assert_success!
          end

          response_entity.assert_success!
          PactBroker::Client::CommandResult.new(true, result_message)
        end

        def result_message
          if json_output?
            response_entity.response.raw_body
          else
            green(message = "Pacticipant \"#{params[:name]}\" #{action}")
          end
        end

        def pacticipant_resource_params
          {
            name: params[:name],
            repositoryUrl: params[:repository_url],
            displayName: params[:display_name]
          }.compact
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pact_broker-client-1.43.0 lib/pact_broker/client/pacticipants/create.rb
pact_broker-client-1.42.0 lib/pact_broker/client/pacticipants/create.rb