예제 #1
0
 def register_device(self, update=False):
     if self.socketIO:
         self.socketIO.disconnect()
         self.socketIO = None
     self.token_event = threading.Event()
     self.ws_thread = threading.Thread(target=self._start_ws)
     self.ws_thread.start()
     self.token_event.wait(15)
     if not self.token:
         if hasattr(self, "socketIO"):
             self.socketIO.disconnect()
         raise TelepatError('Websocket connection failed')
     params = {}
     info = {"os": platform.system(),
             "version": platform.release()
     }
     if not update: info["udid"] = str(uuid.uuid4())
     params["info"] = info
     params["volatile"] = {
         "type": "sockets",
         "token": self.token,
         "active": 1
     }
     response = httpmanager.post("/device/register", params, {})
     if response.status_code == 200:
         response_json = response.json()
         if "identifier" in response_json["content"]:
             device_id = response_json["content"]["identifier"]
             self.device_id = device_id
             self.db.set_operations_data("device_id_{0}".format(self.app_id), device_id)
     return response
예제 #2
0
 def login_admin(self, username, password):
     params = {
         "email": username,
         "password": password
     }
     response = httpmanager.post("/admin/login", params, {})
     if response.status_code == 200:
         httpmanager.bearer = response.json()["content"]["token"]
     return response
예제 #3
0
 def patch(self, obj):
     old_object = self.object_with_id(obj.id)
     assert old_object
     patches = old_object.patch_against(obj)
     patch = {
         "model": self.model_name,
         "context": self.context.id,
         "id": obj.id,
         "patches": patches
     }
     obj.uuid = str(uuid.uuid4())
     response = httpmanager.post("/object/update", patch, {})
     patch_response = TelepatResponse(response)
     return (obj.uuid, patch_response)
예제 #4
0
 def subscribe(self):
     response = httpmanager.post("/object/subscribe", self.params_for_subscription(), {})
     subscribe_response = TelepatResponse(response)
     if subscribe_response.status == 200 and isinstance(subscribe_response.content, list):
         for obj_dict in subscribe_response.content:
             self.process_notification(
                 TelepatTransportNotification(
                     NOTIFICATION_TYPE_ADDED,
                     "/",
                     obj_dict
                 )
             )
         self.telepat_instance.register_subscription(self)
     return subscribe_response
예제 #5
0
 def update_context(self, updated_context):
     context = self.context_map()[updated_context.id]
     return TelepatResponse(httpmanager.post("/admin/context/update", context.patch_against(updated_context), {}))
예제 #6
0
 def get_users(self):
     response = httpmanager.post("/admin/user/all", {}, {})
     return TelepatResponse(response)
예제 #7
0
 def unsubscribe(self):
     response = httpmanager.post("/object/unsubscribe", self.params_for_subscription(), {})
     unsubscribe_response = response
     if unsubscribe_response.status_code == 200:
         self.telepat_instance.unregister_subscription(self)
     return unsubscribe_response