コード例 #1
0
ファイル: Batch.php プロジェクト: DanMaiman/Awfulkid
 public function parseResponse(Postman_Google_Http_Request $response)
 {
     $contentType = $response->getResponseHeader('content-type');
     $contentType = explode(';', $contentType);
     $boundary = false;
     foreach ($contentType as $part) {
         $part = explode('=', $part, 2);
         if (isset($part[0]) && 'boundary' == trim($part[0])) {
             $boundary = $part[1];
         }
     }
     $body = $response->getResponseBody();
     if ($body) {
         $body = str_replace("--{$boundary}--", "--{$boundary}", $body);
         $parts = explode("--{$boundary}", $body);
         $responses = array();
         foreach ($parts as $part) {
             $part = trim($part);
             if (!empty($part)) {
                 list($metaHeaders, $part) = explode("\r\n\r\n", $part, 2);
                 $metaHeaders = $this->client->getIo()->getHttpResponseHeaders($metaHeaders);
                 $status = substr($part, 0, strpos($part, "\n"));
                 $status = explode(" ", $status);
                 $status = $status[1];
                 list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false);
                 $response = new Postman_Google_Http_Request("");
                 $response->setResponseHttpCode($status);
                 $response->setResponseHeaders($partHeaders);
                 $response->setResponseBody($partBody);
                 // Need content id.
                 $key = $metaHeaders['content-id'];
                 if (isset($this->expected_classes[$key]) && strlen($this->expected_classes[$key]) > 0) {
                     $class = $this->expected_classes[$key];
                     $response->setExpectedClass($class);
                 }
                 try {
                     $response = Postman_Google_Http_REST::decodeHttpResponse($response, $this->client);
                     $responses[$key] = $response;
                 } catch (Postman_Google_Service_Exception $e) {
                     // Store the exception as the response, so successful responses
                     // can be processed.
                     $responses[$key] = $e;
                 }
             }
         }
         return $responses;
     }
     return null;
 }
コード例 #2
0
 private function getResumeUri()
 {
     $result = null;
     $body = $this->request->getPostBody();
     if ($body) {
         $headers = array('content-type' => 'application/json; charset=UTF-8', 'content-length' => Postman_Google_Utils::getStrLen($body), 'x-upload-content-type' => $this->mimeType, 'x-upload-content-length' => $this->size, 'expect' => '');
         $this->request->setRequestHeaders($headers);
     }
     $response = $this->client->getIo()->makeRequest($this->request);
     $location = $response->getResponseHeader('location');
     $code = $response->getResponseHttpCode();
     if (200 == $code && true == $location) {
         return $location;
     }
     $message = $code;
     $body = @json_decode($response->getResponseBody());
     if (!empty($body->error->errors)) {
         $message .= ': ';
         foreach ($body->error->errors as $error) {
             $message .= "{$error->domain}, {$error->message};";
         }
         $message = rtrim($message, ';');
     }
     $error = "Failed to start the resumable upload (HTTP {$message})";
     $this->client->getLogger()->error($error);
     throw new Postman_Google_Exception($error);
 }
コード例 #3
0
ファイル: IoTest.php プロジェクト: rapier83/isaebooks
 public function testExecutorSelection()
 {
     $default = function_exists('curl_version') ? 'Postman_Google_IO_Curl' : 'Postman_Google_IO_Stream';
     $client = $this->getClient();
     $this->assertInstanceOf($default, $client->getIo());
     $config = new Postman_Google_Config();
     $config->setIoClass('Postman_Google_IO_Stream');
     $client = new Postman_Google_Client($config);
     $this->assertInstanceOf('Postman_Google_IO_Stream', $client->getIo());
 }
コード例 #4
0
ファイル: ApiClientTest.php プロジェクト: rapier83/isaebooks
 /**
  * @requires extension Memcached
  */
 public function testAppEngineAutoConfig()
 {
     $_SERVER['SERVER_SOFTWARE'] = 'Google App Engine';
     $client = new Postman_Google_Client();
     $this->assertInstanceOf('Postman_Google_Cache_Memcache', $client->getCache());
     $this->assertInstanceOf('Postman_Google_Io_Stream', $client->getIo());
     unset($_SERVER['SERVER_SOFTWARE']);
 }
コード例 #5
0
ファイル: REST.php プロジェクト: DanMaiman/Awfulkid
 /**
  * Executes a Postman_Google_Http_Request
  *
  * @param Postman_Google_Client $client
  * @param Postman_Google_Http_Request $req
  * @return array decoded result
  * @throws Postman_Google_Service_Exception on server side error (ie: not authenticated,
  *  invalid or malformed post body, invalid url)
  */
 public static function execute(Postman_Google_Client $client, Postman_Google_Http_Request $req)
 {
     $httpRequest = $client->getIo()->makeRequest($req);
     $httpRequest->setExpectedClass($req->getExpectedClass());
     return self::decodeHttpResponse($httpRequest, $client);
 }