Class: Opsgenie::Schedule
- Inherits:
-
Object
- Object
- Opsgenie::Schedule
- Defined in:
- lib/opsgenie/schedule.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rotations ⇒ Object
readonly
Returns the value of attribute rotations.
Class Method Summary collapse
- .all ⇒ Object
- .find(id_or_name, type = "id") ⇒ Object
- .find_by_id(id) ⇒ Object
- .find_by_name(name) ⇒ Object
Instance Method Summary collapse
-
#initialize(attrs) ⇒ Schedule
constructor
A new instance of Schedule.
- #on_calls(datetime = nil) ⇒ Object
- #timeline(date: Date.today, interval: nil, interval_unit: nil) ⇒ Object
Constructor Details
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/opsgenie/schedule.rb', line 5 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/opsgenie/schedule.rb', line 5 def name @name end |
#rotations ⇒ Object (readonly)
Returns the value of attribute rotations.
5 6 7 |
# File 'lib/opsgenie/schedule.rb', line 5 def rotations @rotations end |
Class Method Details
.all ⇒ Object
8 9 10 11 |
# 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") ⇒ Object
21 22 23 24 |
# 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) ⇒ Object
17 18 19 |
# File 'lib/opsgenie/schedule.rb', line 17 def find_by_id(id) find(id) end |
.find_by_name(name) ⇒ Object
13 14 15 |
# File 'lib/opsgenie/schedule.rb', line 13 def find_by_name(name) find(name, "name") end |
Instance Method Details
#on_calls(datetime = nil) ⇒ Object
33 34 35 36 37 38 |
# 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) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 |