Skip to content

Commit

Permalink
Issue #18
Browse files Browse the repository at this point in the history
  • Loading branch information
thewulf7 committed May 29, 2017
1 parent 769b3f2 commit d3626e6
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 185 deletions.
47 changes: 25 additions & 22 deletions src/thewulf7/travelPayouts/components/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,55 +84,58 @@ public function execute($url, array $options, $type = 'GET', $replaceOptions = t
if ($statusCode !== 200)
{
$strBody = json_decode((string)$body, true);
throw new \RuntimeException("{$statusCode}:{$strBody['message']}");

$message = isset($strBody['message']) ? $strBody['message'] : 'unknown';

throw new \RuntimeException("{$statusCode}:{$message}");
}

return $this->makeApiResponse($body);
}

/**
* @param $jsonString
*
* @return mixed
* @throws \RuntimeException
*/
private function makeApiResponse($jsonString)
public function getApiVersion()
{
$data = json_decode($jsonString, true);
if (!$data)
{
throw new \RuntimeException("Unable to decode json response: $jsonString");
}

return $data;
return $this->_apiVersion;
}

/**
* @return mixed
* @param mixed $apiVersion
*
* @return $this
*/
public function getClient()
public function setApiVersion($apiVersion)
{
return $this->_client;
$this->_apiVersion = $apiVersion;

return $this;
}

/**
* @return mixed
*/
public function getApiVersion()
public function getClient()
{
return $this->_apiVersion;
return $this->_client;
}

/**
* @param mixed $apiVersion
* @param $jsonString
*
* @return $this
* @return mixed
* @throws \RuntimeException
*/
public function setApiVersion($apiVersion)
private function makeApiResponse($jsonString)
{
$this->_apiVersion = $apiVersion;
$data = json_decode($jsonString, true);
if (!$data)
{
throw new \RuntimeException("Unable to decode json response: $jsonString");
}

return $this;
return $data;
}

/**
Expand Down
Loading

0 comments on commit d3626e6

Please sign in to comment.