Sha256: af848c3590a3479f297ca5e6588b7370454e73ab2695ddda23f3d534975ab1bf

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

module PactBroker
  module Api
    module Resources
      module BadgeMethods
        def allowed_methods
          ["GET", "OPTIONS"]
        end

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

        def resource_exists?
          false
        end

        # Only called if resource_exists? returns false
        def previously_existed?
          true
        end

        def forbidden?
          false
        end

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

        def policy_name
          :'badges::badge'
        end

        def moved_temporarily?
          response.headers["Cache-Control"] = "no-cache"
          begin
            badge_url
          rescue StandardError => e
            # Want to render a badge, even if there's an error
            error_reference = log_and_report_error(e)
            badge_service.error_badge_url("error", "reference: #{error_reference}")
          end
        end

        def badge_url
          raise NotImplementedError
        end

        private

        def label
          lab = request.query["label"]
          lab && !lab.empty? ? lab : nil
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pact_broker-2.111.0 lib/pact_broker/api/resources/badge_methods.rb
pact_broker-2.109.1 lib/pact_broker/api/resources/badge_methods.rb
pact_broker-2.109.0 lib/pact_broker/api/resources/badge_methods.rb
pact_broker-2.108.0 lib/pact_broker/api/resources/badge_methods.rb