PHP: adding the ability to use multipart-form submissions as well as adding formParams to the api

This commit is contained in:
James Ebentier
2015-02-06 11:15:22 -08:00
parent 7315b0ce2c
commit 73a702f91e
2 changed files with 12 additions and 2 deletions

View File

@@ -65,7 +65,7 @@ class APIClient {
$headers[] = "api_key: " . $this->apiKey;
}
if (is_object($postData) or is_array($postData)) {
if (strpos($headers['Content-Type'], "multipart/form-data") < 0 and (is_object($postData) or is_array($postData))) {
$postData = json_encode($this->sanitizeForSerialization($postData));
}

View File

@@ -44,6 +44,7 @@ class {{classname}} {
$method = "{{httpMethod}}";
$queryParams = array();
$headerParams = array();
$formParams = array();
$headerParams['Accept'] = '{{#produces}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/produces}}';
$headerParams['Content-Type'] = '{{#consumes}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/consumes}}';
@@ -60,12 +61,21 @@ class {{classname}} {
$resourcePath = str_replace("{" . "{{paramName}}" . "}",
$this->apiClient->toPathValue(${{paramName}}), $resourcePath);
}{{/pathParams}}
{{#formParams}}
if (${{paramName}} != null) {
$formParams[{{paramName}}] = {{#isFile}}'@' . {{/isFile}}${{paramName}}
}{{/formParams}}
{{#bodyParams}}// body params
$body = null;
if (isset(${{paramName}})) {
$body = ${{paramName}};
}{{/bodyParams}}
$body = $body ?: $formParams;
if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) {
$body = http_build_query($body);
}
{{/bodyParams}}
// make the API Call
$response = $this->apiClient->callAPI($resourcePath, $method,