Sha256: 562cb6bb0e1ec7111ee86f7fe0480b5a5a5f47ffe3181e986ed4a1ff08ef495d

Contents?: true

Size: 1.18 KB

Versions: 17

Compression:

Stored size: 1.18 KB

Contents

require 'pact_broker/api/resources/base_resource'
require 'pact_broker/api/decorators/matrix_decorator'

module PactBroker
  module Api
    module Resources
      class MatrixForConsumerAndProvider < BaseResource

        def content_types_provided
          [["application/hal+json", :to_json]]
        end

        def allowed_methods
          ["GET", "OPTIONS"]
        end

        def resource_exists?
          consumer && provider
        end

        def to_json
          lines = matrix_service.find_for_consumer_and_provider(identifier_from_path)
          PactBroker::Api::Decorators::MatrixDecorator.new(lines).to_json(user_options: { base_url: base_url })
        end

        def consumer
          @consumer ||= find_pacticipant(identifier_from_path[:consumer_name], "consumer")
        end

        def provider
          @provider ||= find_pacticipant(identifier_from_path[:provider_name], "provider")
        end

        def find_pacticipant name, role
          pacticipant_service.find_pacticipant_by_name(name).tap do | pacticipant |
            set_json_error_message("No #{role} with name '#{name}' found") if pacticipant.nil?
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
pact_broker-2.31.0 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.30.0 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.29.0 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.27.6 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.27.5 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.27.4 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.27.3 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.27.2 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.27.0 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.26.1 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.26.0 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.25.0 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.24.0 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.23.4 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.23.3 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.23.2 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb
pact_broker-2.23.1 lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb