Sha256: fb111e738eff2eb05d2fd85a3410f8e15b64194b06b0b21ac903e4d84be8b273

Contents?: true

Size: 1.72 KB

Versions: 43

Compression:

Stored size: 1.72 KB

Contents

require 'pact_broker/client/pact_broker_client'
require 'pact_broker/client/versions/formatter'

module PactBroker
  module Client
    class Versions
      class Describe

        class Result
          attr_reader :success, :message

          def initialize success, message = nil
            @success = success
            @message = message
          end
        end

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

        def initialize params, options, pact_broker_base_url, pact_broker_client_options
          @params = params
          @options = options
          @pact_broker_base_url = pact_broker_base_url
          @pact_broker_client_options = pact_broker_client_options
        end

        def call
          version_hash = if params[:version]
            versions_client.find params
          else
            pact_broker_client.pacticipants.versions.latest(params)
          end
          if version_hash
            Result.new(true, format_version(version_hash))
          else
            Result.new(false, "Pacticipant version not found")
          end
        end

        private

        def format_version(version_hash)
          Formatter.call(version_hash, options[:output])
        end

        attr_reader :params, :options, :pact_broker_base_url, :pact_broker_client_options

        def versions_client
          pact_broker_client.pacticipants.versions
        end

        def pact_broker_client
          @pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
pact_broker-client-1.28.1 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.28.0 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.28 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.27 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.26 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.25 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.24 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.23 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.22 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.21 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.20 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.19 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.14 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.13 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.12 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.11 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.10 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.9 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.8 lib/pact_broker/client/versions/describe.rb
pact_broker-client-1.27.4 lib/pact_broker/client/versions/describe.rb