Added in basicAuth

Added in updateApplicationImage
Added in getClients

Added in deep regret at forgetting a headers=self.headers
This commit is contained in:
Benjamyn Love 2018-11-10 19:55:08 +11:00
parent ade83db3aa
commit 51eb2e9f2d
2 changed files with 38 additions and 4 deletions

View File

@ -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
<h3>Functions Implimented</h3> <b/>
-getApplications() // Gets a list of applications and returns the value in a dictionary
-createApplication(name, description) // Creates a new Application

View File

@ -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