forked from loafle/openapi-generator-original
Merge pull request #400 from FindTheBest/master
Fixing curl $postData for php bindings
This commit is contained in:
commit
f914f26f3b
@ -28,6 +28,8 @@ class APIClient {
|
||||
public static $PUT = "PUT";
|
||||
public static $DELETE = "DELETE";
|
||||
|
||||
private $curl_timout = 5;
|
||||
|
||||
/**
|
||||
* @param string $apiKey your API key
|
||||
* @param string $apiServer the address of the API server
|
||||
@ -37,6 +39,16 @@ class APIClient {
|
||||
$this->apiServer = $apiServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
|
||||
*/
|
||||
public function setTimeout($seconds) {
|
||||
if (!is_numeric($seconds)) {
|
||||
throw new Exception('Timeout variable must be numeric.');
|
||||
}
|
||||
$this->curl_timout = $seconds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $resourcePath path to method endpoint
|
||||
@ -72,7 +84,9 @@ class APIClient {
|
||||
$url = $this->apiServer . $resourcePath;
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
|
||||
if ($this->curl_timout) {
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timout);
|
||||
}
|
||||
// return the result on success, rather than just TRUE
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
|
@ -77,6 +77,8 @@ class {{classname}} {
|
||||
{{/formParams}}
|
||||
if (empty($body)) {
|
||||
$body = null;
|
||||
} else if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) {
|
||||
$body = http_build_query($body);
|
||||
}
|
||||
|
||||
// Make the API Call
|
||||
|
Loading…
x
Reference in New Issue
Block a user