You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Plex-Meta-Manager/modules/notifiarr.py

38 lines
1.5 KiB

3 years ago
from json import JSONDecodeError
from modules import util
from modules.util import Failed
logger = util.logger
base_url = "https://notifiarr.com/api/v1/"
dev_url = "https://dev.notifiarr.com/api/v1/"
3 years ago
class Notifiarr:
def __init__(self, config, params):
self.config = config
self.apikey = params["apikey"]
self.develop = params["develop"]
self.test = params["test"]
logger.secret(self.apikey)
logger.debug(f"Environment: {'Test' if self.test else 'Develop' if self.develop else 'Production'}")
3 years ago
url, _ = self.get_url("user/validate/")
response = self.config.get(url)
3 years ago
try:
response_json = response.json()
except JSONDecodeError as e:
logger.debug(e)
raise Failed("Notifiarr Error: Invalid response")
if response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error"):
3 years ago
logger.debug(f"Response: {response_json}")
raise Failed(f"({response.status_code} [{response.reason}]) {response_json}")
3 years ago
if not params["test"] and not response_json["details"]["response"]:
raise Failed("Notifiarr Error: Invalid apikey")
3 years ago
def get_url(self, path):
url = f"{dev_url if self.develop else base_url}{'notification/test' if self.test else f'{path}{self.apikey}'}"
if self.config.trace_mode:
logger.debug(url)
3 years ago
params = {"event": "pmm"} if self.test else None
3 years ago
return url, params