Module: PagerDuty::Client::EscalationPolicies
- Included in:
- PagerDuty::Client
- Defined in:
- lib/pager_duty/client/escalation_policies.rb
Overview
Module encompassing interactions with the escalation policies API endpoint
Instance Method Summary collapse
-
#create_escalation_policy(name, escalation_rules, options = {}) ⇒ Sawyer::Resource
(also: #create)
Creates an escalation policy.
-
#delete_escalation_policy(id) ⇒ Boolean
(also: #delete)
Remove an existing escalation policy.
-
#escalation_policies(options = {}) ⇒ Array<Sawyer::Resource>
(also: #list_escalation_policies)
List escalation policies.
-
#escalation_policy(id, options = {}) ⇒ Sawyer::Resource
(also: #get_escalation_policy)
Gets escalation policy by id.
-
#update_escalation_policy(id, options = {}) ⇒ Sawyer::Resource
Update an escalation policy.
Instance Method Details
#create_escalation_policy(name, escalation_rules, options = {}) ⇒ Sawyer::Resource Also known as: create
Creates an escalation policy
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pager_duty/client/escalation_policies.rb', line 67 def create_escalation_policy(name, escalation_rules, = {}) params = load_params(name: name, description: .fetch(:description, nil), num_loops: .fetch(:num_loops, nil), escalation_rules: escalation_rules, services: .fetch(:services, []), teams: .fetch(:teams, [])) if [:from_email_address] params[:headers] ||= {} params[:headers][:from] = [:from_email_address] end response = post "/escalation_policies", .merge(params) response[:escalation_policy] end |
#delete_escalation_policy(id) ⇒ Boolean Also known as: delete
Remove an existing escalation policy
50 51 52 |
# File 'lib/pager_duty/client/escalation_policies.rb', line 50 def delete_escalation_policy(id) boolean_from_response :delete, "/escalation_policies/#{id}" end |
#escalation_policies(options = {}) ⇒ Array<Sawyer::Resource> Also known as: list_escalation_policies
List escalation policies
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pager_duty/client/escalation_policies.rb', line 16 def escalation_policies( = {}) user_ids = .fetch(:user_ids, []) team_ids = .fetch(:team_ids, []) query_params = Hash.new query_params["query"] = [:query] if [:query] query_params["user_ids[]"] = user_ids.join(",") if user_ids.length > 0 query_params["team_ids[]"] = team_ids.join(",") if team_ids.length > 0 query_params["include[]"] = [:include] if [:include] query_params["sort_by"] = [:sort_by] if [:sort_by] response = get "/escalation_policies", .merge({query: query_params}) response[:escalation_policies] end |
#escalation_policy(id, options = {}) ⇒ Sawyer::Resource Also known as: get_escalation_policy
Gets escalation policy by id
38 39 40 41 |
# File 'lib/pager_duty/client/escalation_policies.rb', line 38 def escalation_policy(id, = {}) response = get("/escalation_policies/#{id}", ) response[:escalation_policy] end |
#update_escalation_policy(id, options = {}) ⇒ Sawyer::Resource
Update an escalation policy
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/pager_duty/client/escalation_policies.rb', line 96 def update_escalation_policy(id, = {}) policy = {} policy[:type] = "escalation_policy" policy[:name] = [:name] if [:name] policy[:description] = [:description] if [:description] policy[:num_loops] = [:num_loops] if [:num_loops] policy[:escalation_rules] = [:escalation_rules] if [:escalation_rules] policy[:services] = [:services] if [:services] policy[:teams] = [:teams] if [:teams] params = { escalation_policy: policy } response = put "/escalation_policies/#{id}", .merge(params) response[:escalation_policy] end |