Sha256: 17e92fe7e05bf3e399dea728efe802e75814a71ca2a1f5d4bc0a169172a952fc

Contents?: true

Size: 1.38 KB

Versions: 12

Compression:

Stored size: 1.38 KB

Contents

require 'pact_broker/api/resources/base_resource'
require 'pact_broker/configuration'
require 'pact_broker/api/decorators/extended_pact_decorator'

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

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

        def resource_exists?
          pact
        end

        def to_json
          response.headers['X-Pact-Consumer-Version'] = pact.consumer_version_number
          PactBroker::Api::Decorators::PactDecorator.new(pact).to_json(user_options: { base_url: base_url })
        end

        def to_extended_json
          PactBroker::Api::Decorators::ExtendedPactDecorator.new(pact).to_json(user_options: decorator_context(metadata: identifier_from_path[:metadata]))
        end

        def to_html
          PactBroker.configuration.html_pact_renderer.call(
            pact, {
              base_url: base_url,
              badge_url: "#{resource_url}/badge.svg"
          })
        end

        def pact
          @pact ||= pact_service.find_latest_pact(identifier_from_path)
        end

      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pact_broker-2.49.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.48.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.47.1 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.47.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.46.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.45.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.44.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.43.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.42.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.41.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.40.0 lib/pact_broker/api/resources/latest_pact.rb
pact_broker-2.39.0 lib/pact_broker/api/resources/latest_pact.rb