class Opsgenie::Schedule
Attributes
id[R]
name[R]
rotations[R]
Public Class Methods
all()
click to toggle source
# File lib/opsgenie/schedule.rb, line 8 def all body = Opsgenie::Client.get("schedules?expand=rotation") body["data"].map { |s| new(s) } end
find(id_or_name, type = "id")
click to toggle source
# File lib/opsgenie/schedule.rb, line 21 def find(id_or_name, type = "id") body = Opsgenie::Client.get("schedules/#{id_or_name}?identifierType=#{type}") new(body["data"]) unless body["data"].nil? end
find_by_id(id)
click to toggle source
# File lib/opsgenie/schedule.rb, line 17 def find_by_id(id) find(id) end
find_by_name(name)
click to toggle source
# File lib/opsgenie/schedule.rb, line 13 def find_by_name(name) find(name, "name") end
new(attrs)
click to toggle source
# File lib/opsgenie/schedule.rb, line 27 def initialize(attrs) @id = attrs["id"] @name = attrs["name"] @rotations = attrs["rotations"].map { |r| Rotation.new(self, r) } end
Public Instance Methods
on_calls(datetime = nil)
click to toggle source
# File lib/opsgenie/schedule.rb, line 33 def on_calls(datetime = nil) endpoint = "schedules/#{id}/on-calls" endpoint += "?date=#{escape_datetime(datetime)}" unless datetime.nil? body = Opsgenie::Client.get(endpoint) get_participants(body).map { |u| User.find_by_username(u["name"]) } end
timeline(date: Date.today, interval: nil, interval_unit: nil)
click to toggle source
# File lib/opsgenie/schedule.rb, line 40 def timeline(date: Date.today, interval: nil, interval_unit: nil) check_interval_unit(interval_unit) if interval_unit datetime = date.to_datetime endpoint = "schedules/#{id}/timeline?date=#{escape_datetime(datetime)}" endpoint += "&interval=#{interval}" if interval endpoint += "&intervalUnit=#{interval_unit}" if interval_unit body = Opsgenie::Client.get(endpoint) body.dig("data", "finalTimeline", "rotations").map do |rotation| TimelineRotation.new( id: rotation["id"], name: rotation["name"], periods: (rotation["periods"] || []) ) end end
Private Instance Methods
check_interval_unit(value)
click to toggle source
# File lib/opsgenie/schedule.rb, line 69 def check_interval_unit(value) return if valid_intervals.include?(value) raise ArgumentError, "`interval_unit` must be one of `#{valid_intervals}``" end
escape_datetime(datetime)
click to toggle source
# File lib/opsgenie/schedule.rb, line 65 def escape_datetime(datetime) CGI.escape(datetime.to_s) end
get_participants(body)
click to toggle source
# File lib/opsgenie/schedule.rb, line 59 def get_participants(body) body["data"]["onCallParticipants"].select do |p| p["type"] == "user" end end
valid_intervals()
click to toggle source
# File lib/opsgenie/schedule.rb, line 75 def valid_intervals %i[days weeks months] end