Updated project structure and some file names.
Restored `requirements.txt` Updated `setup.py` to include new repository url and contact details. Moved the rtsp code from `record` to `stream`. Updated project structure to make it more readable and developer friendly - moved mixins to the `mixins` package, moved handlers to the `handlers` package. Moved files not belonging to anything in particular to the `util` package. Updated `camera` class to also defer login call. Deleted unused files like `config_handler`.
This commit is contained in:
44
reolinkapi/handlers/rest_handler.py
Normal file
44
reolinkapi/handlers/rest_handler.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import requests
|
||||
from typing import List, Dict, Union, Optional
|
||||
|
||||
|
||||
class Request:
|
||||
proxies = None
|
||||
|
||||
@staticmethod
|
||||
def post(url: str, data: List[Dict], params: Dict[str, Union[str, float]] = None) -> \
|
||||
Optional[requests.Response]:
|
||||
"""
|
||||
Post request
|
||||
:param params:
|
||||
:param url:
|
||||
:param data:
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
headers = {'content-type': 'application/json'}
|
||||
r = requests.post(url, verify=False, params=params, json=data, headers=headers,
|
||||
proxies=Request.proxies)
|
||||
if r.status_code == 200:
|
||||
return r
|
||||
else:
|
||||
raise ValueError(f"Http Request had non-200 Status: {r.status_code}", r.status_code)
|
||||
except Exception as e:
|
||||
print("Post Error\n", e)
|
||||
raise
|
||||
|
||||
@staticmethod
|
||||
def get(url: str, params: Dict[str, Union[str, float]], timeout: float = 1) -> Optional[requests.Response]:
|
||||
"""
|
||||
Get request
|
||||
:param url:
|
||||
:param params:
|
||||
:param timeout:
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
data = requests.get(url=url, verify=False, params=params, timeout=timeout, proxies=Request.proxies)
|
||||
return data
|
||||
except Exception as e:
|
||||
print("Get Error\n", e)
|
||||
raise
|
||||
Reference in New Issue
Block a user