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

Instance Method Details

#create_escalation_policy(name, escalation_rules, options = {}) ⇒ Sawyer::Resource Also known as: create

Creates an escalation policy

Parameters:

  • name:

    nil [String] name for policy

  • escalation_rules:
    Array<Sawyer::Resource>

    List of escalation rule

  • options (Sawyer::Resource) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :description (String) — default: ""

    description of policy

  • :num_loops (Integer) — default: 0

    Number of loops

  • :services (Array<Sawyer::Resource>) — default: []

    List of services

  • :teams (Array<Sawyer::Resource>) — default: []

    List of associated teams

Returns:

  • (Sawyer::Resource)

    Represents escalation policy

See Also:



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, options = {}) 
  params = load_params(name: name, 
                       description: options.fetch(:description, nil),
                       num_loops: options.fetch(:num_loops, nil),
                       escalation_rules: escalation_rules, 
                       services: options.fetch(:services, []),
                       teams: options.fetch(:teams, []))
  if options[:from_email_address]
    params[:headers] ||= {}
    params[:headers][:from] = options[:from_email_address]
  end
  response = post "/escalation_policies", options.merge(params)
  response[:escalation_policy]
end

#delete_escalation_policy(id) ⇒ Boolean Also known as: delete

Remove an existing escalation policy

Parameters:

  • id (String)

    PagerDuty identifier for escalation policy

Returns:

  • (Boolean)

See Also:



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

Parameters:

  • options (Sawyer::Resource) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :query (String)

    Filters the results, showing only the escalation policies whose names contain the query.

  • :user_ids (Array<string>)

    Filters the results, showing only escalation policies on which any of the users is a target.

  • :team_ids (Array<string>)

    An array of team IDs. Only results related to these teams will be returned. Account must have the teams ability to use this parameter.

  • :include (Array<string>)

    Array of additional details to include (One or more of :services, :teams, :targets)

  • :sort_by (String) — default: "name"

    Sort the list by ‘name’, ‘name:asc’ or ‘name:desc

Returns:

  • (Array<Sawyer::Resource>)

    An array of hashes representing escalation policies

See Also:



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(options = {})
  user_ids = options.fetch(:user_ids, [])
  team_ids = options.fetch(:team_ids, [])
  query_params = Hash.new
  query_params["query"]      = options[:query] if options[: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[]"]  = options[:include] if options[:include]
  query_params["sort_by"]    = options[:sort_by] if options[:sort_by]
  
  response = get "/escalation_policies", options.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

Parameters:

  • id (String)

    Unique identifier

  • options (Sawyer::Resource) (defaults to: {})

    A customizable set of options.

Returns:

  • (Sawyer::Resource)

    Represents escalation policy

See Also:



38
39
40
41
# File 'lib/pager_duty/client/escalation_policies.rb', line 38

def escalation_policy(id, options = {})
  response = get("/escalation_policies/#{id}", options)
  response[:escalation_policy]
end

#update_escalation_policy(id, options = {}) ⇒ Sawyer::Resource

Update an escalation policy

Parameters:

  • id (String)

    PagerDuty ID

  • options (Sawyer::Resource) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :name (String)

    Name for policy

  • :description (String)

    Description of policy

  • :num_loops (Integer)

    Number of loops

  • :escalation_rules (Array<Sawyer::Resource>)

    List of escalation rules

  • :services (Array<Sawyer::Resource>)

    List of services

  • :teams (Array<Sawyer::Resource>)

    List of associated teams

Returns:

  • (Sawyer::Resource)

    Represents escalation policy

See Also:



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, options = {}) 
  policy = {}
  policy[:type]             = "escalation_policy"
  policy[:name]             = options[:name] if options[:name]
  policy[:description]      = options[:description] if options[:description]
  policy[:num_loops]        = options[:num_loops] if options[:num_loops]
  policy[:escalation_rules] = options[:escalation_rules] if options[:escalation_rules]
  policy[:services]         = options[:services] if options[:services]
  policy[:teams]            = options[:teams] if options[:teams]

  params = { escalation_policy: policy }
  response = put "/escalation_policies/#{id}", options.merge(params)   
  response[:escalation_policy]
end