grocy-cli/grocy/request.py

26 lines
768 B
Python
Raw Normal View History

2019-06-16 23:54:10 -05:00
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()