Sha256: acc4a5d28b9fb812b24ac303a758b8422761af2935a618d53e19f3bbc1855f5c

Contents?: true

Size: 1.42 KB

Versions: 14

Compression:

Stored size: 1.42 KB

Contents

require 'pact_broker/api/resources/base_resource'
require 'pact_broker/verifications/verification_status'
require 'pact_broker/configuration'

module PactBroker
  module Api
    module Resources

      class Badge < BaseResource

        def allowed_methods
          ['GET']
        end

        def content_types_provided
          [['image/svg+xml', :to_svg]]
        end

        def resource_exists?
          true
        end

        def is_authorized?(authorization_header)
          super || PactBroker.configuration.enable_public_badge_access
        end

        def forbidden?
          false
        end

        private

        def to_svg
          response.headers['Cache-Control'] = 'no-cache'
          badge_service.pact_verification_badge pact, label, initials, verification_status
        end

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

        def latest_verification
          return nil unless pact
          @verification ||= verification_service.find_latest_verification_for(pact.consumer, pact.provider, identifier_from_path[:tag])
        end

        def verification_status
          @verification_status ||= PactBroker::Verifications::Status.new(pact, latest_verification).to_sym
        end

        def label
          request.query['label']
        end

        def initials
          request.query['initials'] == 'true'
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
pact_broker-2.13.1 lib/pact_broker/api/resources/badge.rb
pact_broker-2.13.0 lib/pact_broker/api/resources/badge.rb
pact_broker-2.12.0 lib/pact_broker/api/resources/badge.rb
pact_broker-2.11.0 lib/pact_broker/api/resources/badge.rb
pact_broker-2.10.0 lib/pact_broker/api/resources/badge.rb
pact_broker-2.9.0 lib/pact_broker/api/resources/badge.rb
pact_broker-2.9.0.beta.5 lib/pact_broker/api/resources/badge.rb
pact_broker-2.8.0.beta.5 lib/pact_broker/api/resources/badge.rb
pact_broker-2.8.0.beta.4 lib/pact_broker/api/resources/badge.rb
pact_broker-2.7.0.beta.3 lib/pact_broker/api/resources/badge.rb
pact_broker-2.7.0.beta.2 lib/pact_broker/api/resources/badge.rb
pact_broker-2.7.0.beta.1 lib/pact_broker/api/resources/badge.rb
pact_broker-2.6.0 lib/pact_broker/api/resources/badge.rb
pact_broker-2.5.1 lib/pact_broker/api/resources/badge.rb