26 lines
768 B
Python
26 lines
768 B
Python
|
from grocy.conf import Configuration
|
||
|
from requests import request
|
||
|
import logging
|
||
|
|
||
|
|
||
|
class Request(object):
|
||
|
def __init__(self, method, url):
|
||
|
self.conf = Configuration()
|
||
|
self.conf.load()
|
||
|
self.url = url
|
||
|
self.method = method
|
||
|
self.headers = {
|
||
|
'Content-Type': 'application/json',
|
||
|
'Accept': 'application/json'
|
||
|
}
|
||
|
if self.conf.token:
|
||
|
self.headers[self.conf.API_KEY_HEADER] = self.conf.token
|
||
|
|
||
|
def send(self):
|
||
|
logger = logging.getLogger('request.send')
|
||
|
r = request(method=self.method, url=self.url, headers=self.headers)
|
||
|
if r.raise_for_status():
|
||
|
logger.error(r.raise_for_status())
|
||
|
raise r.raise_for_status()
|
||
|
return r.json()
|