rename APIClient to ApiClient, APIClientException to APIException

This commit is contained in:
wing328
2015-05-28 15:06:31 +08:00
parent 4d1d163a73
commit e993d08563
13 changed files with 53 additions and 53 deletions

View File

@@ -85,8 +85,8 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
supportingFiles.add(new SupportingFile("composer.mustache", packagePath, "composer.json"));
supportingFiles.add(new SupportingFile("configuration.mustache", packagePath + "/lib", "Configuration.php"));
supportingFiles.add(new SupportingFile("APIClient.mustache", packagePath + "/lib", "APIClient.php"));
supportingFiles.add(new SupportingFile("APIClientException.mustache", packagePath + "/lib", "APIClientException.php"));
supportingFiles.add(new SupportingFile("ApiClient.mustache", packagePath + "/lib", "ApiClient.php"));
supportingFiles.add(new SupportingFile("ApiException.mustache", packagePath + "/lib", "ApiException.php"));
supportingFiles.add(new SupportingFile("require.mustache", packagePath, invokerPackage + ".php"));
}

View File

@@ -17,7 +17,7 @@
namespace {{invokerPackage}};
class APIClient {
class ApiClient {
public static $PATCH = "PATCH";
public static $POST = "POST";
@@ -173,7 +173,7 @@ class APIClient {
* @param array $headerParams parameters to be place in request header
* @return mixed
*/
public function callAPI($resourcePath, $method, $queryParams, $postData,
public function callApi($resourcePath, $method, $queryParams, $postData,
$headerParams, $authSettings) {
$headers = array();
@@ -228,7 +228,7 @@ class APIClient {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method != self::$GET) {
throw new APIClientException('Method ' . $method . ' is not recognized.');
throw new ApiException('Method ' . $method . ' is not recognized.');
}
curl_setopt($curl, CURLOPT_URL, $url);
@@ -256,7 +256,7 @@ class APIClient {
// Handle the response
if ($response_info['http_code'] == 0) {
throw new APIClientException("TIMEOUT: api call to " . $url .
throw new ApiException("TIMEOUT: api call to " . $url .
" took more than 5s to return", 0, $response_info, $response);
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
$data = json_decode($response);
@@ -264,12 +264,12 @@ class APIClient {
$data = $response;
}
} else if ($response_info['http_code'] == 401) {
throw new APIClientException("Unauthorized API request to " . $url .
throw new ApiException("Unauthorized API request to " . $url .
": " . serialize($response), 0, $response_info, $response);
} else if ($response_info['http_code'] == 404) {
$data = null;
} else {
throw new APIClientException("Can't connect to the api: " . $url .
throw new ApiException("Can't connect to the api: " . $url .
" response code: " .
$response_info['http_code'], 0, $response_info, $response);
}

View File

@@ -19,7 +19,7 @@ namespace {{invokerPackage}};
use \Exception;
class APIClientException extends Exception {
class ApiException extends Exception {
protected $response, $response_info;
public function __construct($message="", $code=0, $response_info=null, $response=null) {

View File

@@ -28,7 +28,7 @@ class {{classname}} {
function __construct($apiClient = null) {
if (null === $apiClient) {
if (Configuration::$apiClient === null) {
Configuration::$apiClient = new APIClient(); // create a new API client if not present
Configuration::$apiClient = new ApiClient(); // create a new API client if not present
$this->apiClient = Configuration::$apiClient;
}
else
@@ -38,7 +38,7 @@ class {{classname}} {
}
}
private $apiClient; // instance of the APIClient
private $apiClient; // instance of the ApiClient
/**
* get the API client

View File

@@ -31,7 +31,7 @@ class Configuration {
public static $username = '';
public static $password = '';
// an instance of APIClient
// an instance of ApiClient
public static $apiClient;
// debugging
@@ -39,11 +39,11 @@ class Configuration {
public static $debug_file = 'php://output'; //output debug log to STDOUT by default
/*
* manually initalize API client
* manually initalize Api client
*/
public static function init() {
if (self::$apiClient === null)
self::$apiClient = new APIClient();
self::$apiClient = new ApiClient();
}
}

View File

@@ -17,7 +17,7 @@
namespace SwaggerClient;
class APIClient {
class ApiClient {
public static $PATCH = "PATCH";
public static $POST = "POST";
@@ -178,7 +178,7 @@ class APIClient {
* @param array $headerParams parameters to be place in request header
* @return mixed
*/
public function callAPI($resourcePath, $method, $queryParams, $postData,
public function callApi($resourcePath, $method, $queryParams, $postData,
$headerParams, $authSettings) {
$headers = array();
@@ -233,7 +233,7 @@ class APIClient {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method != self::$GET) {
throw new APIClientException('Method ' . $method . ' is not recognized.');
throw new ApiException('Method ' . $method . ' is not recognized.');
}
curl_setopt($curl, CURLOPT_URL, $url);
@@ -261,7 +261,7 @@ class APIClient {
// Handle the response
if ($response_info['http_code'] == 0) {
throw new APIClientException("TIMEOUT: api call to " . $url .
throw new ApiException("TIMEOUT: api call to " . $url .
" took more than 5s to return", 0, $response_info, $response);
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
$data = json_decode($response);
@@ -269,12 +269,12 @@ class APIClient {
$data = $response;
}
} else if ($response_info['http_code'] == 401) {
throw new APIClientException("Unauthorized API request to " . $url .
throw new ApiException("Unauthorized API request to " . $url .
": " . serialize($response), 0, $response_info, $response);
} else if ($response_info['http_code'] == 404) {
$data = null;
} else {
throw new APIClientException("Can't connect to the api: " . $url .
throw new ApiException("Can't connect to the api: " . $url .
" response code: " .
$response_info['http_code'], 0, $response_info, $response);
}

View File

@@ -19,7 +19,7 @@ namespace SwaggerClient;
use \Exception;
class APIClientException extends Exception {
class ApiException extends Exception {
protected $response, $response_info;
public function __construct($message="", $code=0, $response_info=null, $response=null) {

View File

@@ -31,7 +31,7 @@ class Configuration {
public static $username = '';
public static $password = '';
// an instance of APIClient
// an instance of ApiClient
public static $apiClient;
// debugging
@@ -39,11 +39,11 @@ class Configuration {
public static $debug_file = 'php://output'; //output debug log to STDOUT by default
/*
* manually initalize API client
* manually initalize Api client
*/
public static function init() {
if (self::$apiClient === null)
self::$apiClient = new APIClient();
self::$apiClient = new ApiClient();
}
}

View File

@@ -27,7 +27,7 @@ class PetApi {
function __construct($apiClient = null) {
if (null === $apiClient) {
if (Configuration::$apiClient === null) {
Configuration::$apiClient = new APIClient(); // create a new API client if not present
Configuration::$apiClient = new ApiClient(); // create a new API client if not present
$this->apiClient = Configuration::$apiClient;
}
else
@@ -37,7 +37,7 @@ class PetApi {
}
}
private $apiClient; // instance of the APIClient
private $apiClient; // instance of the ApiClient
/**
* get the API client

View File

@@ -27,7 +27,7 @@ class StoreApi {
function __construct($apiClient = null) {
if (null === $apiClient) {
if (Configuration::$apiClient === null) {
Configuration::$apiClient = new APIClient(); // create a new API client if not present
Configuration::$apiClient = new ApiClient(); // create a new API client if not present
$this->apiClient = Configuration::$apiClient;
}
else
@@ -37,7 +37,7 @@ class StoreApi {
}
}
private $apiClient; // instance of the APIClient
private $apiClient; // instance of the ApiClient
/**
* get the API client

View File

@@ -27,7 +27,7 @@ class UserApi {
function __construct($apiClient = null) {
if (null === $apiClient) {
if (Configuration::$apiClient === null) {
Configuration::$apiClient = new APIClient(); // create a new API client if not present
Configuration::$apiClient = new ApiClient(); // create a new API client if not present
$this->apiClient = Configuration::$apiClient;
}
else
@@ -37,7 +37,7 @@ class UserApi {
}
}
private $apiClient; // instance of the APIClient
private $apiClient; // instance of the ApiClient
/**
* get the API client

View File

@@ -11,7 +11,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
//SwaggerClient\Configuration::$debug = true;
// skip initializing the API client as it should be automatic
//$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
//$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
// new pet
$new_pet_id = 10005;
$new_pet = new SwaggerClient\models\Pet;
@@ -34,36 +34,36 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
$add_response = $pet_api->addPet($new_pet);
}
// test static functions defined in APIClient
public function testAPIClient()
// test static functions defined in ApiClient
public function testApiClient()
{
// test selectHeaderAccept
$this->assertSame('application/json', SwaggerClient\APIClient::selectHeaderAccept(array('application/xml','application/json')));
$this->assertSame(NULL, SwaggerClient\APIClient::selectHeaderAccept(array()));
$this->assertSame('application/yaml,application/xml', SwaggerClient\APIClient::selectHeaderAccept(array('application/yaml','application/xml')));
$this->assertSame('application/json', SwaggerClient\ApiClient::selectHeaderAccept(array('application/xml','application/json')));
$this->assertSame(NULL, SwaggerClient\ApiClient::selectHeaderAccept(array()));
$this->assertSame('application/yaml,application/xml', SwaggerClient\ApiClient::selectHeaderAccept(array('application/yaml','application/xml')));
// test selectHeaderContentType
$this->assertSame('application/json', SwaggerClient\APIClient::selectHeaderContentType(array('application/xml','application/json')));
$this->assertSame('application/json', SwaggerClient\APIClient::selectHeaderContentType(array()));
$this->assertSame('application/yaml,application/xml', SwaggerClient\APIClient::selectHeaderContentType(array('application/yaml','application/xml')));
$this->assertSame('application/json', SwaggerClient\ApiClient::selectHeaderContentType(array('application/xml','application/json')));
$this->assertSame('application/json', SwaggerClient\ApiClient::selectHeaderContentType(array()));
$this->assertSame('application/yaml,application/xml', SwaggerClient\ApiClient::selectHeaderContentType(array('application/yaml','application/xml')));
// test addDefaultHeader and getDefaultHeader
SwaggerClient\APIClient::addDefaultHeader('test1', 'value1');
SwaggerClient\APIClient::addDefaultHeader('test2', 200);
$defaultHeader = SwaggerClient\APIClient::getDefaultHeader();
SwaggerClient\ApiClient::addDefaultHeader('test1', 'value1');
SwaggerClient\ApiClient::addDefaultHeader('test2', 200);
$defaultHeader = SwaggerClient\ApiClient::getDefaultHeader();
$this->assertSame('value1', $defaultHeader['test1']);
$this->assertSame(200, $defaultHeader['test2']);
// test deleteDefaultHeader
SwaggerClient\APIClient::deleteDefaultHeader('test2');
$defaultHeader = SwaggerClient\APIClient::getDefaultHeader();
SwaggerClient\ApiClient::deleteDefaultHeader('test2');
$defaultHeader = SwaggerClient\ApiClient::getDefaultHeader();
$this->assertFalse(isset($defaultHeader['test2']));
$pet_api = new SwaggerClient\PetAPI();
$pet_api2 = new SwaggerClient\PetAPI();
$apiClient3 = new SwaggerClient\APIClient();
$apiClient3 = new SwaggerClient\ApiClient();
$apiClient3->setUserAgent = 'api client 3';
$apiClient4 = new SwaggerClient\APIClient();
$apiClient4 = new SwaggerClient\ApiClient();
$apiClient4->setUserAgent = 'api client 4';
$pet_api3 = new SwaggerClient\PetAPI($apiClient3);
@@ -88,7 +88,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
public function testGetPetById()
{
// initialize the API client without host
$api_client = new SwaggerClient\APIClient();
$api_client = new SwaggerClient\ApiClient();
SwaggerClient\Configuration::$apiKey['api_key'] = '111222333444555';
$pet_id = 10005; // ID of pet that needs to be fetched
$pet_api = new SwaggerClient\PetAPI($api_client);
@@ -106,7 +106,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
public function testFindPetByStatus()
{
// initialize the API client
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
$pet_api = new SwaggerClient\PetAPI($api_client);
// return Pet (model)
$response = $pet_api->findPetsByStatus("available");
@@ -125,7 +125,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
public function testUpdatePet()
{
// initialize the API client
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
$pet_id = 10001; // ID of pet that needs to be fetched
$pet_api = new SwaggerClient\PetAPI($api_client);
// create updated pet object
@@ -148,7 +148,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
public function testUpdatePetWithForm()
{
// initialize the API client
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
$pet_id = 10001; // ID of pet that needs to be fetched
$pet_api = new SwaggerClient\PetAPI($api_client);
// update Pet (form)
@@ -165,7 +165,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
public function testAddPet()
{
// initialize the API client
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
$new_pet_id = 10001;
$new_pet = new SwaggerClient\models\Pet;
$new_pet->id = $new_pet_id;
@@ -185,7 +185,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
public function testUploadFile()
{
// initialize the API client
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
$pet_api = new SwaggerClient\PetAPI($api_client);
// upload file
$pet_id = 10001;

View File

@@ -3,7 +3,7 @@
require_once('SwaggerClient-php/SwaggerClient.php');
// initialize the API client
//$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
//$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
//$api_client->addDefaultHeader("test1", "value1");
// to enable logging