taskwarrior-grocy/apps/__init__.py

88 lines
1.4 KiB
Python
Raw Normal View History

import requests
2018-12-02 15:59:42 -06:00
class TaskService(object):
def __init__(self, config):
self.config = config
def findAll():
2018-12-02 15:59:42 -06:00
raise NotImplementedError()
def modify():
raise NotImplementedError()
class RestService(object):
def __init__(self, api_url, json):
self.api_url = api_url
self.headers = {}
self.json
def get(self, path):
api_url = self.api_url
if api_url.endswith('/'):
url = '{0}{1}'.format(api_url, path)
else
url = '{0}/{1}'.format(api_url, path)
r = requests.get(url, headers=self.headers)
if self.json:
return r.json()
return r.content
def delete(self, id):
api_url = self.api_url
if api_url.endswith('/'):
url = '{0}{1}'.format(api_url, path)
else
url = '{0}/{1}'.format(api_url, path)
r = requests.get(url, headers=self.headers)
if self.json:
return r.json()
return r.content
def post(self, data):
api_url = self.api_url
if api_url.endswith('/'):
url = '{0}{1}'.format(api_url, path)
else
url = '{0}/{1}'.format(api_url, path)
r = requests.post(url, data, headers=self.headers)
if self.json:
return r.json()
return r.content
def addHeader(self, type, value):
self.header[type] = value
2018-12-02 15:59:42 -06:00