/**
  * Send the next part of the file to upload.
  * @param [$chunk] the next set of bytes to send. If false will used $data passed
  * at construct time.
  */
 public function nextChunk($chunk = false)
 {
     if (false == $this->resumeUri) {
         $this->resumeUri = $this->getResumeUri();
     }
     if (false == $chunk) {
         $chunk = substr($this->data, $this->progress, $this->chunkSize);
     }
     $lastBytePos = $this->progress + strlen($chunk) - 1;
     $headers = array('content-range' => "bytes {$this->progress}-{$lastBytePos}/{$this->size}", 'content-type' => $this->request->getRequestHeader('content-type'), 'content-length' => $this->chunkSize, 'expect' => '');
     $httpRequest = new Analytify_Google_Http_Request($this->resumeUri, 'PUT', $headers, $chunk);
     if ($this->client->getClassConfig("Analytify_Google_Http_Request", "enable_gzip_for_uploads")) {
         $httpRequest->enableGzip();
     } else {
         $httpRequest->disableGzip();
     }
     $response = $this->client->getIo()->makeRequest($httpRequest);
     $response->setExpectedClass($this->request->getExpectedClass());
     $code = $response->getResponseHttpCode();
     $this->httpResultCode = $code;
     if (308 == $code) {
         // Track the amount uploaded.
         $range = explode('-', $response->getResponseHeader('range'));
         $this->progress = $range[1] + 1;
         // Allow for changing upload URLs.
         $location = $response->getResponseHeader('location');
         if ($location) {
             $this->resumeUri = $location;
         }
         // No problems, but upload not complete.
         return false;
     } else {
         return Analytify_Google_Http_REST::decodeHttpResponse($response);
     }
 }
Beispiel #2
0
 /**
  * Revoke an OAuth2 access token or refresh token. This method will revoke the current access
  * token, if a token isn't provided.
  * @throws Analytify_Google_Auth_Exception
  * @param string|null $token The token (access token or a refresh token) that should be revoked.
  * @return boolean Returns True if the revocation was successful, otherwise False.
  */
 public function revokeToken($token = null)
 {
     if (!$token) {
         if (!$this->token) {
             // Not initialized, no token to actually revoke
             return false;
         } elseif (array_key_exists('refresh_token', $this->token)) {
             $token = $this->token['refresh_token'];
         } else {
             $token = $this->token['access_token'];
         }
     }
     $request = new Analytify_Google_Http_Request(self::OAUTH2_REVOKE_URI, 'POST', array(), "token={$token}");
     $request->disableGzip();
     $response = $this->client->getIo()->makeRequest($request);
     $code = $response->getResponseHttpCode();
     if ($code == 200) {
         $this->token = null;
         return true;
     }
     return false;
 }