Skip to content

Commit

Permalink
PHONUM-2815 (#318)
Browse files Browse the repository at this point in the history
* cnam_lookup in get and list

* added buy number change

* cnam lookup in update api

* added my changes

* handled -ve cases buy

* sync with master logic (review changes)

* sync with master logic (review changes)

* added key validation

* bump version

* handled not found for get

---------

Co-authored-by: kalyan-plivo <[email protected]>
  • Loading branch information
prabhav-plivo and kalyan-plivo authored Jun 2, 2023
1 parent ec3a0e8 commit 736c082
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## [4.50.0](https://github.com/plivo/plivo-php/tree/v4.50.0) (2023-05-02)
**Feature - CNAM Lookup**
- Added New Param `cnam_lookup` in to the response of the [list all numbers API], [list single number API]
- Added `cnam_lookup` filter to AccountPhoneNumber - list all my numbers API.
- Added `cnam_lookup` parameter to buy number[Buy a Phone Number] to configure CNAM Lookup while buying a US number
- Added `cnam_lookup` parameter to update number[Update an account phone number] to configure CNAM Lookup while buying a US number

## [v4.49.0](https://github.com/plivo/plivo-php/tree/v4.43.1) (2023-03-16)
**Feature - Added New Param 'cnam_lookup_number_config' in GetCall and ListCalls**
- Add `cnam_lookup_number_config` to the response for the [retrieve a call details API](https://www.plivo.com/docs/voice/api/call#retrieve-a-call) and the [retreive all call details API](https://www.plivo.com/docs/voice/api/call#retrieve-all-calls)
Expand Down
1 change: 1 addition & 0 deletions src/Plivo/Resources/Number/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function __construct(BaseClient $client, array $response, $authId)
'tendlcRegistrationStatus' => $response['tendlc_registration_status'],
'tollFreeSMSVerification' => $response['toll_free_sms_verification'],
'renewalDate' => $response['renewal_date'],
'cnamLookup' => $response['cnam_lookup'],
];
if (isset($response['object_id'])) {
$this->properties['objectId'] = $response['object_id'];
Expand Down
16 changes: 15 additions & 1 deletion src/Plivo/Resources/Number/NumberInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function __construct(BaseClient $plivoClient, $authId)
* <br /> sms - Returns a list of numbers that provide only 'sms' services.
* + [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.
* + [string] cnam_lookup - Used to filter on the basis of this param. If this parameter is included in the request, all numbers of the particular cnam lookup are displayed.
* + [string] renewal_date - Used to filter on the basis of this param. If this parameter is included in the request, all numbers of the particular renewal date are displayed.
* + [string] renewal_date__gt - Used to filter on the basis of this param. If this parameter is included in the request, all numbers greater than renewal date are displayed.
* + [string] renewal_date__gte - Used to filter on the basis of this param. If this parameter is included in the request, all numbers greater than equal renewal date are displayed.
Expand Down Expand Up @@ -107,9 +108,21 @@ public function get($number)
[]
);

return new Number(
$responseContents = $response->getContent();
if(!array_key_exists("error",$responseContents)){
return new Number(
$this->client, $response->getContent(),
$this->pathParams['authId']);
} else {
throw new PlivoResponseException(
$responseContents['error'],
0,
null,
$response->getContent(),
$response->getStatusCode()

);
}
}

/**
Expand All @@ -120,6 +133,7 @@ public function get($number)
* + [string] alias - The textual name given to the number.
* + [string] app_id - The application id of the application that is to be linked.
* + [string] subaccount - The auth_id of the subaccount to which this number should be added. This can only be performed by a main account holder.
* + [string] cnam_lookup - The cnam lookup value for the number (Valid values : enabled, disabled).
* @return ResponseUpdate
*/
public function update($number, $optionalArgs = [])
Expand Down
13 changes: 11 additions & 2 deletions src/Plivo/Resources/PhoneNumber/PhoneNumberInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ public function getList($countryIso, $optionalArgs = [])
*
* @param number $phoneNumber
* @param string|null $appId
* @param string|null $cnamLookup
* @return PhoneNumberBuyResponse output
*/
public function buy($phoneNumber, $appId = null)
public function buy($phoneNumber, $appId = null, $cnamLookup = null)
{
$response = $this->client->update(
$this->uri . $phoneNumber . '/',
['app_id'=>$appId]
['app_id'=>$appId,'cnam_lookup'=>$cnamLookup]
);

$responseContents = $response->getContent();
Expand All @@ -108,6 +109,14 @@ public function buy($phoneNumber, $appId = null)
$responseContents['status'],
$response->getStatusCode()
);
} elseif (gettype($responseContents['error']) == "array" && array_key_exists("error",$responseContents['error'])) {
throw new PlivoResponseException(
$responseContents['error']['error'],
0,
null,
$response->getContent(),
$response->getStatusCode()
);
} else {
throw new PlivoResponseException(
$responseContents['error'],
Expand Down
2 changes: 1 addition & 1 deletion src/Plivo/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Version
/**
* @const int PHP helper library minor version number
*/
const MINOR = 48;
const MINOR = 50;

/**
* @const int PHP helper library patch number
Expand Down
1 change: 1 addition & 0 deletions tests/Mocks/numberGetResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"voice_rate": "0.00850",
"mms_enabled": true,
"mms_rate": "0.00750",
"cnam_lookup": "enabled",
"compliance_application_id": "20372631212782797",
"compliance_status": "submitted",
"renewal_date": "2014-03-14",
Expand Down
3 changes: 3 additions & 0 deletions tests/Mocks/numberListResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"voice_rate": "0.00850",
"mms_enabled": true,
"mms_rate": "0.00950",
"cnam_lookup": "enabled",
"compliance_application_id": "20372631212782797",
"compliance_status": "submitted",
"renewal_date": "2014-09-05",
Expand Down Expand Up @@ -57,6 +58,7 @@
"voice_rate": "0.00850",
"mms_enabled": true,
"mms_rate": "0.00750",
"cnam_lookup": "enabled",
"compliance_application_id": "20372631212782797",
"compliance_status": "submitted",
"renewal_date": "2013-02-01",
Expand Down Expand Up @@ -86,6 +88,7 @@
"voice_rate": "0.00850",
"mms_enabled": true,
"mms_rate": "0.00850",
"cnam_lookup": "disabled",
"compliance_application_id": "20372631212782799",
"compliance_status": "submitted",
"renewal_date": "2013-04-25",
Expand Down

0 comments on commit 736c082

Please sign in to comment.