Skip to content

Commit

Permalink
Merge pull request #115 from plivo/revert_response
Browse files Browse the repository at this point in the history
Fix JSON responses
  • Loading branch information
nixonsam authored Mar 20, 2019
2 parents 5f68ad5 + 079c857 commit 32f73de
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 109 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [v4.3.1](https://github.com/plivo/plivo-php/releases/tag/v4.3.1) - 2019-03-20
- Fix Json responses for all resources.

## [v4.3.0](https://github.com/plivo/plivo-php/releases/tag/v4.3.0) - 2019-03-12
- Add PHLO support
- Add Multi-Party Call triggers
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ The Plivo PHP SDK makes it simpler to integrate communications into your PHP app

- To install the **stable release**, run the following command in the project directory:

$ composer require plivo/php-sdk
$ composer require plivo/plivo-php

- To install a **specific release**, run the following command in the project directory:

$ composer require plivo/php-sdk:4.3.0
$ composer require plivo/plivo-php:4.3.1

- To test the features in the **beta release**, run the following command in the project directory:

$ composer require plivo/php-sdk:v4.2-beta1
$ composer require plivo/plivo-php:v4.2-beta1

- Alternatively, you can download this source and run

Expand Down
9 changes: 7 additions & 2 deletions src/Plivo/Resources/Application/ApplicationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function __construct(BaseClient $plivoClient, $authId)
* + string subaccount - Id of the subaccount, in case only subaccount applications are needed.
* + boolean log_incoming_messages - controls the incoming message logs.
*
* @return JSON output
* @return ApplicationCreateResponse output
*/
public function create(
$appName, array $optionalArgs = [])
Expand All @@ -66,7 +66,12 @@ public function create(
array_merge($mandaoryArgs, $optionalArgs)
);

return json_encode($response->getContent(), JSON_FORCE_OBJECT);
$responseContents = $response->getContent();

return new ApplicationCreateResponse(
$responseContents['api_id'],
$responseContents['app_id'],
$responseContents['message']);
}

/**
Expand Down
14 changes: 11 additions & 3 deletions src/Plivo/Resources/Call/CallInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ public function create($from, array $to, $answerUrl, $answerMethod,
array_merge($mandatoryArgs, $optionalArgs)
);

return json_encode($response->getContent(), JSON_FORCE_OBJECT);
$responseContents = $response->getContent();
return new CallCreateResponse(
$responseContents['api_id'],
$responseContents['message'],
$responseContents['request_uuid']
);
}

/**
Expand Down Expand Up @@ -220,8 +225,11 @@ public function getList(array $optionalArgs = [])

array_push($calls, $newCall);
}

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

/**
Expand Down
12 changes: 8 additions & 4 deletions src/Plivo/Resources/Endpoint/EndpointInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ public function create($username, $password, $alias, $appId = null)
$this->uri,
array_merge($mandatoryArgs, ['app_id' => $appId])
);

return json_encode($response->getContent(), JSON_FORCE_OBJECT);
$responseContents = $response->getContent();
return new EndpointCreateReponse(
$responseContents['username'],
$responseContents['alias'],
$responseContents['message'],
$responseContents['endpoint_id'],
$responseContents['api_id']);
}

/**
Expand Down Expand Up @@ -110,8 +115,7 @@ public function getList($optionalArgs = [])

array_push($endpoints, $newEndpoint);
}

return json_encode($response->getContent(), JSON_FORCE_OBJECT);
return new ResourceList($this->client, $response->getContent()['meta'], $endpoints);
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/Plivo/Resources/Message/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function getList($optionalArgs = [])
array_push($messages, $newMessage);
}

return json_encode($response->getContent(), JSON_FORCE_OBJECT);
return new MessageList($this->client, $response->getContent()['meta'], $messages);
}

// protected function getAllList()
Expand Down Expand Up @@ -137,7 +137,7 @@ protected function getList($optionalArgs = [])
* <br /> ErrorCode - Delivery Response code returned by the carrier attempting the delivery. See Supported error codes {https://www.plivo.com/docs/api/message/#standard-plivo-error-codes}.
* + [string] :method - The method used to call the url. Defaults to POST.
* + [string] :log - If set to false, the content of this message will not be logged on the Plivo infrastructure and the dst value will be masked (e.g., 141XXXXX528). Default is set to true.
* @return JSON output
* @return MessageCreateResponse output
* @throws PlivoValidationException
*/

Expand Down Expand Up @@ -171,7 +171,12 @@ public function create($src, array $dst, $text,
array_merge($mandatoryArgs, $optionalArgs, ['src' => $src, 'powerpack_uuid' => $powerpackUUID])
);

return json_encode($response->getContent(), JSON_FORCE_OBJECT);
$responseContents = $response->getContent();
return new MessageCreateResponse(
$responseContents['message'],
$responseContents['message_uuid'],
$responseContents['api_id']
);
}

}
3 changes: 2 additions & 1 deletion src/Plivo/Resources/PHLO/Node/NodeClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public function update($action, $arguments)
];

$response = $this->client->updateNode($this->nodeUrl, $params);
return json_encode($response->getContent(), JSON_FORCE_OBJECT);
return $response->getContent();
// return json_encode($response->getContent(), JSON_FORCE_OBJECT);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Plivo/Resources/PHLO/Node/NodeMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function __call($name, $arguments = null)
];

$response = $this->client->updateNode($this->nodeMemberUrl, $params);
return json_encode($response->getContent(), JSON_FORCE_OBJECT);
return $response->getContent();
// return json_encode($response->getContent(), JSON_FORCE_OBJECT);
}
}
3 changes: 2 additions & 1 deletion src/Plivo/Resources/PHLO/Phlo.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public function getPhlo($id)
{
$phlo = new self($this->client, $id, $this->baseUrl);
$response = $phlo->client->getPhlorunner($phlo->phloUrl, []);
return json_encode($response->getContent(), JSON_FORCE_OBJECT);
return $response->getContent();
// return json_encode($response->getContent(), JSON_FORCE_OBJECT);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Plivo/Resources/PHLO/Phlorunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function run($arguments = [] , $authId = null)
"authId" => $authId
];
$response = $this->client->getPhlorunnerApis($this->phlorunnerUrl, $arguments, $headers);
return json_encode($response->getContent(), JSON_FORCE_OBJECT);
return $response->getContent();
// return json_encode($response->getContent(), JSON_FORCE_OBJECT);
}
}
16 changes: 11 additions & 5 deletions src/Plivo/Resources/PhoneNumber/PhoneNumberInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function __construct(BaseClient $plivoClient, $authId)
* + [string] rate_center - Numbers can be searched using Rate Center {http://en.wikipedia.org/wiki/Telephone_exchange}. This filter is application only for country_iso US and CA.
* + [int] limit - Used to display the number of results per page. The maximum number of results that can be fetched is 20.
* + [int] offset - Denotes the number of value items by which the results should be offset. Eg:- If the result contains a 1000 values and limit is set to 10 and offset is set to 705, then values 706 through 715 are displayed in the results. This parameter is also used for pagination of the results.
* @return JSON output
* @return ResourceList output
*/
public function getList($countryIso, $optionalArgs = [])
{
Expand All @@ -65,16 +65,15 @@ public function getList($countryIso, $optionalArgs = [])

array_push($phoneNumbers, $newNumber);
}

return json_encode($response->getContent(), JSON_FORCE_OBJECT);
return new ResourceList($this->client, $response->getContent()['meta'], $phoneNumbers);
}

/**
* Buy a phone number
*
* @param number $phoneNumber
* @param string|null $appId
* @return JSON output
* @return PhoneNumberBuyResponse output
*/
public function buy($phoneNumber, $appId = null)
{
Expand All @@ -83,6 +82,13 @@ public function buy($phoneNumber, $appId = null)
['app_id'=>$appId]
);

return json_encode($response->getContent(), JSON_FORCE_OBJECT);
$responseContents = $response->getContent();
return new PhoneNumberBuyResponse(
$responseContents['api_id'],
$responseContents['message'],
$responseContents['numbers'][0]['number'],
$responseContents['numbers'][0]['status'],
$responseContents['status']
);
}
}
2 changes: 1 addition & 1 deletion src/Plivo/Resources/Recording/Recording.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Recording extends Resource
*/
function __construct(BaseClient $client, array $response, $authId)
{
parent::__construct($client);
// parent::__construct($client);

$this->properties = [
'addTime' => $response['add_time'],
Expand Down
8 changes: 3 additions & 5 deletions src/Plivo/Resources/Recording/RecordingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ protected function getList($optionalArgs = [])
$recordings = [];

foreach ($response->getContent()['objects'] as $recording) {

$newRecording = new Recording(
$this->client, $recording, $this->pathParams['authId']);

array_push($recordings, $newRecording);
}
// return new ResourceList(
// $this->client, $response->getContent()['meta'], $recordings);

return json_encode($response->getContent(), JSON_FORCE_OBJECT);
return new ResourceList(
$this->client, $response->getContent()['meta'], $recordings);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Plivo/Resources/ResourceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ResourceList implements \IteratorAggregate
/**
* @var BaseClient
*/
protected $client;
// protected $client;

/**
* @var array
Expand All @@ -24,7 +24,7 @@ class ResourceList implements \IteratorAggregate
/**
* @var
*/
protected $uri;
// protected $uri;

/**
* @var
Expand All @@ -44,7 +44,7 @@ class ResourceList implements \IteratorAggregate
*/
function __construct(BaseClient $plivoClient, array $meta, array $resources)
{
$this->client = $plivoClient;
// $this->client = $plivoClient;
$this->meta = $meta;
$this->resources = $resources;
}
Expand Down
13 changes: 10 additions & 3 deletions src/Plivo/Resources/SubAccount/SubAccountInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ public function create($name, $enabled = null)
$this->uri,
$data
);

return json_encode($response->getContent(), JSON_FORCE_OBJECT);
$responseContents = $response->getContent();
return new SubAccountCreateResponse(
$responseContents['message'],
$responseContents['auth_id'],
$responseContents['auth_token'],
$responseContents['api_id']);
}

/**
Expand Down Expand Up @@ -173,6 +177,9 @@ protected function getList($limit = null, $offset = null)
array_push($subAccounts, $newSubAccount);
}

return json_encode($response->getContent(), JSON_FORCE_OBJECT);
return new SubAccountList(
$this->client,
$response->getContent()['meta'],
$subAccounts);
}
}
2 changes: 1 addition & 1 deletion src/Plivo/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Version
/**
* @const int PHP helper library patch number
*/
const PATCH = 0;
const PATCH = 1;

/**
* @return string
Expand Down
Loading

0 comments on commit 32f73de

Please sign in to comment.