当前位置: 首页>>代码示例>>PHP>>正文


PHP Google_Http_REST::decodeHttpResponse方法代码示例

本文整理汇总了PHP中Google_Http_REST::decodeHttpResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Http_REST::decodeHttpResponse方法的具体用法?PHP Google_Http_REST::decodeHttpResponse怎么用?PHP Google_Http_REST::decodeHttpResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Google_Http_REST的用法示例。


在下文中一共展示了Google_Http_REST::decodeHttpResponse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDecodeEmptyResponse

 public function testDecodeEmptyResponse()
 {
     $url = 'http://localhost';
     $response = new Google_Http_Request($url, 'GET', array());
     $response->setResponseBody('{}');
     $response->setResponseHttpCode(200);
     $decoded = $this->rest->decodeHttpResponse($response);
     $this->assertEquals(array(), $decoded);
 }
开发者ID:rickb838,项目名称:scalr,代码行数:9,代码来源:RestTest.php

示例2: tesProperErrorFormatting

 /**
  * @expectedException Google_Service_Exception
  */
 public function tesProperErrorFormatting()
 {
     $stream = Stream::factory('{
       error: {
        errors: [
         {
          "domain": "global",
          "reason": "authError",
          "message": "Invalid Credentials",
          "locationType": "header",
          "location": "Authorization",
         }
        ],
       "code": 401,
       "message": "Invalid Credentials"
     }');
     $response = new Response(401, array(), $stream);
     $this->rest->decodeHttpResponse($response);
 }
开发者ID:rahul9878,项目名称:google-api-php-client,代码行数:22,代码来源:RESTTest.php

示例3: nextChunk

 /**
  * 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 Google_Http_Request($this->resumeUri, 'PUT', $headers, $chunk);
     if ($this->client->getClassConfig("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 Google_Http_REST::decodeHttpResponse($response);
     }
 }
开发者ID:omodev,项目名称:hooks,代码行数:40,代码来源:MediaFileUpload.php

示例4: parseResponse

 public function parseResponse(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 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 = Google_Http_REST::decodeHttpResponse($response);
                     $responses[$key] = $response;
                 } catch (Google_Service_Exception $e) {
                     // Store the exception as the response, so succesful responses
                     // can be processed.
                     $responses[$key] = $e;
                 }
             }
         }
         return $responses;
     }
     return null;
 }
开发者ID:Erginus,项目名称:demo,代码行数:49,代码来源:Batch.php

示例5: testNotJson404Error

 /**
  * @expectedException Google_Service_Exception
  */
 public function testNotJson404Error()
 {
     $stream = Psr7\stream_for('Not Found');
     $response = new Response(404, array(), $stream);
     $this->rest->decodeHttpResponse($response, $this->request);
 }
开发者ID:knedle,项目名称:twitter-nette-skeleton,代码行数:9,代码来源:RESTTest.php

示例6: testNotJson404Error

 /**
  * @expectedException Google_Service_Exception
  */
 public function testNotJson404Error()
 {
     $stream = Stream::factory('Not Found');
     $response = new Response(404, array(), $stream);
     $this->rest->decodeHttpResponse($response);
 }
开发者ID:OlivierBarbier,项目名称:google-api-php-client,代码行数:9,代码来源:RESTTest.php

示例7: parseResponse

 public function parseResponse(ResponseInterface $response, $classes = array())
 {
     $contentType = $response->getHeaderLine('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 = (string) $response->getBody();
     if (!empty($body)) {
         $body = str_replace("--{$boundary}--", "--{$boundary}", $body);
         $parts = explode("--{$boundary}", $body);
         $responses = array();
         $requests = array_values($this->requests);
         foreach ($parts as $i => $part) {
             $part = trim($part);
             if (!empty($part)) {
                 list($rawHeaders, $part) = explode("\r\n\r\n", $part, 2);
                 $headers = $this->parseRawHeaders($rawHeaders);
                 $status = substr($part, 0, strpos($part, "\n"));
                 $status = explode(" ", $status);
                 $status = $status[1];
                 list($partHeaders, $partBody) = $this->parseHttpResponse($part, false);
                 $response = new Response($status, $partHeaders, Psr7\stream_for($partBody));
                 // Need content id.
                 $key = $headers['content-id'];
                 $class = '';
                 if (!empty($this->expected_classes[$key])) {
                     $class = $this->expected_classes[$key];
                 }
                 try {
                     $response = Google_Http_REST::decodeHttpResponse($response, $requests[$i - 1]);
                 } catch (Google_Service_Exception $e) {
                     // Store the exception as the response, so successful responses
                     // can be processed.
                     $response = $e;
                 }
                 $responses[$key] = $response;
             }
         }
         return $responses;
     }
     return null;
 }
开发者ID:andytan2624,项目名称:andytan.net,代码行数:47,代码来源:Batch.php

示例8: makePutRequest

 /**
  * Sends a PUT-Request to google drive and parses the response,
  * setting the appropiate variables from the response()
  *
  * @param Google_Http_Request $httpRequest the Reuqest which will be send
  *
  * @return false|mixed false when the upload is unfinished or the decoded http response
  *
  */
 private function makePutRequest(RequestInterface $request)
 {
     $response = $this->client->execute($request);
     $this->httpResultCode = $response->getStatusCode();
     if (308 == $this->httpResultCode) {
         // Track the amount uploaded.
         $range = explode('-', $response->getHeaderLine('range'));
         $this->progress = $range[1] + 1;
         // Allow for changing upload URLs.
         $location = $response->getHeaderLine('location');
         if ($location) {
             $this->resumeUri = $location;
         }
         // No problems, but upload not complete.
         return false;
     }
     return Google_Http_REST::decodeHttpResponse($response, $this->request);
 }
开发者ID:andytan2624,项目名称:andytan.net,代码行数:27,代码来源:MediaFileUpload.php

示例9: makePutRequest

 /**
  * Sends a PUT-Request to google drive and parses the response,
  * setting the appropiate variables from the response()
  *
  * @param Google_Http_Request $httpRequest the Reuqest which will be send
  *
  * @return false|mixed false when the upload is unfinished or the decoded http response
  *
  */
 private function makePutRequest(Google_Http_Request $httpRequest)
 {
     if ($this->client->getClassConfig("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 Google_Http_REST::decodeHttpResponse($response, $this->client);
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:35,代码来源:MediaFileUpload.php


注:本文中的Google_Http_REST::decodeHttpResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。