From 99f748ed7f445c5dfb019b6327d119e08f00cad4 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Sun, 5 Oct 2014 01:30:14 +0200 Subject: another massive commit all of this should be squashed later.. at least most of it works now, I think... I should add some tests probably. --- client/bug_delete.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'client/bug_delete.py') diff --git a/client/bug_delete.py b/client/bug_delete.py index bcce88e..393225e 100755 --- a/client/bug_delete.py +++ b/client/bug_delete.py @@ -10,24 +10,37 @@ required. -i, --ticket-id ID of the ticket to delete """ from docopt import docopt -import json, requests +import json, requests, sys +import configparser if __name__ == '__main__': print(docopt(__doc__)) -def call(args): +def entrypoint(args): print(args) - api_endpoint = args['--uri'] + '/api/1.0/ticket/' + c = configparser.ConfigParser() + c.read('config') + config = c[args['--uri']] + access_token = config['access_token'] - req = requests.delete(api_endpoint + args['']) + uri = args['--uri'] + '/api/1.0/ticket/' + args[''] + headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Access-Token': access_token, + } + + req = requests.delete(uri, headers=headers, verify=False) res = json.loads(req.text) - if req.status_code == 404: - print("Ticket with ID '{}' could not be deleted: {}".format(args[''], res['error'])) + if req.status_code == (401 or 404): + sys.exit("Ticket with ID '{}' could not be deleted: {}".format(args[''], res['error'])) + elif req.status_code == 200: - print("Ticket with ID '{}' deleted successfully.".format(args[''])) + sys.exit("Ticket with ID '{}' deleted successfully.".format(args[''])) + else: - exit("ALERT ALERT ALERT") + sys.exit("ALERT ALERT ALERT") #print("{} {}\n {}".format(t['id'], t['title'], t['uri'])) -- cgit v1.2.3-54-g00ecf