Update Android app device registration

This commit is contained in:
JonnyWong16 2017-03-27 20:50:00 -07:00
parent 203a6d47b4
commit 896922de4f
4 changed files with 75 additions and 41 deletions

View file

@ -341,13 +341,13 @@ class API2:
return data
def register_android_app(self, notifier_id=None, device_token='', **kwargs):
def register_device(self, device_name='', device_token='', **kwargs):
""" Registers the PlexPy Android App for notifications.
```
Required parameters:
notifier_id (int): The notifier id of the PlexPy Android App notifier
device_token (str): The device token of the PlexPy Android App
device_name (str): The device name of the PlexPy Android App
Optional parameters:
None
@ -356,10 +356,8 @@ class API2:
None
```
"""
import notifiers
if not notifier_id:
self._api_msg = 'Device registartion failed: no notifier id provided.'
if not device_name:
self._api_msg = 'Device registartion failed: no device name provided.'
self._api_result_type = 'error'
return
@ -368,24 +366,23 @@ class API2:
self._api_result_type = 'error'
return
if notifier_id:
notifier = notifiers.get_notifier_config(notifier_id=notifier_id)
if not notifier or notifier['agent_id'] != 21:
self._api_msg = 'Device registartion failed: Incorrect notifier id provided'
self._api_result_type = 'error'
return
db = database.MonitorDatabase()
config = {'androidapp_api_key': notifier['config']['api_key'],
'androidapp_device_token': device_token}
if notifiers.set_notifier_config(notifier_id=notifier_id, agent_id=notifier['agent_id'], **config):
self._api_msg = 'Device registration successful.'
self._api_result_type = 'success'
return
keys = {'device_token': device_token}
values = {'device_name': device_name}
else:
self._api_msg = 'Device registration failed.'
self._api_result_type = 'error'
try:
db.upsert(table_name='mobile_devices', key_dict=keys, value_dict=values)
except Exception as e:
logger.warn(u"PlexPy APIv2 :: Failed to register mobile device in the database: %s." % e)
self._api_msg = 'Device registartion failed: database error.'
self._api_result_type = 'error'
return
logger.info(u"PlexPy APIv2 :: Registered mobile device in the database: %s." % device_name)
self._api_msg = 'Device registration successful.'
self._api_result_type = 'success'
return
def _api_make_md(self):
""" Tries to make a API.md to simplify the api docs. """