public function __construct(ApiUri $baseUri, BookingList $bookDataRQ)
 {
     parent::__construct($baseUri, self::BOOKING);
     $this->request->setMethod(Request::METHOD_GET);
     $this->setDataRequest($bookDataRQ);
 }
 public function __construct(ApiUri $baseUri, $bookingId)
 {
     parent::__construct($baseUri, self::BOOKING);
     $this->request->setMethod(Request::METHOD_DELETE);
     $this->baseUri->setPath($baseUri->getPath() . "/" . self::BOOKING . "/{$bookingId}");
 }
Esempio n. 3
0
 public function __construct(ApiUri $baseUri)
 {
     parent::__construct($baseUri, self::STATUS);
     $this->request->setMethod(Request::METHOD_GET);
 }
 public function __construct(ApiUri $baseUri, CheckRate $checkDataRQ)
 {
     parent::__construct($baseUri, self::CHECK_AVAIL);
     $this->request->setMethod(Request::METHOD_POST);
     $this->setDataRequest($checkDataRQ);
 }
 /**
  * Generic API Call, this is a internal used method for sending all requests to webservice and parse
  * JSON response and transforms to PHP-Array object.
  * @param ApiRequest $request API Abstract request helper for construct request
  * @return array Response data into PHP Array structure
  * @throws HotelSDKException Calling exception, can capture remote server auditdata if exists.
  */
 private function callApi(ApiRequest $request)
 {
     try {
         $signature = hash("sha256", $this->apiKey . $this->sharedSecret . time());
         $this->lastRequest = $request->prepare($this->apiKey, $signature);
         $response = $this->httpClient->send($this->lastRequest);
     } catch (\Exception $e) {
         throw new HotelSDKException("Error accessing API: " . $e->getMessage());
     }
     if ($response->getStatusCode() !== 200) {
         $auditData = null;
         $message = '';
         $errorResponse = null;
         if ($response->getBody() !== null) {
             try {
                 $errorResponse = \Zend\Json\Json::decode($response->getBody(), \Zend\Json\Json::TYPE_ARRAY);
                 $auditData = new AuditData($errorResponse["auditData"]);
                 $message = $errorResponse["error"]["code"] . ' ' . $errorResponse["error"]["message"];
             } catch (\Exception $e) {
                 throw new HotelSDKException($response->getReasonPhrase() . ': ' . $response->getBody());
             }
         }
         throw new HotelSDKException($response->getReasonPhrase() . ': ' . $message, $auditData);
     }
     return \Zend\Json\Json::decode(mb_convert_encoding($response->getBody(), 'UTF-8'), \Zend\Json\Json::TYPE_ARRAY);
 }
 public function __construct(ApiUri $baseUri, Availability $availDataRQ)
 {
     parent::__construct($baseUri, self::AVAILABILITY);
     $this->request->setMethod(Request::METHOD_POST);
     $this->setDataRequest($availDataRQ);
 }
 /**
  * @param ApiRequest $request API Abstract request helper for contruct request
  * @return mixed Response data into array format
  * @throws HotelSDKException
  * @throws \Exception
  */
 private function callApi(ApiRequest $request)
 {
     try {
         $this->lastRequest = $request->prepare($this->apiKey, $this->signature);
         $response = $this->httpClient->send($this->lastRequest);
     } catch (\Exception $e) {
         throw new HotelSDKException("Error accessing API: " . $e->getMessage());
     }
     if ($response->getStatusCode() === 403) {
         throw new \Exception("Not authorized, review your api-key and secret!");
     }
     if ($response->getStatusCode() !== 200) {
         $auditData = null;
         $message = "";
         if ($response->getBody() !== null) {
             $errorResponse = \Zend\Json\Json::decode($response->getBody(), \Zend\Json\Json::TYPE_ARRAY);
             $auditData = new AuditData($errorResponse["auditData"]);
             $message = $errorResponse["error"]["message"];
         }
         throw new HotelSDKException($response->getReasonPhrase() . ". " . $message, $auditData);
     }
     return \Zend\Json\Json::decode($response->getBody(), \Zend\Json\Json::TYPE_ARRAY);
 }