Exemple #1
0
 protected function _buildData(IApiRequestDetail $request)
 {
     if ($request->getRequestBody()) {
         return $request->getRequestBody();
     } else {
         return $request->getPostFields();
     }
 }
Exemple #2
0
 /**
  * @inheritdoc
  */
 public function getRawResult()
 {
     if ($this->_result === null) {
         if ($this->hasConnection()) {
             if ($this->_requestDetail->requiresAuth()) {
                 $this->_getConnection()->setToken($this->_endpoint->getToken());
                 try {
                     $this->_result = false;
                     $result = $this->_getConnection()->load($this);
                     if ($result->getRawResult()->getStatusCode() == 403) {
                         $msg = $result->getRawResult()->getStatusMessage();
                         $this->_result = new ForbiddenException($msg == 'OK' ? 'Invalid token' : $msg);
                         throw $this->_result;
                     }
                 } catch (\Exception $e) {
                     if ($e->getCode() == 403 && stristr($e->getMessage(), 'token')) {
                         $result = $this->_getConnection()->load($this);
                     } else {
                         $this->_result = ApiException::build($e->getCode(), $e->getMessage(), $e);
                         throw $this->_result;
                     }
                 }
             } else {
                 $result = $this->_getConnection()->load($this);
             }
             $this->setRawResult($result->getRawResult());
         } else {
             throw new ClientApiException("No API Connection Available", 428);
         }
     }
     if ($this->_result instanceof \Exception) {
         throw $this->_result;
     }
     if ($this->_result instanceof IApiResult) {
         if ($this->shouldThrowExceptions()) {
             if ($this->_result->getStatusCode() !== 200) {
                 throw ApiException::build($this->_result->getStatusCode(), $this->_result->getStatusMessage());
             }
         }
         return $this->_result;
     }
     throw new ClientApiException("Invalid API Result Stored", 418);
 }