/**
  * A factory for creating the appropriate exception based on the response from PlayerLync API.
  *
  * @param PlayerLyncResponse $response The response that threw the exception.
  *
  * @return PlayerLyncResponseException
  */
 public static function create(PlayerLyncResponse $response)
 {
     $data = $response->getDecodedBody();
     //        //oauth error is not standard API format, so check this first
     //        $isAuthError = isset($data['error']) && isset($data['error_description']);
     //
     //        if ($isAuthError)
     //        {
     //            $code = 148002;
     //            return new static($response, new PlayerLyncAuthenticationException($data['error_description'], $code));
     //        }
     if ($data['errors']['code'] >= 148000 && $data['errors']['code'] <= 148010) {
         return new static($response, new PlayerLyncAuthenticationException($data['errors']['message'], $data['errors']['code']));
     } else {
         return new static($response, new PlayerLyncSDKException($data['errors']['message'], $data['errors']['code']));
     }
 }
 /**
  * Makes the request to API and returns the result.
  *
  * @param PlayerLyncRequest $request
  *
  * @return PlayerLyncResponse
  *
  * @throws PlayerLyncSDKException
  */
 public function sendRequest(PlayerLyncRequest $request)
 {
     if (get_class($request) === 'PlayerLyncRequest') {
         $request->validateAccessToken();
     }
     list($url, $method, $headers, $body) = $this->prepareRequestMessage($request);
     // Since file uploads can take a while, we need to give more time for uploads
     $timeOut = static::DEFAULT_REQUEST_TIMEOUT;
     if ($request->containsFileUploads()) {
         $timeOut = static::DEFAULT_FILE_UPLOAD_REQUEST_TIMEOUT;
     } elseif ($request->containsVideoUploads()) {
         $timeOut = static::DEFAULT_VIDEO_UPLOAD_REQUEST_TIMEOUT;
     }
     // Should throw `PlayerLyncSDKException` exception on HTTP client error.
     // Don't catch to allow it to bubble up.
     $rawResponse = $this->httpClientHandler->send($url, $method, $body, $headers, $timeOut);
     static::$requestCount++;
     $returnResponse = new PlayerLyncResponse($request, $rawResponse->getBody(), $rawResponse->getHttpResponseCode(), $rawResponse->getHeaders());
     if ($returnResponse->isError()) {
         throw $returnResponse->getThrownException();
     }
     return $returnResponse;
 }