Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made changes for statusCode retrieval for SDK response #255

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Plivo/Resources/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@
*/
class Application extends Resource
{
public $statusCode;
/**
* Application constructor.
* @param BaseClient $client
* @param $response
* @param $authId
*/
public function __construct(BaseClient $client, $response, $authId)
public function __construct(BaseClient $client, $response, $authId, $statusCode)
{
$this->statusCode = $statusCode;
parent::__construct($client);

$this->properties = [
Expand Down
21 changes: 17 additions & 4 deletions src/Plivo/Resources/Application/ApplicationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,19 @@ public function delete($appId, array $optionalArgs = [])
$this->uri . $appId . '/',
$optionalArgs
);
$responseContents = $response->getContent();

return new ResponseDelete($response->getStatusCode());
if(!array_key_exists("api_id", $responseContents)){
return new ResponseDelete($response->getStatusCode());
}
elseif ($response->getStatusCode() == 400){
return new ResponseDelete($response->getStatusCode(), "app_id parameter is missing or invalid.",
$responseContents['api_id']);
}
else{
return new ResponseDelete($response->getStatusCode(), "application ".$appId." not found",
$responseContents['api_id']);
}
}

/**
Expand All @@ -183,7 +194,8 @@ public function get($appId)
return new Application(
$this->client,
$response->getContent(),
$this->pathParams['authId']);
$this->pathParams['authId'],
$response->getStatusCode());
}


Expand Down Expand Up @@ -212,14 +224,15 @@ public function getList(array $optionalArgs = [])
$newApplication = new Application(
$this->client,
$application,
$this->pathParams['authId']);
$this->pathParams['authId'], null);

array_push($applications, $newApplication);
}

return new ApplicationList(
$this->client,
$response->getContent()['meta'],
$applications);
$applications,
$response->getStatusCode());
}
}
4 changes: 3 additions & 1 deletion src/Plivo/Resources/Application/ApplicationList.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
*/
class ApplicationList extends ResourceList
{
public $statusCode;
/**
* ApplicationList constructor.
* @param BaseClient $plivoClient
* @param $meta
* @param array $resources
*/
function __construct(BaseClient $plivoClient, $meta, array $resources)
function __construct(BaseClient $plivoClient, $meta, array $resources, $statusCode)
{
$this->statusCode = $statusCode;
parent::__construct($plivoClient, $meta, $resources);
}
}
6 changes: 4 additions & 2 deletions src/Plivo/Resources/Call/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@
*/
class Call extends Resource
{
public $statusCode;

/**
* Call constructor.
* @param BaseClient $client
* @param $response
* @param $authId
*/
function __construct(
BaseClient $client, $response, $authId)
BaseClient $client, $response, $authId, $statusCode)
{
parent::__construct($client);

Expand Down Expand Up @@ -72,6 +74,6 @@ function __construct(
];

$this->id = $response['call_uuid'];

$this->statusCode = $statusCode;
}
}
68 changes: 56 additions & 12 deletions src/Plivo/Resources/Call/CallInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Plivo\BaseClient;
use Plivo\Resources\ResourceInterface;
use Plivo\Resources\ResourceList;
use Plivo\Resources\ResponseDelete;

use Plivo\Resources\ResponseUpdate;
use Plivo\Util\ArrayOperations;
Expand Down Expand Up @@ -138,7 +139,8 @@ public function get($callUuid)
return new Call(
$this->client,
$response->getContent(),
$this->pathParams['authId']);
$this->pathParams['authId'],
$response->getStatusCode());
}

/**
Expand All @@ -165,7 +167,8 @@ public function getLive($liveCallUuid)
return new CallLive(
$this->client,
$response->getContent(),
$this->pathParams['authId']);
$this->pathParams['authId'],
$response->getStatusCode());
}

/**
Expand Down Expand Up @@ -193,7 +196,8 @@ public function getQueued($queuedCallUuid)
return new CallQueued(
$this->client,
$response->getContent(),
$this->pathParams['authId']);
$this->pathParams['authId'],
$response->getStatusCode());
}

/**
Expand Down Expand Up @@ -237,15 +241,16 @@ public function getList(array $optionalArgs = [])
$calls = [];

foreach ($response->getContent()['objects'] as $call) {
$newCall = new Call($this->client, $call, $this->pathParams['authId'], $call['call_uuid']);
$newCall = new Call($this->client, $call, $this->pathParams['authId'], null);

array_push($calls, $newCall);
}
return
new CallList(
$this->client,
$response->getContent()['meta'],
$calls);
$calls,
$response->getStatusCode());
}

/**
Expand All @@ -264,7 +269,8 @@ public function getListLive(array $optionalArgs = [])

$liveCallUuids = $response->getContent()['calls'];

return $liveCallUuids;
$resp['statusCode'] = $response->getStatusCode();
return array_merge($response->getContent(), $resp);
}

/**
Expand All @@ -283,7 +289,8 @@ public function getListQueued()

$queuedCallUuids = $response->getContent()['calls'];

return $queuedCallUuids;
$resp['statusCode'] = $response->getStatusCode();
return array_merge($response->getContent(), $resp);
}

/**
Expand All @@ -294,10 +301,19 @@ public function getListQueued()
public function delete($callUuid = null)
{
$optionalArgs['isVoiceRequest'] = true;
$this->client->delete(
$response = $this->client->delete(
$this->uri . $callUuid . '/',
$optionalArgs
);
$responseContents = $response->getContent();

if(!array_key_exists("api_id", $responseContents)){
return new ResponseDelete($response->getStatusCode());
}
else{
return new ResponseDelete($response->getStatusCode(), "call not found",
$responseContents['api_id']);
}
}

/**
Expand Down Expand Up @@ -501,10 +517,19 @@ public function stopRecording($liveCallUuid, $url = null)
}

$params['isVoiceRequest'] = true;
$this->client->delete(
$response = $this->client->delete(
$this->uri . $liveCallUuid . '/Record/',
$params
);
$responseContents = $response->getContent();

if(!array_key_exists("api_id", $responseContents)){
return new ResponseDelete($response->getStatusCode());
}
else{
return new ResponseDelete($response->getStatusCode(), "call not found",
$responseContents['api_id']);
}
}

/**
Expand Down Expand Up @@ -590,10 +615,19 @@ public function stopPlaying($liveCallUuid)
}
$optionalArgs['isVoiceRequest'] = true;

$this->client->delete(
$response = $this->client->delete(
$this->uri . $liveCallUuid . '/Play/',
$optionalArgs
);
$responseContents = $response->getContent();

if(!array_key_exists("api_id", $responseContents)){
return new ResponseDelete($response->getStatusCode());
}
else{
return new ResponseDelete($response->getStatusCode(), "call not found",
$responseContents['api_id']);
}
}

/**
Expand Down Expand Up @@ -682,10 +716,19 @@ public function stopSpeaking($liveCallUuid)
"Which call to stop speaking in? No callUuid given");
}
$optionalArgs['isVoiceRequest'] = true;
$this->client->delete(
$response = $this->client->delete(
$this->uri . $liveCallUuid . '/Speak/',
$optionalArgs
);
$responseContents = $response->getContent();

if(!array_key_exists("api_id", $responseContents)){
return new ResponseDelete($response->getStatusCode());
}
else{
return new ResponseDelete($response->getStatusCode(), "call not found",
$responseContents['api_id']);
}
}

/**
Expand Down Expand Up @@ -753,13 +796,14 @@ public function cancel($requestUuid)
"Which call request to cancel? No requestUuid given");
}
$optionalArgs['isVoiceRequest'] = true;
$this->client->delete(
$response = $this->client->delete(
"Account/".
$this->pathParams['authId'].
"/Request/".
$requestUuid.
'/',
$optionalArgs
);
return new ResponseDelete($response->getStatusCode());
}
}
4 changes: 3 additions & 1 deletion src/Plivo/Resources/Call/CallList.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
*/
class CallList extends ResourceList
{
public $statusCode;

/**
* CallList constructor.
* @param BaseClient $plivoClient
* @param array $meta
* @param array $resources
*/
function __construct(BaseClient $plivoClient, $meta, array $resources)
function __construct(BaseClient $plivoClient, $meta, array $resources, $statusCode)
{
parent::__construct($plivoClient, $meta, $resources);
$this->statusCode = $statusCode;
}

}
5 changes: 4 additions & 1 deletion src/Plivo/Resources/Call/CallLive.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
*/
class CallLive extends Resource
{
public $statusCode;

/**
* CallLive constructor.
* @param BaseClient $client The Plivo API REST client
* @param array $response
* @param string $authId
*/
function __construct(BaseClient $client, $response, $authId)
function __construct(BaseClient $client, $response, $authId, $statusCode)
{
parent::__construct($client);

Expand All @@ -39,6 +41,7 @@ function __construct(BaseClient $client, $response, $authId)
];

$this->id = $response['call_uuid'];
$this->statusCode = $statusCode;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Plivo/Resources/Call/CallQueued.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
*/
class CallQueued extends Resource
{
public $statusCode;

/**
* CallQueued constructor.
* @param BaseClient $client The Plivo API REST client
* @param array $response
* @param string $authId
*/
function __construct(BaseClient $client, $response, $authId)
function __construct(BaseClient $client, $response, $authId, $statusCode)
{
parent::__construct($client);

Expand All @@ -39,6 +41,7 @@ function __construct(BaseClient $client, $response, $authId)
];

$this->id = $response['call_uuid'];
$this->statusCode = $statusCode;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Plivo/Resources/Conference/Conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
class Conference extends Resource
{
public $statusCode;

/**
* Conference constructor.
* @param BaseClient $client
Expand All @@ -30,11 +32,13 @@ class Conference extends Resource
* @param $conferenceName
*/
public function __construct(
BaseClient $client, $response, $authId, $conferenceName)
BaseClient $client, $response, $authId, $conferenceName, $statusCode)
{
$this->statusCode = $statusCode;
parent::__construct($client);

$this->properties = [
'apiId' => $response['api_id'],
'conferenceName' => $response['conference_name'],
'conferenceRunTime' => $response['conference_run_time'],
'conferenceMemberCount' => $response['conference_member_count'],
Expand Down
Loading