Skip to content

Commit

Permalink
Merge pull request #45 from spurwork/add-optional-route
Browse files Browse the repository at this point in the history
add optional route support
  • Loading branch information
NateDolz authored Apr 26, 2021
2 parents eb2a01c + c52de53 commit f197888
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/SpurClientBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f197888

Please sign in to comment.