Module: PagerDuty::Client::Addons

Included in:
PagerDuty::Client
Defined in:
lib/pager_duty/client/addons.rb

Overview

Third-party developers can write their own add-ons to PagerDuty’s UI, to add HTML to the product.

Given a configuration containing a <tt>src</ttd> parameter, that URL will be embedded in an iframe on a page that’s available to users from a drop-down menu.

Instance Method Summary collapse

Instance Method Details

#addon(id, options = {}) ⇒ Sawyer::Resource Also known as: get_addon

Get details about an existing add-on.

Parameters:

  • id (String)

    PagerDuty id for addon

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

    A customizable set of options.

Returns:

  • (Sawyer::Resource)

    A hash representing add-on

See Also:



37
38
39
40
# File 'lib/pager_duty/client/addons.rb', line 37

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

#addons(options = {}) ⇒ Array<Sawyer::Resource> Also known as: list_addons

List add-ons

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • :include_services (boolean) — default: false

    Whether to include referenced services

  • :service_ids (Array<String>)

    ids of services to include

  • :filter (String) — default: nil

    Filter to type of addon (one of :full_page_addon or :incident_show_addon)

Returns:

  • (Array<Sawyer::Resource>)

    An array of hashes representing add-ons

See Also:



19
20
21
22
23
24
25
26
27
# File 'lib/pager_duty/client/addons.rb', line 19

def addons(options = {})
  query = Hash.new
  query["include[]"]     = "services" if options.fetch(:include_services, false)
  query["service_ids[]"] = options.fetch(:service_ids, [])
  query["filter"]        = options[:filter] if options[:filter] && [:full_page_addon, :incident_show_addon].include?(options[:filter])

  response = get "/addons", options.merge({query: query})
  response[:addons]
end

#delete_addon(id) ⇒ Boolean

Remove an existing add-on.

Parameters:

  • id (String)

    addon ID

Returns:

  • (Boolean)

See Also:



71
72
73
# File 'lib/pager_duty/client/addons.rb', line 71

def delete_addon(id)
  boolean_from_response :delete, "/addons/#{id}"
end

#install_addon(type, name, src, options = {}) ⇒ Sawyer::Resource Also known as: create_addon

Creates an add-on in the associated account

Parameters:

  • type (Symbol)

    Type of addon (one of :full_page_addon or :incident_show_addon)

  • name (String)

    name of addon

  • src (String)

    HTTPS URL of addon

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

    A customizable set of options.

Returns:

  • (Sawyer::Resource)

    A hash representing add-on created

See Also:



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pager_duty/client/addons.rb', line 52

def install_addon(type, name, src, options = {})
  params = { 
    addon: {
      type: type,
      name: name,
      src:  src
    }
  }
  response = post "/addons", options.merge(params)
  response[:addon]
end

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

Updates addon

Parameters:

  • id (String)

    Addon ID

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

    A customizable set of options.

Options Hash (options):

  • :type (String)

    Type of addon (one of :full_page_addon or :incident_show_addon)

  • :name (String)

    Name of addon

  • :src (String)

    HTTPS URL of addon

Returns:

  • (Sawyer::Resource)

    A hash representing add-on updated

See Also:



85
86
87
88
89
90
91
92
# File 'lib/pager_duty/client/addons.rb', line 85

def update_addon(id, options = {})
  # params = {addon: {}}
  # params[:addon][:type] = options[:type] if options.key?(:type)
  # params[:addon][:name] = options[:name] if options.key?(:name)
  # params[:addon][:src]  = options[:src] if options.key?(:src)
  response = put "addons/#{id}", options
  response[:addon]
end