diff --git a/changelog.md b/changelog.md index f0f6b9e..797c452 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file. (Placeholder for unreleased content) +## [1.5.0] + +2022-03-23 + +### Added + +- notification profile create/get/update/delete https://nodeping.com/docs-api-notificationprofiles.html + ## [1.4.1] 2022-01-13 diff --git a/nodeping_api/notificationprofiles.py b/nodeping_api/notificationprofiles.py new file mode 100644 index 0000000..6939711 --- /dev/null +++ b/nodeping_api/notificationprofiles.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Manage notification profiles for NodePing Account. + +https://nodeping.com/docs-api-notificationprofiles.html +""" + +from . import _query_nodeping_api, _utils, config + +API_URL = "{0}notificationprofiles".format(config.API_URL) + + +def get(token, + customerid=None, + id=None): + """Get one or all notification profiles for an account or subaccount. + + :param token: The NodePing token for your account + :type token: str + :param customerid: (optional) ID for the subaccount + :type customerid: str + :param id: (optional) - id of the notification profile you want to get. + """ + if id: + url = "{0}?id={1}".format(API_URL, id) + else: + url = API_URL + + url = _utils.create_url(token, url, customerid) + + return _query_nodeping_api.get(url) + + +def create(token, + name, + notifications, + customerid=None): + """Create a new notification profile. + + :param token: The NodePing token for your account + :type token: str + :param name: label for the notification profile + :type name: str + :param notifications: list containing the contact or group id, delay, and scheduling for notifications + :type notifications: list + :param customerid: (optional) ID for the subaccount + :type customerid: str + + notifications param example: + + [ + {"contactkey1": + {"delay":0, + "schedule":"schedule1" + } + }, + {"contactkey2": + {"delay":5, + "schedule":"schedule2" + } + } + ] + """ + url = _utils.create_url(token, API_URL, customerid) + data = {"notifications": notifications, "name": name} + + return _query_nodeping_api.post(url, data) + + +def update(token, + name, + id, + notifications, + customerid=None): + """Update information for a contact profile. + + :param token: The NodePing token for your account + :type token: str + :param name: label for the notification profile + :type name: str + :param id: notification profile id you want to modify + :type id: str + :param notifications: list containing the contact or group id, delay, and scheduling for notifications + :type notifications: list + :param customerid: (optional) ID for the subaccount + :type customerid: str + + notifications param example: + + [ + {"contactkey1": + {"delay":0, + "schedule":"schedule1" + } + }, + {"contactkey2": + {"delay":5, + "schedule":"schedule2" + } + } + ] + """ + url = _utils.create_url(token, API_URL, customerid) + data = {"notifications": notifications, "name": name, "id": id} + + return _query_nodeping_api.put(url, data) + + +def delete(token, + id, + customerid=None): + """Get one or all notification profiles for an account or subaccount. + + :param token: The NodePing token for your account + :type token: str + :param customerid: (optional) ID for the subaccount + :type customerid: str + :param id: (optional) - id of the notification profile you want to get. + """ + url = "{0}/{1}".format(API_URL, id) + + url = _utils.create_url(token, url, customerid) + + return _query_nodeping_api.delete(url) diff --git a/setup.py b/setup.py index c07cd36..1313ab6 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ URL = "https://github.com/NodePing/python-nodeping-api" EMAIL = "support@nodeping.com" AUTHOR = "NodePing" -VERSION = "1.4.1" +VERSION = "1.5.0" LICENSE = "MIT" setuptools.setup(