Esempio n. 1
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);
 }
Esempio n. 2
0
 /**
  * Make a response for a request.
  *
  * @param Request $request The request.
  *
  * @return Response The response.
  */
 private function makeResponse(Request $request)
 {
     if ($this->responseExists($request)) {
         return $this->getFromFile($request);
     }
     $response = $this->http->execute($request);
     if ($response->ok()) {
         $this->writeToFile($request, $response);
     } else {
         echo PHP_EOL . 'Request failed >>> ' . $request->getMethod() . ': ' . $request->getEndpoint() . PHP_EOL;
         print_r($response);
         echo PHP_EOL;
     }
     return $response;
 }