Skip to content
This repository has been archived by the owner on May 28, 2021. It is now read-only.

Commit

Permalink
Updating docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TZK- committed Apr 8, 2017
1 parent c9f2df7 commit 4f2ad8e
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions src/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ abstract class RestClient
* RestClient constructor.
*
* @param $baseUrl the API base URL
* @param $token the public API token
* @param $language the language to be used when calling the API
*/
public function __construct($baseUrl, $token, $language = 'en')
public function __construct($baseUrl)
{
$this->baseUrl = $baseUrl;
$this->curl = new Curl();
$this->curl->setHeader('Content-Type', 'application/json');
$this->curl->setHeader('Accept-Language', $language);
$this->curl->setUserAgent(self::USER_AGENT);
$this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, true);
}
Expand All @@ -43,36 +40,25 @@ public function __construct($baseUrl, $token, $language = 'en')
* @param string $url the url used to send the request
* @param array $data the data to send with the request
*
* @throws \Exception
* @throws TaigaException
*
* @return array|\StdClass
* @return array|StdClass
*/
public function request($method, $url, array $data = [])
{
$this->curl->{strtolower($method)}($this->baseUrl.$url, $data);
if ($this->curl->error) {
throw new TaigaException(self::getErrorMessage($this->curl));
throw new TaigaException(static::getErrorMessage($this->curl));
}
return $this->curl->response;
}

/**
* Generate a string in case of request errors.
*
* @param Curl $curl the curl request
*
* @return string
*/
protected static function getErrorMessage(Curl $curl)
{
return 'Error '.$curl->errorCode.' - '.$curl->effectiveUrl.' : '.$curl->errorMessage;
}

/**
* @return Curl
*/
public function getCurl()
protected static function getErrorMessage()
{
return $this->curl;
return sprintf('Error %s - %s: %s',
$this->curl->errorCode,
$this->curl->effectiveUrl,
$this->curl->errorMessage
);
}
}

0 comments on commit 4f2ad8e

Please sign in to comment.