コード例 #1
0
 /**
  * Sends the request to Vend, and reutrns the decoded JSON data from the response.
  *
  * @param CurlHttpRequest $request The request to send.
  *
  * @param                 $requestType
  *
  * @return array
  * @throws EntityNotFoundException
  * @throws CommunicationException
  */
 protected function sendRequest(CurlHttpRequest $request, $requestType)
 {
     $result = $request->send();
     if (!$result->getError() && 404 == $result->getResponseCode()) {
         throw new EntityNotFoundException('The specified entity can not be found', 404, null, $result);
     }
     if (!$result->isRequestSuccessful()) {
         $exceptionClass = $this->getCommunicationExceptionClass();
         throw new $exceptionClass($requestType, $result, 0, null, $result);
     }
     $resultData = json_decode($result->getResponseBody(), true);
     if (empty($resultData)) {
         $exceptionClass = $this->getCommunicationExceptionClass();
         throw new $exceptionClass($requestType, $result, 0, null, $result);
     }
     return $resultData;
 }
コード例 #2
0
ファイル: OAuth.php プロジェクト: ShoppinPal/vend-php-api
 /**
  * Adds an authorisation header with the OAuth data to the request.
  *
  * @param CurlHttpRequest $request     The request
  * @param string          $tokenType   The token type.
  * @param string          $accessToken The access token.
  *
  * @return void
  */
 public function addAuthorisationHeaderToRequest(CurlHttpRequest $request, $tokenType, $accessToken)
 {
     $request->addHeader('Authorization: ' . $tokenType . ' ' . $accessToken);
 }