Esempio n. 1
0
 def handle_event(self, event):
     api_event = ApiEvent(event)
     action = api_event.action
     event = api_event.event
     if action == self.EVENT_COMMAND_INSERT_ACTION:
         command = Command(self._api, event[self.EVENT_COMMAND_KEY])
         return self._handler.handle_command_insert(command)
     if action == self.EVENT_COMMAND_UPDATE_ACTION:
         command = Command(self._api, event[self.EVENT_COMMAND_KEY])
         return self._handler.handle_command_update(command)
     if action == self.EVENT_NOTIFICATION_ACTION:
         notification = Notification(event[self.EVENT_NOTIFICATION_KEY])
         return self._handler.handle_notification(notification)
Esempio n. 2
0
 def handle_event(self, event):
     api_event = ApiEvent(event)
     action = api_event.action
     subscription_id = api_event.subscription_id
     if self._api.removed_subscription_id_exists(action, subscription_id):
         return
     event = api_event.event
     if action == self.EVENT_COMMAND_INSERT_ACTION:
         command = Command(self._api, event[self.EVENT_COMMAND_KEY])
         return self._handler.handle_command_insert(command)
     if action == self.EVENT_COMMAND_UPDATE_ACTION:
         command = Command(self._api, event[self.EVENT_COMMAND_KEY])
         return self._handler.handle_command_update(command)
     if action == self.EVENT_NOTIFICATION_ACTION:
         notification = Notification(event[self.EVENT_NOTIFICATION_KEY])
         return self._handler.handle_notification(notification)
Esempio n. 3
0
 def send_notification(self,
                       device_id,
                       notification_name,
                       parameters=None,
                       timestamp=None):
     notification = {'notification': notification_name}
     if parameters:
         notification['parameters'] = parameters
     if timestamp:
         notification['timestamp'] = timestamp
     auth_api_request = AuthApiRequest(self)
     auth_api_request.method('POST')
     auth_api_request.url('device/{deviceId}/notification',
                          deviceId=device_id)
     auth_api_request.action('notification/insert')
     auth_api_request.set('notification', notification, True)
     auth_api_request.response_key('notification')
     notification = auth_api_request.execute('Notification send failure.')
     notification[Notification.DEVICE_ID_KEY] = device_id
     notification[Notification.NOTIFICATION_KEY] = notification_name
     notification[Notification.PARAMETERS_KEY] = parameters
     return Notification(notification)
Esempio n. 4
0
 def list_notifications(self,
                        device_id,
                        start=None,
                        end=None,
                        notification=None,
                        sort_field=None,
                        sort_order=None,
                        take=None,
                        skip=None):
     auth_api_request = AuthApiRequest(self)
     auth_api_request.url('device/{deviceId}/notification',
                          deviceId=device_id)
     auth_api_request.action('notification/list')
     auth_api_request.param('start', start)
     auth_api_request.param('end', end)
     auth_api_request.param('notification', notification)
     auth_api_request.param('sortField', sort_field)
     auth_api_request.param('sortOrder', sort_order)
     auth_api_request.param('take', take)
     auth_api_request.param('skip', skip)
     auth_api_request.response_key('notifications')
     notifications = auth_api_request.execute('List notifications failure.')
     return [Notification(notification) for notification in notifications]