2018-12-02 22:09:55 -06:00
|
|
|
import requests
|
2018-12-02 15:59:42 -06:00
|
|
|
class TaskService(object):
|
|
|
|
def __init__(self, config):
|
|
|
|
self.config = config
|
|
|
|
|
2018-12-02 22:09:55 -06:00
|
|
|
def findAll():
|
2018-12-02 15:59:42 -06:00
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def modify():
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2018-12-02 22:09:55 -06:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|