From 329f247fbe90cc36aadd8775322623e4682a4d7b Mon Sep 17 00:00:00 2001 From: Luke Epp Date: Thu, 22 Sep 2016 15:00:44 -0700 Subject: [PATCH] Added abilities examples --- REST_API_v2/Abilities/list_abilities.py | 45 +++++++++++++++++++++++ REST_API_v2/Abilities/test_ability.py | 48 +++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100755 REST_API_v2/Abilities/list_abilities.py create mode 100755 REST_API_v2/Abilities/test_ability.py diff --git a/REST_API_v2/Abilities/list_abilities.py b/REST_API_v2/Abilities/list_abilities.py new file mode 100755 index 0000000..dbe7f79 --- /dev/null +++ b/REST_API_v2/Abilities/list_abilities.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# +# Copyright (c) 2016, PagerDuty, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of PagerDuty Inc nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import requests + +# Update to match your API key +API_KEY = '3c3gRvzx7uGfMYEnWKvF' + + +def list_abilities(): + url = 'https://api.pagerduty.com/abilities' + headers = { + 'Accept': 'application/vnd.pagerduty+json;version=2', + 'Authorization': 'Token token={token}'.format(token=API_KEY) + } + r = requests.get(url, headers=headers) + print 'Status Code: {code}'.format(code=r.status_code) + print r.json() + +if __name__ == '__main__': + list_abilities() diff --git a/REST_API_v2/Abilities/test_ability.py b/REST_API_v2/Abilities/test_ability.py new file mode 100755 index 0000000..7a1da01 --- /dev/null +++ b/REST_API_v2/Abilities/test_ability.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# +# Copyright (c) 2016, PagerDuty, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of PagerDuty Inc nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import requests + +# Update to match your API key +API_KEY = '3c3gRvzx7uGfMYEnWKvF' + +# Update to match your ability ID +ID = 'sso' + + +def test_ability(): + url = 'https://api.pagerduty.com/abilities/{id}'.format(id=ID) + headers = { + 'Accept': 'application/vnd.pagerduty+json;version=2', + 'Authorization': 'Token token={token}'.format(token=API_KEY) + } + r = requests.get(url, headers=headers) + print 'Status Code: {code}'.format(code=r.status_code) + print r.text + +if __name__ == '__main__': + test_ability()