Class: EscalationPolicy

Inherits:
Pagerduty show all
Defined in:
lib/pagerduty/models/escalationpolicies.rb

Instance Attribute Summary

Attributes inherited from Pagerduty

#subdomain, #token

Instance Method Summary collapse

Methods inherited from Pagerduty

#acknowledge, #alerts, #alerts_per_time, #create_escalation_policy, #create_maintenance_window, #create_schedule_override, #create_service, #create_user, #escalation_policies, #escalation_rules, #get_escalation_policy, #get_escalation_rule, #get_incident, #get_incident_counts, #get_log_entries, #get_log_entry, #get_maintenance_window, #get_maintenance_windows, #get_schedule, #get_schedule_users, #get_schedules, #get_service, #get_services, #get_user, #get_users, #has_requirements?, #incidents, #incidents_per_time, #initialize, #notes, #resolve, #trigger

Methods included from Pagerduty::Core

#curl, #has_requirements?

Constructor Details

This class inherits a constructor from Pagerduty

Instance Method Details

#add_escalation_rule(options = {}) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/pagerduty/models/escalationpolicies.rb', line 107

def add_escalation_rule(options={})
  EscalationRule.new(JSON.parse(curl({
    uri: "https://#@@subdomain.pagerduty.com/api/v1/escalation_policies/#{self.id}/escalation_rules",
    data: { escalation_rule: options.hashify },
    method: 'POST'
  }).body)['escalation_rule'])
end

#deleteObject



96
97
98
99
100
101
102
103
104
105
# File 'lib/pagerduty/models/escalationpolicies.rb', line 96

def delete
  res = curl({
    uri: "https://#@@subdomain.pagerduty.com/api/v1/escalation_policies/#{self.id}",
    method: 'DELETE',
    raw_response: true
  })

  res.code == '204' ? 'Successfully deleted policy' : JSON.parse(res.body)

end

#refreshObject



125
126
127
# File 'lib/pagerduty/models/escalationpolicies.rb', line 125

def refresh
  self.attributes = get_escalation_policy(id: self.id)
end

#saveObject



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/pagerduty/models/escalationpolicies.rb', line 82

def save
  self.escalation_rules = self.escalation_rules.map { |rule|
    rule.class == EscalationRule ? rule.hashify : rule
  }

  saved_policy = EscalationPolicy.new(JSON.parse(curl({
    uri: "https://#@@subdomain.pagerduty.com/api/v1/escalation_policies/#{self.id}",
    data: { escalation_policy: self.attributes },
    method: 'PUT'
  }).body)['escalation_policy'])

  self.attributes = saved_policy.attributes
end

#update_escalation_rules(options = {}) ⇒ Object



115
116
117
118
119
120
121
122
123
# File 'lib/pagerduty/models/escalationpolicies.rb', line 115

def update_escalation_rules(options={})
  options[:rules] = options[:rules].map { |rule| rule.class == EscalationRule ? rule.hashify : rule }

  JSON.parse(curl({
    uri: "https://#@@subdomain.pagerduty.com/api/v1/escalation_policies/#{self.id}/escalation_rules",
    data: { escalation_rules: options[:rules] },
    method: 'PUT'
  }).body)
end