From c52de53611289a322b6173770316589c4e784455 Mon Sep 17 00:00:00 2001 From: natedolz Date: Mon, 26 Apr 2021 10:59:30 -0500 Subject: [PATCH] add optional route support --- src/SpurClientBase.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/SpurClientBase.php b/src/SpurClientBase.php index 4fa4f63..d2435d5 100644 --- a/src/SpurClientBase.php +++ b/src/SpurClientBase.php @@ -8,12 +8,18 @@ abstract class SpurClientBase { protected $baseUrl; + protected $optional = ""; protected $authToken; protected $timeOffset; public function __construct($baseUrl, $authToken, $timeOffset = null) { $this->baseUrl = $baseUrl; + $optional_string = str_replace("http://", "", $baseUrl); + $optional_string = str_replace("https://", "", $optional_string); + $this->optional = strpos($optional_string, '/') === false + ? "" + : substr($optional_string, strpos($optional_string, '/')) + "/"; $this->authToken = $authToken; $this->timeOffset = $timeOffset; } @@ -56,7 +62,7 @@ public function delete($url, $params = []) public function send($method, $url, $options) { try { - return json_decode($this->getClient()->request($method, $url, $options)->getBody()->getContents(), true); + return json_decode($this->getClient()->request($method, $this->optional + $url, $options)->getBody()->getContents(), true); } catch (ClientException $e) { if ($e->getResponse()->getStatusCode() === 422) { $data = json_decode($e->getResponse()->getBody(), true);