Skip to content

Commit

Permalink
Merge branch 'master' into guzzlehttp_inc
Browse files Browse the repository at this point in the history
  • Loading branch information
nixonsam committed Oct 13, 2020
2 parents 6f9ded4 + 64f9401 commit ee5f4c9
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
## [v4.12.0](https://github.com/plivo/plivo-php/releases/tag/v4.12.0) - 2020-10-06
- Upgarde Guzzle Http cleint Version 6 to 7.

## [v4.12.0](https://github.com/plivo/plivo-php/releases/tag/v4.12.0) - 2020-09-21
- Add support for Lookup API.

## [v4.11.1](https://github.com/plivo/plivo-php/releases/tag/v4.11.1) - 2020-09-17
- Fix "Media is invalid" error while using Send MMS API.

Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The Plivo PHP SDK makes it simpler to integrate communications into your PHP app

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

$ composer require plivo/plivo-php:4.9.0
$ composer require plivo/plivo-php:4.12.0

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

Expand Down Expand Up @@ -164,6 +164,17 @@ $call_made = $client->calls->create(
);
```

### Lookup a number

```php
<?php
require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("AUTH_ID", "AUTH_TOKEN");
$response = $client->lookup->get("<number-goes-here>", "carrier");
```

### Generate Plivo XML

```php
Expand Down
41 changes: 41 additions & 0 deletions src/Plivo/Resources/Lookup/LookupInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Plivo\Resources\Lookup;

use Plivo\BaseClient;
use Plivo\Resources\ResourceInterface;

/**
* Class LookupInterface
* @package Plivo\Resources\Lookup
*/
class LookupInterface extends ResourceInterface
{
/**
* LookupInterface constructor.
* @param BaseClient $plivoClient
*/
public function __construct(BaseClient $plivoClient)
{
parent::__construct($plivoClient);
$this->uri = "Lookup/Number/";
}

/**
* Lookup a phone number.
* @param number
* @param type
*/
public function get($number, $type = "carrier")
{
$uri = $this->uri . $number . '?type=' . $type;
$response = $this->client->fetch(
$uri,
[]
);

// returns a nested associative array and is better than subclassing
// from Resource class since there is no further use for client.
return $response->getContent();
}
}
33 changes: 29 additions & 4 deletions src/Plivo/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Plivo\Resources\Message\MessageInterface;
use Plivo\Resources\Powerpack\PowerpackInterface;
use Plivo\Resources\Media\MediaInterface;
use Plivo\Resources\Lookup\LookupInterface;
use Plivo\Resources\Number\NumberInterface;
use Plivo\Resources\PhoneNumber\PhoneNumberInterface;
use Plivo\Resources\Pricing\PricingInterface;
Expand All @@ -28,7 +29,8 @@
* @property AccountInterface account Interface to handle all Account related api calls
* @property MessageInterface message Interface to handle all Message related api calls
* @property PowerpackInterface powerpack Interface to handle all Powerpack related api calls
* @property MediaInterface media Interface to handle all upload mms media api
* @property MediaInterface media Interface to handle all upload mms media api
* @property LookupInterface lookup Interface to handle calls to the Lookup API
* @property EndpointInterface endpoint Interface to handle all Endpoint related api calls
* @property NumberInterface number Interface to handle all Number related api calls
* @property PhoneNumberInterface phoneNumber Interface to handle all PhoneNumber related api calls
Expand Down Expand Up @@ -68,6 +70,11 @@ class RestClient
*/
protected $_media;

/**
* @var LookupInterface
*/
protected $_lookup;

/**
* @var ApplicationInterface
*/
Expand Down Expand Up @@ -130,10 +137,17 @@ public function __construct(
$proxyHost = null,
$proxyPort = null,
$proxyUsername = null,
$proxyPassword = null)
{
$proxyPassword = null
) {

$this->client = new BaseClient(
$authId, $authToken, $proxyHost, $proxyPort, $proxyUsername, $proxyPassword);
$authId,
$authToken,
$proxyHost,
$proxyPort,
$proxyUsername,
$proxyPassword
);
$this->msgClient = new MessageClient($authId, $authToken, $proxyHost, $proxyPort, $proxyUsername, $proxyPassword);
}

Expand Down Expand Up @@ -196,6 +210,17 @@ protected function getMedia()
return $this->_media;
}

/**
* @return LookupInterface
*/
protected function getLookup()
{
if (!$this->_lookup) {
$this->_lookup = new LookupInterface($this->client);
}
return $this->_lookup;
}

/**
* @return ApplicationInterface
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Plivo/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Plivo;


/**
* Class Version
* @package Plivo
Expand All @@ -25,7 +24,7 @@ class Version
/**
* @const int PHP helper library patch number
*/
const PATCH = 1;
const PATCH = 0;
/**
* @return string
*/
Expand Down
23 changes: 23 additions & 0 deletions tests/Mocks/lookupGetResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"api_id": "a35a2e7a-fd27-42e6-910c-33382f43240e",
"phone_number": "+14154305555",
"country": {
"name": "United States",
"code_iso2": "US",
"code_iso3": "USA"
},
"format": {
"e164": "+14154305555",
"national": "(415) 430-5555",
"international": "+1 415-430-5555",
"rfc3966": "tel:+1-415-430-5555"
},
"carrier": {
"mobile_country_code": "310",
"mobile_network_code": "150",
"name": "Cingular Wireless",
"type": "mobile",
"ported": true
},
"resource_uri": "/v1/Lookup/Number/+14154305555?type=carrier"
}
35 changes: 35 additions & 0 deletions tests/Resources/LookupTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Plivo\Tests\Resources;

use Plivo\Http\PlivoRequest;
use Plivo\Http\PlivoResponse;
use Plivo\Tests\BaseTestCase;

/**
* Class LookupTest
* @package Plivo\Tests\Resources
*/
class LookupTest extends BaseTestCase
{

public function testLookupGet()
{
$number = "+14154305555";
$request = new PlivoRequest(
'GET',
'Lookup/Number/'.$number.'?type=carrier',
[]
);
$body = file_get_contents(__DIR__ . '/../Mocks/lookupGetResponse.json');
$this->mock(new PlivoResponse($request, 200, $body));

$actual = $this->client->lookup->get($number);
$this->assertRequest($request);

self::assertNotNull($actual);
self::assertEquals($actual["phone_number"], $number);
self::assertEquals($actual["format"]["e164"], $number);
self::assertEquals($actual["resource_uri"], "/v1/Lookup/Number/+14154305555?type=carrier");
}
}

0 comments on commit ee5f4c9

Please sign in to comment.