From bfc14938d0b37cc105230eb717e66e07ea852632 Mon Sep 17 00:00:00 2001 From: James Ebentier Date: Tue, 27 Jan 2015 13:16:20 -0800 Subject: [PATCH 1/3] Fixing curl $postData for php bindings --- src/main/resources/php/Swagger.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/php/Swagger.mustache b/src/main/resources/php/Swagger.mustache index efa2ecb0fde..785ad73d0ee 100644 --- a/src/main/resources/php/Swagger.mustache +++ b/src/main/resources/php/Swagger.mustache @@ -66,7 +66,7 @@ class APIClient { } if (is_object($postData) or is_array($postData)) { - $postData = json_encode($this->sanitizeForSerialization($postData)); + $postData = http_build_query($this->sanitizeForSerialization($postData)); } $url = $this->apiServer . $resourcePath; From 61ea9564f84a302f1783cddd06df54675de153e1 Mon Sep 17 00:00:00 2001 From: James Ebentier Date: Tue, 27 Jan 2015 13:48:59 -0800 Subject: [PATCH 2/3] building a fix for postData that will pass TravisCI build --- src/main/resources/php/Swagger.mustache | 2 +- src/main/resources/php/api.mustache | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/php/Swagger.mustache b/src/main/resources/php/Swagger.mustache index 785ad73d0ee..efa2ecb0fde 100644 --- a/src/main/resources/php/Swagger.mustache +++ b/src/main/resources/php/Swagger.mustache @@ -66,7 +66,7 @@ class APIClient { } if (is_object($postData) or is_array($postData)) { - $postData = http_build_query($this->sanitizeForSerialization($postData)); + $postData = json_encode($this->sanitizeForSerialization($postData)); } $url = $this->apiServer . $resourcePath; diff --git a/src/main/resources/php/api.mustache b/src/main/resources/php/api.mustache index 9d3e59fc63b..30d34f556e7 100644 --- a/src/main/resources/php/api.mustache +++ b/src/main/resources/php/api.mustache @@ -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 From 4a6e719d6a761068f5c5d9247655f21a6765bc6d Mon Sep 17 00:00:00 2001 From: James Ebentier Date: Wed, 28 Jan 2015 16:04:11 -0800 Subject: [PATCH 3/3] APIClient: making the cURL timeout able to be variably set for better dynamic api calls --- src/main/resources/php/Swagger.mustache | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/resources/php/Swagger.mustache b/src/main/resources/php/Swagger.mustache index efa2ecb0fde..962cc53455f 100644 --- a/src/main/resources/php/Swagger.mustache +++ b/src/main/resources/php/Swagger.mustache @@ -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);