public function preSend(RequestInterface $request)
 {
     $raw = $request->getContent();
     $url = new Url($this->apiBaseUrl . $request->getResource() . '.json');
     $request->setContent(json_encode($raw));
     $request->setHost($url->getHost());
     $request->setResource($url->getResource());
     $request->addHeader('Authorization: Bearer ' . $this->token);
     $request->addHeader('Accept: application/json');
     $request->addHeader('Content-Type: application/json');
 }
Beispiel #2
0
 protected function call()
 {
     $this->request->setMethod($this->call->getMethod());
     $this->request->setHost($this->call->getRequestPartBase());
     $this->request->setResource($this->call->getRequestPartUri());
     $this->request->setHeaders($this->headers->getHeaders());
     if ($this->call->getFormattedBody()) {
         $this->request->setContent($this->call->getFormattedBody());
     }
     $this->client->setIgnoreErrors(true);
     $this->client->setVerifyPeer($this->configuration->getVerifyPeer());
     $this->client->setMaxRedirects(0);
     $this->client->setTimeout(60);
     $this->client->send($this->request, $this->response);
 }
 /**
  * {@inheritDoc}
  */
 public function preSend(RequestInterface $request)
 {
     $request->setContent(preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $request->getContent()));
     $request->setResource(preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $request->getResource()));
 }
Beispiel #4
0
 /**
  * Applies the current URL to the supplied request.
  */
 public function applyToRequest(RequestInterface $request)
 {
     $request->setResource($this->getResource());
     $request->setHost($this->getHost());
 }
 public function preSend(RequestInterface $request)
 {
     if ($request::METHOD_GET !== $request->getMethod() || null === $this->page) {
         return;
     }
     $resource = $request->getResource();
     // Already configured, properly a secondary request
     if (false !== strpos($resource, 'pagelen=') xor false !== strpos($resource, 'limit=')) {
         return;
     }
     $urlComponents = parse_url($resource);
     if (!isset($urlComponents['query'])) {
         $urlComponents['query'] = [];
     } else {
         parse_str($urlComponents['query'], $query);
         $urlComponents['query'] = $query;
     }
     /*
      * Page limiting works as follow (only when perPage is higher then maximum):
      *
      * Divide perPage by two, so each page covers exactly two request.
      * We have a maximum of 100 (unless the limit is disabled) so no crazy math or truncating is required.
      */
     if ('2.0' === $this->client->getApiVersion()) {
         $urlComponents['query']['pagelen'] = null === $this->perPage ? 100 : $this->perPage;
         $urlComponents['query']['page'] = $this->page;
         // BitBucket please fix your API..
         // https://bitbucket.org/site/master/issue/9659/pagelen-sometimes-limited-to-100
         if (false !== strpos($urlComponents['path'], '/pullrequests') && $urlComponents['query']['pagelen'] > 50) {
             $urlComponents['query']['pagelen'] = $urlComponents['query']['pagelen'] / 2;
         }
     } elseif ('1.0' === $this->client->getApiVersion()) {
         if (null === $this->perPage) {
             // Use the maximum
             $limit = 50;
         } elseif ($this->perPage > 50) {
             // Divide perPage by two, so each page covers exactly two request (no crazy math or truncating).
             $limit = $this->perPage / 2;
         } else {
             $limit = $this->perPage;
         }
         $urlComponents['query']['limit'] = $limit;
         $urlComponents['query']['start'] = abs($this->page - 1) * $limit;
     }
     $request->setResource($urlComponents['path'] . '?' . http_build_query($urlComponents['query'], '', '&'));
 }