Add device token to android app notifier config

This commit is contained in:
JonnyWong16 2017-03-25 23:39:32 -07:00
parent d18c2ffddb
commit 8e13e2deb2
4 changed files with 27 additions and 29 deletions

View file

@ -526,6 +526,12 @@ textarea.form-control:focus {
text-align: center;
pointer-events: none;
}
.form-control[readonly] {
background-color: #555;
}
.form-control[readonly]:focus {
background-color: #fff;
}
.poster {
position: relative;
height: 225px;
@ -3037,12 +3043,6 @@ a:hover .overlay-refresh-image:hover {
#plex-log-levels label {
margin-bottom: 0;
}
#api_key.form-control[readonly] {
background-color: #555;
}
#api_key.form-control[readonly]:focus {
background-color: #fff;
}
#plexpy-notifiers-table .friendly_name,
#notifier-config-modal span.notifier_id {
color: #777;

View file

@ -43,7 +43,7 @@
<label for="${item['name']}">${item['label']}</label>
<div class="row">
<div class="col-md-8">
<input type="${item['input_type']}" class="form-control" id="${item['name']}" name="${item['name']}" value="${item['value']}" size="30">
<input type="${item['input_type']}" class="form-control" id="${item['name']}" name="${item['name']}" value="${item['value']}" size="30" ${'readonly' if item.get('readonly') else ''}>
% if item['name'] == 'osx_notify_app':
<a href="javascript:void(0)" id="osxnotifyregister">Register</a>
% endif

View file

@ -341,13 +341,13 @@ class API2:
return data
def register_android_app(self, notifier_id=None, device_id='', **kwargs):
def register_android_app(self, notifier_id=None, 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_id (str): The device id of the PlexPy Android App
device_token (str): The device token of the PlexPy Android App
Optional parameters:
None
@ -363,8 +363,8 @@ class API2:
self._api_result_type = 'error'
return
elif not device_id:
self._api_msg = 'Device registartion failed: no device id provided.'
elif not device_token:
self._api_msg = 'Device registartion failed: no device token provided.'
self._api_result_type = 'error'
return
@ -375,8 +375,8 @@ class API2:
self._api_result_type = 'error'
return
config = {'androidapp_apikey': notifier['config']['apikey'],
'androidapp_deviceid': device_id}
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.'

View file

@ -665,32 +665,23 @@ class ANDROIDAPP(Notifier):
"""
PlexPy Android App notifications
"""
_DEFAULT_CONFIG = {'apikey': '',
'deviceid': ''
_DEFAULT_CONFIG = {'api_key': '',
'device_token': ''
}
def _register_device(self, apikey='', device_id=''):
config = {'apikey': apikey,
'deviceid': device_id}
if self.set_config(config):
return True
def notify(self, subject='', body='', action='', **kwargs):
if not subject or not body:
return
data = {'to': self.config['deviceid'],
data = {'to': self.config['device_token'],
'data': {'subject': subject.encode("utf-8"),
'body': body.encode("utf-8")}
}
http_handler = HTTPSConnection("api.pushy.me")
http_handler.request("POST",
"/push",
headers={
'Content-type': "application/json"
},
"/push?%s" % urlencode({'api_key': self.config['api_key']}),
headers={'Content-type': "application/json"},
body=json.dumps(data))
response = http_handler.getresponse()
request_status = response.status
@ -707,10 +698,17 @@ class ANDROIDAPP(Notifier):
def return_config_options(self):
config_option = [{'label': 'Pushy API Key',
'value': self.config['apikey'],
'name': 'androidapp_apikey',
'value': self.config['api_key'],
'name': 'androidapp_api_key',
'description': 'Your Pushy API key.',
'input_type': 'text'
},
{'label': 'Device Token',
'value': self.config['device_token'],
'name': 'androidapp_device_token',
'description': 'Your Android App device token. Filled in automatically after registering the deivce in the app.',
'input_type': 'text',
'readonly': True
}
]