本文整理汇总了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);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例6: testNotJson404Error
/**
* @expectedException Google_Service_Exception
*/
public function testNotJson404Error()
{
$stream = Stream::factory('Not Found');
$response = new Response(404, array(), $stream);
$this->rest->decodeHttpResponse($response);
}
示例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;
}
示例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);
}
示例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);
}
}