From a636e2ef007b56a2d8f2e19b23cc96724c622988 Mon Sep 17 00:00:00 2001 From: Timo Janssen Date: Wed, 1 May 2019 09:17:01 +0200 Subject: [PATCH] fixed draft endpoint response model --- src/Wuunder/Api/DraftsApiResponse.php | 10 ---------- src/Wuunder/Api/Endpoints/Drafts.php | 13 ++++++++----- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Wuunder/Api/DraftsApiResponse.php b/src/Wuunder/Api/DraftsApiResponse.php index 1e2f8c1..416ed48 100644 --- a/src/Wuunder/Api/DraftsApiResponse.php +++ b/src/Wuunder/Api/DraftsApiResponse.php @@ -8,14 +8,4 @@ public function __construct($header, $body, $error) { parent::__construct($header, $body, $error); } - - /** - * Returns booking url - * - * @return mixed - */ - public function getBookingUrl() - { - return $this->getBody(); - } } \ No newline at end of file diff --git a/src/Wuunder/Api/Endpoints/Drafts.php b/src/Wuunder/Api/Endpoints/Drafts.php index 6e508c7..d0c1baa 100644 --- a/src/Wuunder/Api/Endpoints/Drafts.php +++ b/src/Wuunder/Api/Endpoints/Drafts.php @@ -55,10 +55,10 @@ public function getConfig() */ public function fire() { - $bookingRequest = new PostRequest($this->apiEnvironment->getStageBaseUrl() . "/drafts", + $draftRequest = new PostRequest($this->apiEnvironment->getStageBaseUrl() . "/drafts", $this->apiKey->getApiKey(), json_encode($this->config->getDrafts())); try { - $bookingRequest->send(); + $draftRequest->send(); } catch(Exception $e) { $this->logger->log($e); } @@ -67,10 +67,13 @@ public function fire() $header = null; $error = null; - if (isset($bookingRequest->getResponseHeaders()["location"])) { - $header = $bookingRequest->getResponseHeaders(); + if (isset($draftRequest->getResponseHeaders()["http_code"]) + && strpos($draftRequest->getResponseHeaders()["http_code"], "200 OK") !== false + ) { + $header = $draftRequest->getResponseHeaders(); + $body = $draftRequest->getBody(); } else { - $error = $bookingRequest->getResponse(); + $error = $draftRequest->getResponse(); } $this->draftsResponse = new DraftsApiResponse($header, $body, $error);