add test case and prefix support

This commit is contained in:
wing328
2015-05-20 18:25:35 +08:00
parent 06c7a6a109
commit 20439e646f
3 changed files with 78 additions and 14 deletions

View File

@@ -67,6 +67,19 @@ class APIClient {
$this->curl_timeout = $seconds;
}
/**
* Get API key (with prefix if set)
* @param string key name
* @return string
*/
public function getApiKeyWithPrefix($apiKey) {
if (Configuration::$apiKeyPrefix[$apiKey]) {
return Configuration::$apiKeyPrefix[$apiKey]." ".Configuration::$apiKey[$apiKey];
} else {
return Configuration::$apiKey[$apiKey];
}
}
/**
* update hearder and query param based on authentication setting
*
@@ -85,25 +98,26 @@ class APIClient {
switch($auth) {
case 'api_key':
$headerParams['api_key'] = Configuration::$apiKey['api_key'];
break;
$headerParams['api_key'] = $this->getApiKeyWithPrefix('api_key');
break;
case 'api_secret':
$queryParams['api_secret'] = Configuration::$apiKey['api_secret'];
break;
$queryParams['api_secret'] = $this->getApiKeyWithPrefix('api_secret');
break;
case 'petstore_auth':
#TODO support oauth
break;
//TODO support oauth
break;
default:
//TODO show warning about security definition not found
}
}
}
/**
* @param string $resourcePath path to method endpoint
* @param string $method method to call
@@ -117,6 +131,9 @@ class APIClient {
$headers = array();
# determine authentication setting
$this->updateParamsForAuth($headerParams, $queryParams, $authSettings);
# Allow API key from $headerParams to override default
$added_api_key = False;
if ($headerParams != null) {