moving $host back to ApiClient and making ApiClient setters fluent

This commit is contained in:
nmonterroso 2015-06-22 08:36:49 -07:00
parent 99e963709b
commit 04be474f56
2 changed files with 29 additions and 22 deletions

View File

@ -31,6 +31,11 @@ class ApiClient {
protected $defaultHeaders = array(); protected $defaultHeaders = array();
/**
* The host (from basePath)
*/
protected $host = '{{basePath}}';
/* /*
* @var string timeout (second) of the HTTP request, by default set to 0, no timeout * @var string timeout (second) of the HTTP request, by default set to 0, no timeout
*/ */
@ -49,7 +54,11 @@ class ApiClient {
/** /**
* @param ApiConfiguration $config config for this ApiClient * @param ApiConfiguration $config config for this ApiClient
*/ */
function __construct(ApiConfiguration $config = null) { function __construct($host = null, ApiConfiguration $config = null) {
if ($host != null) {
$this->host = $host;
}
if ($config == null) { if ($config == null) {
$config = ApiConfiguration::getDefaultConfiguration(); $config = ApiConfiguration::getDefaultConfiguration();
} }
@ -69,6 +78,7 @@ class ApiClient {
} }
$this->defaultHeaders[$headerName] = $headerValue; $this->defaultHeaders[$headerName] = $headerValue;
return $this;
} }
/** /**
@ -80,6 +90,22 @@ class ApiClient {
return $this->defaultHeaders; return $this->defaultHeaders;
} }
/**
* @param string $host
* @return ApiConfiguration
*/
public function setHost($host) {
$this->host = $host;
return $this;
}
/**
* @return string
*/
public function getHost() {
return $this->host;
}
/** /**
* delete the default header based on header name * delete the default header based on header name
* *
@ -99,6 +125,7 @@ class ApiClient {
throw new \InvalidArgumentException('User-agent must be a string.'); throw new \InvalidArgumentException('User-agent must be a string.');
$this->userAgent = $userAgent; $this->userAgent = $userAgent;
return $this;
} }
/** /**
@ -120,6 +147,7 @@ class ApiClient {
throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.');
$this->curlTimeout = $seconds; $this->curlTimeout = $seconds;
return $this;
} }
/** /**

View File

@ -21,11 +21,6 @@ class ApiConfiguration {
private static $defaultConfiguration = null; private static $defaultConfiguration = null;
/**
* The host (from basePath)
*/
protected $host = '{{basePath}}';
/** /**
* Associate array to store API key(s) * Associate array to store API key(s)
*/ */
@ -56,22 +51,6 @@ class ApiConfiguration {
*/ */
protected $debugFile = 'php://output'; protected $debugFile = 'php://output';
/**
* @param string $host
* @return ApiConfiguration
*/
public function setHost($host) {
$this->host = $host;
return $this;
}
/**
* @return string
*/
public function getHost() {
return $this->host;
}
/** /**
* @param string $key * @param string $key
* @param string $value * @param string $value