From 51eb2e9f2d95a35b22830da71ddacc3dd21da20a Mon Sep 17 00:00:00 2001 From: benjamyn Date: Sat, 10 Nov 2018 19:55:08 +1100 Subject: [PATCH] Added in basicAuth Added in updateApplicationImage Added in getClients Added in deep regret at forgetting a headers=self.headers --- README.md | 2 +- gotipy.py | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index da98fdc..1a68a2c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Initialize the wrapper with the token you want to use i.e: gotipy_usr = gotipy.gotipy("user token", "https://URL.TLD") -Functions Implimented +

Functions Implimented

-getApplications() // Gets a list of applications and returns the value in a dictionary -createApplication(name, description) // Creates a new Application diff --git a/gotipy.py b/gotipy.py index 65dcd95..0c9b496 100644 --- a/gotipy.py +++ b/gotipy.py @@ -1,13 +1,29 @@ import requests import json +import base64 from pprint import pprint +proxies = { + 'http': "localhost:8080" +} + class gotipy(object): def __init__(self, token, url): self.token = token self.url = url self.headers = {'X-Gotify-Key' : self.token} +## Auth Function + def basicAuth(self, user, passwd): + self.user = user + self.passwd = passwd + self.string = self.user + ':' + self.passwd + self.encoded = base64.b64encode(self.string.encode("utf-8")) + print(self.string.encode('utf-8')) + self.headers["authorization"] = "Basic " + base64.b64encode(self.string) + print(self.encoded) + return self.headers + ## Token Functions def getApplications(self): self.requrl = self.url + '/application' @@ -31,13 +47,31 @@ class gotipy(object): pprint(req) return req - def deleteApplication(self, id): - self.id = id - self.requrl = self.url + '/application/' + self.id + def deleteApplication(self, appid): + self.appid = appid + self.requrl = self.url + '/application/' + self.appid req = requests.delete(self.requrl, headers=self.headers) return req + def updateApplicationImage(self, appid, imgData): + self.id = appid + self.imgData = { 'file': imgData} + self.requrl = self.url + '/application/' + self.id + '/image' + + req = requests.post(self.requrl, headers=self.headers, files=self.imgData) + return req + + def getClients(self, user, passwd): + self.user = user + self.passwd = passwd + self.requrl = self.url + '/client' + + print(self.headers) + + req = requests.get(self.requrl, headers=self.headers, proxies=proxies) + return req + ## Message Functions def sendMessage(self, title, message): self.title = title