Skip to content

Commit

Permalink
Update SDK to latest version of API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Schurter committed Dec 19, 2017
1 parent 66c689c commit c75a496
Show file tree
Hide file tree
Showing 171 changed files with 3,706 additions and 722 deletions.
39 changes: 37 additions & 2 deletions lib/Http/ConnectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,34 @@ final class ConnectionException extends Exception {
* @var string
*/
private $url;

/**
* The log token of the request.
*
* @var string
*/
private $requestToken;

/**
* The error message without prefixed log token.
*
* @var string
*/
private $errorMessage;

/**
* Constructor.
*
* @param string $url the URL of the connection
* @param string $requestToken the log token of the request
* @param string $message the error message
* @param int $code the error code
*/
public function __construct($url = null, $message = "", $code = 0) {
parent::__construct($message, $code);
public function __construct($url = null, $requestToken = "", $message = "", $code = 0) {
parent::__construct('[' . $requestToken . '] ' . $message, $code);
$this->url = $url;
$this->requestToken = $requestToken;
$this->errorMessage = $message;
}

/**
Expand All @@ -61,5 +78,23 @@ public function __construct($url = null, $message = "", $code = 0) {
public function getUrl() {
return $this->url;
}

/**
* Returns the log token of the request.
*
* @return string
*/
public function getRequestToken() {
return $this->requestToken;
}

/**
* Returns the error message without prefixed log token.
*
* @return string
*/
public function getErrorMessage() {
return $this->errorMessage;
}

}
6 changes: 3 additions & 3 deletions lib/Http/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function send(ApiClient $apiClient, HttpRequest $request) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getBody());
} elseif ($request->getMethod() !== HttpRequest::GET) {
throw new ConnectionException($request->getUrl(), '[' . $request->getLogToken() . '] Method ' . $request->getMethod() . ' is not recognized.');
throw new ConnectionException($request->getUrl(), $request->getLogToken(), 'Method ' . $request->getMethod() . ' is not recognized.');
}
curl_setopt($curl, CURLOPT_URL, $request->getUrl());

Expand Down Expand Up @@ -133,9 +133,9 @@ private function handleResponse(ApiClient $apiClient, HttpRequest $request, $cur

// curl_exec can sometimes fail but still return a blank message from curl_error().
if (!empty($curl_error_message)) {
throw new ConnectionException($url, '[' . $request->getLogToken() . '] ' . $curl_error_message);
throw new ConnectionException($url, $request->getLogToken(), $curl_error_message);
} else {
throw new ConnectionException($url, '[' . $request->getLogToken() . '] API call failed for an unknown reason. This could happen if you are disconnected from the network.');
throw new ConnectionException($url, $request->getLogToken(), 'API call failed for an unknown reason. This could happen if you are disconnected from the network.');
}
} else {
return new HttpResponse($response_info['http_code'], $http_header, $http_body);
Expand Down
22 changes: 11 additions & 11 deletions lib/Http/SocketHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public function send(ApiClient $apiClient, HttpRequest $request) {
}

if (empty($responseMessage)) {
throw new ConnectionException($request->getUrl(),
'[' . $request->getLogToken() . '] The server responded with an empty response (no HTTP header and no HTTP body).');
throw new ConnectionException($request->getUrl(), $request->getLogToken(),
'The server responded with an empty response (no HTTP header and no HTTP body).');
}

return new HttpResponse($responseMessage);
Expand Down Expand Up @@ -151,8 +151,8 @@ private function readFromSocket(ApiClient $apiClient, HttpRequest $request, $soc
return $responseMessage;
}
else {
throw new ConnectionException(null,
'[' . $request->getLogToken() . '] The remote server did not respond within ' . $apiClient->getConnectionTimeout() . ' seconds.');
throw new ConnectionException(null, $request->getLogToken(),
'The remote server did not respond within ' . $apiClient->getConnectionTimeout() . ' seconds.');
}
}

Expand Down Expand Up @@ -191,8 +191,8 @@ private function readContentFromSocket(ApiClient $apiClient, HttpRequest $reques
return $result;
}
else {
throw new ConnectionException(null,
'[' . $request->getLogToken() . '] The remote server did not respond within ' . $apiClient->getConnectionTimeout() . ' seconds.');
throw new ConnectionException(null, $request->getLogToken(),
'The remote server did not respond within ' . $apiClient->getConnectionTimeout() . ' seconds.');
}
}

Expand Down Expand Up @@ -227,8 +227,8 @@ private function readLineFromSocket(ApiClient $apiClient, HttpRequest $request,
return $result;
}
else {
throw new ConnectionException(null,
'[' . $request->getLogToken() . '] The remote server did not respond within ' . $apiClient->getConnectionTimeout() . ' seconds.');
throw new ConnectionException(null, $request->getLogToken(),
'The remote server did not respond within ' . $apiClient->getConnectionTimeout() . ' seconds.');
}
}

Expand All @@ -253,7 +253,7 @@ private function startStreamSocket(ApiClient $apiClient, HttpRequest $request) {

$result = fwrite($socket, $message);
if ($result == false) {
throw new ConnectionException($request->getUrl(), '[' . $request->getLogToken() . '] Could not send the message to the server.');
throw new ConnectionException($request->getUrl(), $request->getLogToken(), 'Could not send the message to the server.');
}
return $socket;
}
Expand Down Expand Up @@ -310,12 +310,12 @@ private function createSocketStream(ApiClient $apiClient, HttpRequest $request)
$this->createStreamContext($apiClient, $request));

if ($filePointer === false) {
throw new ConnectionException($request->getUrl(), '[' . $request->getLogToken() . '] ' . $errstr);
throw new ConnectionException($request->getUrl(), $request->getLogToken(), $errstr);
}

if (!(get_resource_type($filePointer) == 'stream')) {
$errorMessage = 'Could not connect to the server. The returned socket was not a stream.';
throw new ConnectionException($request->getUrl(), '[' . $request->getLogToken() . '] ' . $errorMessage);
throw new ConnectionException($request->getUrl(), $request->getLogToken(), $errorMessage);
}

return $filePointer;
Expand Down
4 changes: 2 additions & 2 deletions lib/Model/AbstractAccountUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public static function swaggerTypes() {
* @param mixed[] $data an associated array of property values initializing the model
*/
public function __construct(array $data = null) {
if (isset($data['name']) && $data['name'] != null) {
if (isset($data['name'])) {
$this->setName($data['name']);
}
if (isset($data['subaccountLimit']) && $data['subaccountLimit'] != null) {
if (isset($data['subaccountLimit'])) {
$this->setSubaccountLimit($data['subaccountLimit']);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Model/AbstractApplicationUserUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public static function swaggerTypes() {
* @param mixed[] $data an associated array of property values initializing the model
*/
public function __construct(array $data = null) {
if (isset($data['name']) && $data['name'] != null) {
if (isset($data['name'])) {
$this->setName($data['name']);
}
if (isset($data['state']) && $data['state'] != null) {
if (isset($data['state'])) {
$this->setState($data['state']);
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/Model/AbstractHumanUserUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ public static function swaggerTypes() {
* @param mixed[] $data an associated array of property values initializing the model
*/
public function __construct(array $data = null) {
if (isset($data['emailAddress']) && $data['emailAddress'] != null) {
if (isset($data['emailAddress'])) {
$this->setEmailAddress($data['emailAddress']);
}
if (isset($data['firstname']) && $data['firstname'] != null) {
if (isset($data['firstname'])) {
$this->setFirstname($data['firstname']);
}
if (isset($data['language']) && $data['language'] != null) {
if (isset($data['language'])) {
$this->setLanguage($data['language']);
}
if (isset($data['lastname']) && $data['lastname'] != null) {
if (isset($data['lastname'])) {
$this->setLastname($data['lastname']);
}
if (isset($data['state']) && $data['state'] != null) {
if (isset($data['state'])) {
$this->setState($data['state']);
}
if (isset($data['timeZone']) && $data['timeZone'] != null) {
if (isset($data['timeZone'])) {
$this->setTimeZone($data['timeZone']);
}
}
Expand Down
Loading

0 comments on commit c75a496

Please sign in to comment.