Class: Readiness::Pagerduty::Schedules
- Defined in:
- lib/support_readiness/pagerduty/schedules.rb
Overview
Create a schedule
List audit records for a schedule
List users on call
Preview a schedule
Defines the class Schedules within the module Readiness::Pagerduty.
Instance Attribute Summary collapse
- #description ⇒ Object
- #escalation_policies ⇒ Object
- #final_schedule ⇒ Object
- #html_url ⇒ Object
- #id ⇒ Object
- #name ⇒ Object
- #overrides_subschedule ⇒ Object
- #schedule_layers ⇒ Object
- #self ⇒ Object
- #summary ⇒ Object
- #teams ⇒ Object
- #time_zone ⇒ Object
- #type ⇒ Object
- #users ⇒ Object
Class Method Summary collapse
-
.create_overrides(client, schedule, list) ⇒ Array
Create overrides on a schedule within Pagerduty.
-
.delete_override!(client, schedule, oid) ⇒ Boolean
Delete an override on a schedule within Pagerduty.
-
.find(client, sid) ⇒ Hash
Locates a schedule within Pagerduty.
-
.find!(client, sid) ⇒ Object
Locates a schedule within Pagerduty.
-
.list(client) ⇒ Array
Lists schedules.
-
.overrides(client, schedule, start_time = Time.now.utc.iso8601, end_time = (Time.now.utc + 1.hours).iso8601, editable = true) ⇒ Array
Lists overrides for a schedule within Pagerduty.
-
.update!(client, schedule) ⇒ Object
Updates a schedule within Pagerduty.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ Schedules
constructor
Creates a new Schedules instance.
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Constructor Details
#initialize(object = {}) ⇒ Schedules
Creates a new Readiness::Pagerduty::Schedules instance
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 28 def initialize(object = {}) @description = object['description'] @escalation_policies = object['escalation_policies'] @final_schedule = object['final_schedule'] @html_url = object['html_url'] @id = object['id'] @name = object['name'] @overrides_subschedule = object['overrides_subschedule'] @schedule_layers = object['schedule_layers'] @self = object['self'] @summary = object['summary'] @teams = object['teams'] @time_zone = object['time_zone'] @type = object['type'] @users = object['users'] end |
Instance Attribute Details
#description ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def description @description end |
#escalation_policies ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def escalation_policies @escalation_policies end |
#final_schedule ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def final_schedule @final_schedule end |
#html_url ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def html_url @html_url end |
#id ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def id @id end |
#name ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def name @name end |
#overrides_subschedule ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def overrides_subschedule @overrides_subschedule end |
#schedule_layers ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def schedule_layers @schedule_layers end |
#self ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def self @self end |
#summary ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def summary @summary end |
#teams ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def teams @teams end |
#time_zone ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def time_zone @time_zone end |
#type ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def type @type end |
#users ⇒ Object
17 18 19 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 17 def users @users end |
Class Method Details
.create_overrides(client, schedule, list) ⇒ Array
Create overrides on a schedule within Pagerduty. This will exit on error
190 191 192 193 194 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 190 def self.create_overrides(client, schedule, list) response = client.connection.post "schedules/#{schedule.id}/overrides", { overrides: list }.to_json handle_request_error(1, 'Pagerduty', response.status, { action: 'Create overrides', id: schedule.id }) unless response.status == 201 Oj.load(response.body) end |
.delete_override!(client, schedule, oid) ⇒ Boolean
Delete an override on a schedule within Pagerduty. This will exit on error
215 216 217 218 219 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 215 def self.delete_override!(client, schedule, oid) response = client.connection.delete "schedules/#{schedule.id}/overrides/#{oid}" handle_request_error(1, 'Pagerduty', response.status, { action: 'Delete an override', id: schedule.id }) unless [200, 204].include?(response.status) true end |
.find(client, sid) ⇒ Hash
Locates a schedule within Pagerduty. This will not exit on error (except Authentication errors)
93 94 95 96 97 98 99 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 93 def self.find(client, sid) response = client.connection.get("schedules/#{sid}") handle_request_error(0, 'Pagerduty', response.status, { action: 'get', id: sid }) unless response.status == 200 return Schedules.new(Oj.load(response.body)['schedule']) if response.status == 200 Oj.load(response.body) end |
.find!(client, sid) ⇒ Object
Locates a schedule within Pagerduty. This will exit on error
118 119 120 121 122 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 118 def self.find!(client, sid) response = client.connection.get("schedules/#{sid}") handle_request_error(1, 'Pagerduty', response.status, { action: 'Find schedule', id: sid }) unless response.status == 200 Schedules.new(Oj.load(response.body)['schedule']) end |
.list(client) ⇒ Array
Lists schedules
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 61 def self.list(client) array = [] offset = 0 loop do response = client.connection.get "schedules?limit=100&offset=#{offset}" handle_request_error(0, 'Pagerduty', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['schedules'].map { |e| Schedules.new(e) } break unless body['more'] offset += 100 end array.uniq end |
.overrides(client, schedule, start_time = Time.now.utc.iso8601, end_time = (Time.now.utc + 1.hours).iso8601, editable = true) ⇒ Array
Lists overrides for a schedule within Pagerduty. This will exit on error
145 146 147 148 149 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 145 def self.overrides(client, schedule, start_time = Time.now.utc.iso8601, end_time = (Time.now.utc + 1.hours).iso8601, editable = true) response = client.connection.get "schedules/#{schedule.id}/overrides?editable=#{editable}&since=#{start_time}&until=#{end_time}" handle_request_error(1, 'Pagerduty', response.status, { action: 'List overrides', id: schedule.id }) unless response.status == 201 Oj.load(response.body)['overrides'] end |
.update!(client, schedule) ⇒ Object
Updates a schedule within Pagerduty. This will exit on error
240 241 242 243 244 |
# File 'lib/support_readiness/pagerduty/schedules.rb', line 240 def self.update!(client, schedule) response = client.connection.put "schedules/#{schedule.id}", to_clean_json_with_key(schedule, 'schedule') handle_request_error(1, 'Pagerduty', response.status, { action: 'Update schedule', id: schedule.id, message: Oj.load(response.body)}) unless response.status == 200 Schedules.new(Oj.load(response.body)['schedule']) end |