Exemplo n.º 1
0
    def pull_update(self, _auto=False):
        """
        Start updates by polling the server for the latest updates.

        This is the only method that needs to be called from outside.  The rest
        are triggered asynchronously.

        Call chain:
        pull_update -> _updates_received -> _update_complete

        _auto: Set to True when called by the scheduled LoopingCall.
        """
        # If this call was triggered externally (_auto=False), then reset the
        # timer for the next scheduled call so we do not poll again too soon.
        if not _auto and self.scheduled_call.running:
            self.scheduled_call.reset()

        def handle_error(error):
            print("Request for updates failed: {}".format(error.getErrorMessage()))

        request = PDServerRequest('/api/routers/{router_id}/updates')
        d = request.get(completed=False)
        d.addCallback(self._updates_received)
        d.addErrback(handle_error)
        yield d
Exemplo n.º 2
0
def verify_cloud_token(token):
    headers = {"Authorization": "Bearer {}".format(token)}

    # Pass custom Authorization header and setAuthHeader=False to prevent
    # PDServerRequest from using the node's own authorization token.
    request = PDServerRequest("/api/users/me",
                              headers=headers,
                              setAuthHeader=False)
    return request.get()
Exemplo n.º 3
0
def verify_cloud_token(token):
    headers = {
        "Authorization": "Bearer {}".format(token)
    }

    # Pass custom Authorization header and setAuthHeader=False to prevent
    # PDServerRequest from using the node's own authorization token.
    request = PDServerRequest("/api/users/me", headers=headers,
            setAuthHeader=False)
    return request.get()
Exemplo n.º 4
0
    def start_long_poll(self):
        self.long_poll_started = True

        while self.use_long_poll:
            request = PDServerRequest('/api/routers/{router_id}/updates/poll')
            try:
                response = yield request.get()
            except Exception:
                pass
            else:
                # 200 = update(s) available
                # 204 = no updates yet
                # 404 = server does not support this endpoint
                if response.code == 200:
                    self.pull_update(_auto=False)
                elif response.code == 404:
                    self.use_long_poll = False