Module: PactBroker::Api::Resources::BadgeMethods

Included in:
Badge, CanIDeployPacticipantVersionByBranchToEnvironmentBadge, CanIDeployPacticipantVersionByTagToTagBadge, CanIMergeBadge
Defined in:
lib/pact_broker/api/resources/badge_methods.rb

Instance Method Summary collapse

Instance Method Details

#allowed_methodsObject



5
6
7
# File 'lib/pact_broker/api/resources/badge_methods.rb', line 5

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

#badge_urlObject

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/pact_broker/api/resources/badge_methods.rb', line 45

def badge_url
  raise NotImplementedError
end

#content_types_providedObject



9
10
11
# File 'lib/pact_broker/api/resources/badge_methods.rb', line 9

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

#forbidden?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/pact_broker/api/resources/badge_methods.rb', line 22

def forbidden?
  false
end

#is_authorized?(authorization_header) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/pact_broker/api/resources/badge_methods.rb', line 26

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

#moved_temporarily?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
# File 'lib/pact_broker/api/resources/badge_methods.rb', line 34

def moved_temporarily?
  set_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

#policy_nameObject



30
31
32
# File 'lib/pact_broker/api/resources/badge_methods.rb', line 30

def policy_name
  :'badges::badge'
end

#previously_existed?Boolean

Only called if resource_exists? returns false

Returns:

  • (Boolean)


18
19
20
# File 'lib/pact_broker/api/resources/badge_methods.rb', line 18

def previously_existed?
  true
end

#resource_exists?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/pact_broker/api/resources/badge_methods.rb', line 13

def resource_exists?
  false
end

#set_cache_control(cache_control_str) ⇒ Object



49
50
51
# File 'lib/pact_broker/api/resources/badge_methods.rb', line 49

def set_cache_control(cache_control_str)
  response.headers["Cache-Control"] = cache_control_str
end