Skip to content

Commit

Permalink
Merge branch 'master' into number-priority
Browse files Browse the repository at this point in the history
  • Loading branch information
nixonsam committed Nov 17, 2020
2 parents df98e0b + 53c95a8 commit ed03c6a
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 25 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Change Log

## [v4.14.0](https://github.com/plivo/plivo-php/releases/tag/v4.14.0) - 2020-10-25
- Change Lookup API endpoint and response.

## [v4.13.0](https://github.com/plivo/plivo-php/releases/tag/v4.13.0) - 2020-10-13
- Add support to Guzzle HTTP client 7.
- Fix "issue-168", _Undefined index: from_number_ error - Retrieve Message Details API with Invalid message UUID.

## [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.

## [v4.11.0](https://github.com/plivo/plivo-php/releases/tag/v4.11.0) - 2020-08-25
- Add Powerpack for mms.

## [v4.10.0](https://github.com/plivo/plivo-php/releases/tag/v4.10.0) - 2020-08-03
- Add retries to multiple regions for voice requests.

Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

The Plivo PHP SDK makes it simpler to integrate communications into your PHP applications using the Plivo REST API. Using the SDK, you will be able to make voice calls, send SMS and generate Plivo XML to control your call flows.

**Supported PHP Versions**: This SDK works with PHP 7.1.0+.

## Installation

### To install Composer
Expand Down Expand Up @@ -66,7 +68,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.14.0

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

Expand Down Expand Up @@ -164,6 +166,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>");
```

### Generate Plivo XML

```php
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"source": "https://github.com/plivo/plivo-php"
},
"require": {
"guzzlehttp/guzzle": "^6.0",
"php": ">=7.1.0",
"guzzlehttp/guzzle": "^6.3 || ^7.0",
"firebase/php-jwt": "^5.2"
},
"autoload": {
Expand Down
12 changes: 11 additions & 1 deletion src/Plivo/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class BaseClient
const VOICE_BASE_API_URL = 'https://voice.plivo.com/';
const VOICE_BASE_API_FALLBACK_URL_1 = 'https://voice-usw1.plivo.com/';
const VOICE_BASE_API_FALLBACK_URL_2 = 'https://voice-use1.plivo.com/';
const LOOKUP_API_BASE_URL = 'https://lookup.plivo.com/';
/**
* @const Default timeout for request
*/
Expand All @@ -50,6 +51,8 @@ class BaseClient

public static $isVoiceRequest = false;

public static $isLookupRequest = false;

/**
* Instantiates a new BaseClient object.
*
Expand Down Expand Up @@ -175,7 +178,10 @@ public function sendRequest(PlivoRequest $request, $url = null)
elseif(static::$voiceRetryCount == 2){
$url = self::VOICE_BASE_API_FALLBACK_URL_2 . $request->getUrl();
}
}
}
if (static::$isLookupRequest) {
$url = self::LOOKUP_API_BASE_URL . $request->getUrl();
}
$timeout = $this->timeout ?: static::DEFAULT_REQUEST_TIMEOUT;

$plivoResponse =
Expand Down Expand Up @@ -210,6 +216,10 @@ public function fetch($uri, $params)
if (array_key_exists("isVoiceRequest", $params)){
static::$isVoiceRequest = true;
unset($params['isVoiceRequest']);
}
if (array_key_exists("isLookupRequest", $params)){
static::$isLookupRequest = true;
unset($params['isLookupRequest']);
}
$request =
new PlivoRequest(
Expand Down
5 changes: 4 additions & 1 deletion src/Plivo/HttpClients/PlivoGuzzleHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ public function send_request($url, $method, $body, $headers, $timeOut, $request)
$headers["Authorization"] = "Basic " . base64_encode("$this->authId:$this->authToken");
$request->setHeaders($headers);
$options =[];
$requestBody = json_encode($request->getParams(), JSON_FORCE_OBJECT);
$requestBody = json_encode($request->getParams());
if(empty($request->getParams())){
$requestBody = json_encode($request->getParams(), JSON_FORCE_OBJECT);
}
if (array_key_exists("isCallInsightsRequest", $request->getParams())) {
unset($request->getParams()['isCallInsightsRequest']);
$requestBody = $requestBody;
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 = "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,
['isLookupRequest' => true]
);

// returns a nested associative array and is better than subclassing
// from Resource class since there is no further use for client.
return $response->getContent();
}
}
5 changes: 1 addition & 4 deletions src/Plivo/Resources/Message/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ public function get($messageUuid)
$this->uri . $messageUuid .'/',
[]
);

return new Message(
$this->client, $response->getContent(),
$this->pathParams['authId'], $this->uri);
return json_encode($response->getContent(), JSON_FORCE_OBJECT);
}


Expand Down
28 changes: 23 additions & 5 deletions src/Plivo/Resources/Powerpack/Numbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@ public function get()
* Add an number
* @param string $uuid
* @param array optionalArgs
* + [string] service (Supported services are 'sms' and 'mms'. Defaults to 'sms' when not set)
* @return Response
*/
public function buy_add_number( $optionalArgs = [])
{
$data = [
'rent' => 'true'
];
$service = $optionalArgs['service'];
if (ArrayOperations::checkNull([$service])) {
$service = 'sms';
}
$data['service'] = $service;
$number = $optionalArgs['number'];
if (ArrayOperations::checkNull([$number])){
$country_iso = $optionalArgs['country_iso2'];
Expand Down Expand Up @@ -111,9 +117,12 @@ public function count( $optionalArgs = [])
/**
* Add an number
* @param string number
* @param array $optionalArgs
* Valid arguments
* + [string] service (Supported services are 'sms' and 'mms'. Defaults to 'sms' if not set)
* @return Response
*/
public function add( $number)
public function add( $number, $optionalArgs = [])
{
if (ArrayOperations::checkNull([$number])) {
throw
Expand All @@ -122,7 +131,7 @@ public function add( $number)
}
$response = $this->client->update(
$this->url . '/Number/' . $number . '/',
[]
$optionalArgs
);
return $response->getContent();

Expand Down Expand Up @@ -150,11 +159,14 @@ public function remove( $number, $optionalArgs = [])

/**
* @param $number
* * @param array $optionalArgs
* Valid arguments
* + [string] service (Supported services are 'sms' and 'mms'. Defaults to 'sms' if not set)
* @return Powerpack
*
* @throws PlivoValidationException
*/
public function find( $number)
public function find( $number, $optionalArgs = [])
{
if (ArrayOperations::checkNull([$number])) {
throw
Expand All @@ -163,12 +175,18 @@ public function find( $number)
}

$response = $this->client->fetch(
$this->url . '/Number/' . $number . '/', []
$this->url . '/Number/' . $number . '/', $optionalArgs
);
return $response->getContent();

}

/**
* @param array $optionalArgs
* Valid arguments
* + [string] service (Supported services are 'sms' and 'mms'. Defaults to 'sms' if not set)
* @return Response
*
*/
public function list( $optionalArgs = [])
{
$response = $this->client->fetch(
Expand Down
25 changes: 20 additions & 5 deletions src/Plivo/Resources/Powerpack/Powerpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function __construct(
* + [string] pattern
* + [string] country_iso
* + [string] type
* + [string] service (Supported services are 'sms' and 'mms'. Would list all numbers belonging to the pool, if not set)
* + [int] limit -
* + [int] offset -
* @return ResourceList output
Expand Down Expand Up @@ -144,11 +145,15 @@ public function find_tollfree($tollfree)

/**
* @param $number
* @param array $optionalArgs
* Valid arguments
* + [string] service (Supported services are 'sms' and 'mms'. Would search for both the services if not set)
* @return Powerpack
*
* @throws PlivoValidationException
*/
public function find_number( $number)
public function find_number( $number, $optionalArgs = [])
{
if (ArrayOperations::checkNull([$this->id])) {
throw
Expand All @@ -162,7 +167,7 @@ public function find_number( $number)
}

$response = $this->client->fetch(
$this->url . '/Number/' . $number . '/', []
$this->url . '/Number/' . $number . '/', $optionalArgs
);
return $response->getContent();

Expand Down Expand Up @@ -251,9 +256,12 @@ public function remove_shortcode( $shortcode, $optionalArgs = [])
/**
* Add an number
* @param string number
* @param array $optionalArgs
* Valid arguments
* + [string] service (Supported services are 'sms' and 'mms'. Default to 'sms' if not set.)
* @return Response
*/
public function add_number( $number)
public function add_number( $number, $optionalArgs = [])
{
if (ArrayOperations::checkNull([$number])) {
throw
Expand All @@ -262,7 +270,7 @@ public function add_number( $number)
}
$response = $this->client->update(
$this->url . '/Number/' . $number . '/',
[]
$optionalArgs
);
return $response->getContent();

Expand Down Expand Up @@ -310,7 +318,7 @@ public function update( array $optionalArgs = [])
}

$response = $this->client->update(
$this->powerpack_url .'Powerpack/' . $uuid .'/' ,
$this->powerpack_url .'Powerpack/' . $this->id .'/' ,
$optionalArgs
);

Expand Down Expand Up @@ -368,6 +376,7 @@ public function list_tollfree( $optionalArgs = [])
* + [string] pattern
* + [string] country_iso
* + [string] type
* + [string] service (Supported services are 'sms' and 'mms'. Would give count of all numbers belonging to the pool if not set.)
* $uuid -- powerpack uuid
* + [int] limit -
* + [int] offset -
Expand All @@ -392,13 +401,19 @@ public function count_numbers( $optionalArgs = [])
* Add an number
* @param string $uuid
* @param array optionalArgs
* + [string] service (Supported services are 'sms' and 'mms'. Defaults to 'sms' when not set)
* @return Response
*/
public function buy_add_number( $optionalArgs = [])
{
$data = [
'rent' => 'true'
];
$service = $optionalArgs['service'];
if (ArrayOperations::checkNull([$service])) {
$service = 'sms';
}
$data['service'] = $service;
$number = $optionalArgs['number'];
if (ArrayOperations::checkNull([$number])){
$country_iso = $optionalArgs['country_iso2'];
Expand Down
Loading

0 comments on commit ed03c6a

Please sign in to comment.