class Opsgenie::Rotation

Attributes

id[R]
name[R]
participants[R]
schedule[R]
start_date[R]
time_restriction[R]
type[R]

Public Class Methods

new(schedule, attrs) click to toggle source
# File lib/opsgenie/rotation.rb, line 11
def initialize(schedule, attrs)
  @schedule = schedule
  @id = attrs["id"]
  @name = attrs["name"]
  @time_restriction = attrs["timeRestriction"]
  @start_date = DateTime.parse(attrs["startDate"])
  @type = attrs["type"]
  @participants = attrs["participants"]
end

Public Instance Methods

on_call_for_date(date) click to toggle source
# File lib/opsgenie/rotation.rb, line 21
def on_call_for_date(date)
  day_of_the_week = date.strftime("%A").downcase
  restriction = time_restriction["restrictions"].find { |r|
    r["startDay"] == day_of_the_week
  }

  return unless restriction

  time = Time.new(
    date.year,
    date.month,
    date.day,
    restriction["startHour"],
    restriction["startMin"]
  )

  on_calls = schedule.on_calls((time + 60).to_datetime)
  on_calls.select { |user| participant_usernames.include?(user.username) }
end
timeline(date: Date.today, interval: nil, interval_unit: nil) click to toggle source
# File lib/opsgenie/rotation.rb, line 41
def timeline(date: Date.today, interval: nil, interval_unit: nil)
  rotations = schedule.timeline(
    date: date,
    interval: interval,
    interval_unit: interval_unit
  )

  rotations.find { |r| r.name == name }
end

Private Instance Methods

participant_usernames() click to toggle source
# File lib/opsgenie/rotation.rb, line 53
def participant_usernames
  participants.map { |p| p["username"] }
end