Class: Upcheck::Adapters::Heroku

Inherits:
Object
  • Object
show all
Defined in:
lib/upcheck/adapters/heroku.rb

Constant Summary collapse

URL =
"https://status.heroku.com/api/v4/current-status.json"
COLOR_TO_STATUS =
{
  "green" => "none",
  "yellow" => "minor",
  "red" => "major"
}.freeze
COLOR_SEVERITY =
{"green" => 0, "yellow" => 1, "red" => 2}.freeze
STATUS_TO_DESCRIPTION =
{
  "none" => "All systems operational",
  "minor" => "Some systems experiencing degradation",
  "major" => "Major service disruption"
}.freeze
COLOR_TO_COMPONENT_STATUS =
{
  "green" => "operational",
  "yellow" => "degraded_performance",
  "red" => "major_outage"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(http_client: HTTPClient.new) ⇒ Heroku

Returns a new instance of Heroku.



28
29
30
# File 'lib/upcheck/adapters/heroku.rb', line 28

def initialize(http_client: HTTPClient.new)
  @http_client = http_client
end

Instance Method Details

#componentsObject



39
40
41
42
43
44
45
46
# File 'lib/upcheck/adapters/heroku.rb', line 39

def components
  @components ||= payload.fetch("status").map do |entry|
    Component.new(
      "name" => entry["system"],
      "status" => COLOR_TO_COMPONENT_STATUS.fetch(entry["status"])
    )
  end
end

#descriptionObject



37
# File 'lib/upcheck/adapters/heroku.rb', line 37

def description = STATUS_TO_DESCRIPTION.fetch(status)

#incidentsObject



48
49
50
# File 'lib/upcheck/adapters/heroku.rb', line 48

def incidents
  @incidents ||= build_incidents(payload.fetch("incidents"))
end

#scheduled_maintenancesObject



52
53
54
# File 'lib/upcheck/adapters/heroku.rb', line 52

def scheduled_maintenances
  @scheduled_maintenances ||= build_incidents(payload.fetch("scheduled"))
end

#statusObject



32
33
34
35
# File 'lib/upcheck/adapters/heroku.rb', line 32

def status
  worst_color = payload.fetch("status").map { |s| s["status"] }.max_by { |c| COLOR_SEVERITY.fetch(c, 0) }
  COLOR_TO_STATUS.fetch(worst_color)
end