update php to support user agent

This commit is contained in:
William Cheng 2015-03-15 16:33:57 +08:00
parent ad7a5967ff
commit b8166f283a
2 changed files with 38 additions and 2 deletions

View File

@ -48,6 +48,18 @@ class APIClient {
$this->headerValue = $headerValue;
}
/**
* Set the user agent of the API client
*
* @param string $user_agent The user agent of the API client
*/
public function setUserAgent($user_agent) {
if (!is_string($user_agent)) {
throw new Exception('User-agent must be a string.');
}
$this->user_agent= $user_agent;
}
/**
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
*/
@ -58,7 +70,6 @@ class APIClient {
$this->curl_timout = $seconds;
}
/**
* @param string $resourcePath path to method endpoint
* @param string $method method to call
@ -121,6 +132,13 @@ class APIClient {
}
curl_setopt($curl, CURLOPT_URL, $url);
// Set user agent
if ($this->user_agent) {
curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
} else { // use PHP-Swagger as the default user agent
curl_setopt($curl, CURLOPT_USERAGENT, 'PHP-Swagger');
}
// Make the request
$response = curl_exec($curl);
$response_info = curl_getinfo($curl);

View File

@ -48,6 +48,18 @@ class APIClient {
$this->headerValue = $headerValue;
}
/**
* Set the user agent of the API client
*
* @param string $user_agent The user agent of the API client
*/
public function setUserAgent($user_agent) {
if (!is_string($user_agent)) {
throw new Exception('User-agent must be a string.');
}
$this->user_agent= $user_agent;
}
/**
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
*/
@ -58,7 +70,6 @@ class APIClient {
$this->curl_timout = $seconds;
}
/**
* @param string $resourcePath path to method endpoint
* @param string $method method to call
@ -121,6 +132,13 @@ class APIClient {
}
curl_setopt($curl, CURLOPT_URL, $url);
// Set user agent
if ($this->user_agent) {
curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
} else { // use PHP-Swagger as the default user agent
curl_setopt($curl, CURLOPT_USERAGENT, 'PHP-Swagger');
}
// Make the request
$response = curl_exec($curl);
$response_info = curl_getinfo($curl);