Example #1
0
 /**
  * Executes a http request.
  *
  * @param Request $request The http request.
  *
  * @return Response The http response.
  */
 public function execute(Request $request)
 {
     $method = $request->getMethod();
     $endpoint = $request->getEndpoint();
     $params = $request->getParams();
     $headers = $request->getHeaders();
     try {
         if ($method === 'GET') {
             $buzzResponse = $this->client->call($endpoint . '?' . http_build_query($params), $method, $headers, array());
         } else {
             $buzzRequest = new FormRequest();
             $buzzRequest->fromUrl($endpoint);
             $buzzRequest->setMethod($method);
             $buzzRequest->setHeaders($headers);
             foreach ($params as $key => $value) {
                 if ($value instanceof Image) {
                     $value = new FormUpload($value->getData());
                 }
                 $buzzRequest->setField($key, $value);
             }
             $buzzResponse = new BuzzResponse();
             $this->client->send($buzzRequest, $buzzResponse);
         }
     } catch (RequestException $e) {
         throw new Exception($e->getMessage());
     }
     return static::convertResponse($request, $buzzResponse);
 }
Example #2
0
 /**
  * Get the caching file for a request.
  *
  * @param Request $request The request.
  *
  * @return string The path to the caching file.
  */
 private function getFilePath(Request $request)
 {
     $endpoint = $request->getEndpoint();
     $path = static::getPath($endpoint);
     $method = strtolower($request->getMethod());
     $params = static::paramsToString($request->getParams());
     $file = $method . $path . $params;
     $chars = array('/', ':', '.', ',', ' ');
     $file = static::str_replace($chars, '_', $file);
     return sprintf('%s/%s.json', $this->cacheDir, $file);
 }
Example #3
0
 /**
  * Fetches multiple pins and processes the response.
  *
  * @param Request $request
  * @param $fields array The fields to require.
  *
  * @throws RateLimitedReached
  *
  * @return Response The response.
  */
 private function fetchMultiplePins(Request $request, array $fields = null)
 {
     $fields = $fields ? $fields : Pin::fields();
     $request->setFields($fields);
     return $this->execute($request, function (Response $response) {
         $mapper = new Mapper(new Pin());
         return $mapper->toList($response);
     });
 }
Example #4
0
 /**
  * Executes a http request.
  *
  * @param Request $request The http request.
  *
  * @return Http\Response The http response.
  */
 public function execute(Request $request)
 {
     $headers = $request->getHeaders();
     $headers['Authorization'] = sprintf('BEARER %s', $this->accessToken);
     $authenticatedRequest = new Request($request->getMethod(), $this->getBaseUriWithVersion() . $request->getEndpoint(), $request->getParams(), $headers);
     return $this->http->execute($authenticatedRequest);
 }