Sha256: 83c57540a964a5110e6992f1c9f40731d4c35ee499c1a29ee552b2136c66c1b7

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

require 'pact_broker/api/resources/base_resource'
require 'pact_broker/configuration'
require 'pact_broker/domain/verification'
require 'pact_broker/api/contracts/verification_contract'
require 'pact_broker/api/decorators/verification_decorator'
require 'pact_broker/api/decorators/extended_verification_decorator'

module PactBroker
  module Api
    module Resources
      class Verification < BaseResource
        def content_types_provided
          [
            ["application/hal+json", :to_json],
            ["application/json", :to_json],
            ["application/vnd.pactbrokerextended.v1+json", :to_extended_json]
          ]
        end

        # Remember to update latest_verification_id_for_pact_version_and_provider_version
        # if/when DELETE is implemented
        def allowed_methods
          ["GET", "OPTIONS"]
        end

        def resource_exists?
          if identifier_from_path[:verification_number] == "all"
            set_json_error_message("To see all the verifications for a pact, use the Matrix page")
            false
          else
            !!verification
          end
        end

        def to_json
          decorator_for(verification).to_json(user_options: { base_url: base_url })
        end

        def to_extended_json
          extended_decorator_for(verification).to_json(user_options: { base_url: base_url })
        end

        private

        def verification
          @verification ||= verification_service.find(identifier_from_path)
        end

        def decorator_for model
          PactBroker::Api::Decorators::VerificationDecorator.new(model)
        end

        def extended_decorator_for model
          PactBroker::Api::Decorators::ExtendedVerificationDecorator.new(model)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pact_broker-2.47.1 lib/pact_broker/api/resources/verification.rb
pact_broker-2.47.0 lib/pact_broker/api/resources/verification.rb