mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Move webserver notify to API
This commit is contained in:
parent
29ab470e42
commit
9b4536f132
4 changed files with 52 additions and 8 deletions
|
@ -35,6 +35,8 @@ import database
|
|||
import libraries
|
||||
import logger
|
||||
import mobile_app
|
||||
import notification_handler
|
||||
import notifiers
|
||||
import users
|
||||
|
||||
|
||||
|
@ -397,6 +399,50 @@ class API2:
|
|||
|
||||
return
|
||||
|
||||
def notify(self, notifier_id='', subject='Tautulli', body='Test notification', **kwargs):
|
||||
""" Send a notification using Tautulli.
|
||||
|
||||
```
|
||||
Required parameters:
|
||||
notifier_id (int): The ID number of the notification agent
|
||||
subject (str): The subject of the message
|
||||
body (str): The body of the message
|
||||
|
||||
Optional parameters:
|
||||
None
|
||||
|
||||
Returns:
|
||||
None
|
||||
```
|
||||
"""
|
||||
if not notifier_id:
|
||||
self._api_msg = 'Notification failed: no notifier id provided.'
|
||||
self._api_result_type = 'error'
|
||||
return
|
||||
|
||||
notifier = notifiers.get_notifier_config(notifier_id=notifier_id)
|
||||
|
||||
if not notifier:
|
||||
self._api_msg = 'Notification failed: invalid notifier_id provided %s.' % notifier_id
|
||||
self._api_result_type = 'error'
|
||||
return
|
||||
|
||||
logger.api_debug(u'Tautulli APIv2 :: Sending notification.')
|
||||
success = notification_handler.notify(notifier_id=notifier_id,
|
||||
notify_action='api',
|
||||
subject=subject,
|
||||
body=body,
|
||||
**kwargs)
|
||||
|
||||
if success:
|
||||
self._api_msg = 'Notification sent.'
|
||||
self._api_result_type = 'success'
|
||||
else:
|
||||
self._api_msg = 'Notification failed.'
|
||||
self._api_result_type = 'error'
|
||||
|
||||
return
|
||||
|
||||
def _api_make_md(self):
|
||||
""" Tries to make a API.md to simplify the api docs. """
|
||||
|
||||
|
@ -581,8 +627,8 @@ General optional parameters:
|
|||
if isinstance(result, (dict, list)):
|
||||
ret = result
|
||||
else:
|
||||
raise
|
||||
except:
|
||||
raise Exception
|
||||
except Exception:
|
||||
try:
|
||||
ret = json.loads(result)
|
||||
except (ValueError, TypeError):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue