public function execute()
 {
     $body = '';
     /** @var displetretsidx_Google_HttpRequest $req */
     foreach ($this->requests as $key => $req) {
         $body .= "--{$this->boundary}\n";
         $body .= $req->toBatchString($key) . "\n";
     }
     $body = rtrim($body);
     $body .= "\n--{$this->boundary}--";
     global $displetretsidx_apiConfig;
     $url = $displetretsidx_apiConfig['basePath'] . '/batch';
     $httpRequest = new displetretsidx_Google_HttpRequest($url, 'POST');
     $httpRequest->setRequestHeaders(array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary));
     $httpRequest->setPostBody($body);
     $response = displetretsidx_Google_Client::$io->makeRequest($httpRequest);
     $response = $this->parseResponse($response);
     return $response;
 }
示例#2
0
 /**
  * @visible for testing
  * Process an http request that contains an enclosed entity.
  * @param displetretsidx_Google_HttpRequest $request
  * @return displetretsidx_Google_HttpRequest Processed request with the enclosed entity.
  */
 public function processEntityRequest(displetretsidx_Google_HttpRequest $request)
 {
     $postBody = $request->getPostBody();
     $contentType = $request->getRequestHeader("content-type");
     // Set the default content-type as application/x-www-form-urlencoded.
     if (false == $contentType) {
         $contentType = self::FORM_URLENCODED;
         $request->setRequestHeaders(array('content-type' => $contentType));
     }
     // Force the payload to match the content-type asserted in the header.
     if ($contentType == self::FORM_URLENCODED && is_array($postBody)) {
         $postBody = http_build_query($postBody, '', '&');
         $request->setPostBody($postBody);
     }
     // Make sure the content-length header is set.
     if (!$postBody || is_string($postBody)) {
         $postsLength = strlen($postBody);
         $request->setRequestHeaders(array('content-length' => $postsLength));
     }
     return $request;
 }