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

Swapped to Vonage namespace #50

Merged
merged 2 commits into from
Sep 9, 2020
Merged
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
18 changes: 9 additions & 9 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
NEXMO_API_KEY=
NEXMO_API_SECRET=
NEXMO_APPLICATION_ID=
NEXMO_APPLICATION_PRIVATE_KEY_PATH=
VONAGE_API_KEY=
VONAGE_API_SECRET=
VONAGE_APPLICATION_ID=
VONAGE_APPLICATION_PRIVATE_KEY_PATH=
FROM=
dragonmantank marked this conversation as resolved.
Show resolved Hide resolved
NEXMO_TO_NUMBER=
VONAGE_TO_NUMBER=
RECIPIENT_NUMBER=
TO_NUMBER=
NEXMO_SECRET_ID=
VONAGE_SECRET_ID=
INSIGHT_NUMBER=
SMS_CALLBACK_URL=

# Numbers API examples
NEXMO_NUMBER=447700900001
NEXMO_NUMBER_TYPE=mobile-lvn
NEXMO_NUMBER_FEATURES=VOICE,SMS
VONAGE_NUMBER=447700900001
VONAGE_NUMBER_TYPE=mobile-lvn
VONAGE_NUMBER_FEATURES=VOICE,SMS
COUNTRY_CODE=GB
NUMBER_SEARCH_PATTERN=1
NUMBER_SEARCH_CRITERIA=234
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Nexmo APIs Quickstart Examples for PHP
# Vonage APIs Quickstart Examples for PHP

<img src="https://developer.nexmo.com/assets/images/Vonage_Nexmo.svg" height="48px" alt="Nexmo is now known as Vonage" />

Expand All @@ -8,21 +8,21 @@ Quickstarts also available for [Java](https://github.com/nexmo/nexmo-java-code-s

## Setup

These code samples are meant to be used for [https://developer.nexmo.com/](https://developer.nexmo.com/), and are structured in such a way as to be used for internal testing. Developers are free to use these code snippets as a reference, but these may require changes to be worked into your specific application. We recommend checking out the [Nexmo Developer Website](https://developer.nexmo.com/), which displays these code snippets in a more copy/paste fashion.
These code samples are meant to be used for [https://developer.nexmo.com/](https://developer.nexmo.com/), and are structured in such a way as to be used for internal testing. Developers are free to use these code snippets as a reference, but these may require changes to be worked into your specific application. We recommend checking out the [Vonage Developer Website](https://developer.nexmo.com/), which displays these code snippets in a more copy/paste fashion.

If you would like to run these examples yourself, you will need to do the following:

1. Run `composer install` in the root of the repository
2. Copy `.env-example` to `.env`
3. Edit `.env` with your Nexmo credentials
3. Edit `.env` with your Vonage credentials

From there, you can fill out the various environment variables as detailed by the individual code snippet. Some snippets may share common environment variables.

Larger or more complex snippets may include their own `composer.json` file and have additional requirements. Please check any READMEs inside of the larger examples for setup instructions.

## Configure with Your Nexmo API Keys
## Configure with Your Vonage API Keys

To use this sample you will first need a [Nexmo account](https://dashboard.nexmo.com/sign-up). Once you have your own API credentials, rename
To use this sample you will first need a [Vonage account](https://dashboard.nexmo.com/sign-up). Once you have your own API credentials, rename
the `.env-example` file to `.env` and set the values as required.

For some of the examples, you will need to [buy a number](https://dashboard.nexmo.com/buy-numbers).
Expand Down
4 changes: 2 additions & 2 deletions account/account-balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

$response = $client->account()->getBalance();
echo round($response->getBalance(), 2) . " EUR\n";
4 changes: 2 additions & 2 deletions account/configure-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

$response = $client->account()->updateConfig([
"sms_callback_url" => SMS_CALLBACK_URL
Expand Down
4 changes: 2 additions & 2 deletions applications/create-application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic));

try {
$application = new Nexmo\Application\Application();
Expand Down
8 changes: 4 additions & 4 deletions applications/delete-application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic));

try {
$isDeleted = $client->applications()->delete(MESSAGES_APPLICATION_ID);
Expand All @@ -14,8 +14,8 @@
} else {
echo "Could not delete application " . MESSAGES_APPLICATION_ID . PHP_EOL;
dragonmantank marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (\Nexmo\Client\Exception\Request $e) {
} catch (\Vonage\Client\Exception\Request $e) {
echo "There was a problem with the request: " . $e->getMessage() . PHP_EOL;
} catch (\Nexmo\Client\Exception\Server $e) {
} catch (\Vonage\Client\Exception\Server $e) {
echo "The server encounted an error: " . $e->getMessage() . PHP_EOL;
}
8 changes: 4 additions & 4 deletions applications/get-application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic));

try {
$application = $client->applications()->get(MESSAGES_APPLICATION_ID);

echo $application->getId() . PHP_EOL;
echo $application->getName() . PHP_EOL;
} catch (\Nexmo\Client\Exception\Request $e) {
} catch (\Vonage\Client\Exception\Request $e) {
echo "There was a problem with the request: " . $e->getMessage() . PHP_EOL;
} catch (\Nexmo\Client\Exception\Server $e) {
} catch (\Vonage\Client\Exception\Server $e) {
echo "The server encounted an error: " . $e->getMessage() . PHP_EOL;
}
4 changes: 2 additions & 2 deletions applications/list-applications.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic));

foreach ($client->applications() as $application) {
echo sprintf("%s: %s\n", $application->getId(), $application->getName());
Expand Down
4 changes: 2 additions & 2 deletions applications/update-application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic));

try {
$application = $client->applications()->get(MESSAGES_APPLICATION_ID);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"nexmo/client": "^2.0",
"vonage/client": "^2.3",
"vlucas/phpdotenv": "^2.5"
}
}
8 changes: 4 additions & 4 deletions initialize/application.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

$keypair = new \Nexmo\Client\Credentials\Keypair(
file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH),
NEXMO_APPLICATION_ID
$keypair = new \Vonage\Client\Credentials\Keypair(
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
VONAGE_APPLICATION_ID
);

$client = new \Nexmo\Client($keypair);
$client = new \Vonage\Client($keypair);
4 changes: 2 additions & 2 deletions initialize/basic.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);
10 changes: 5 additions & 5 deletions initialize/full.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);

$keypair = new \Nexmo\Client\Credentials\Keypair(
file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH),
NEXMO_APPLICATION_ID
$keypair = new \Vonage\Client\Credentials\Keypair(
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
VONAGE_APPLICATION_ID
);

$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic, $keypair));
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic, $keypair));
8 changes: 4 additions & 4 deletions number-insights/advanced-async-trigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

$options = getopt('n:c:h');

Expand Down Expand Up @@ -45,10 +45,10 @@
try {
$client->insights()->advancedAsync(SEARCH_NUMBER, CALLBACK_WEBHOOK);
echo "The number will be looked up soon.";
} catch (\Nexmo\Client\Exception\Request $e) {
} catch (\Vonage\Client\Exception\Request $e) {
error_log("Client error: " . $e->getMessage());
exit(1);
} catch (\Nexmo\Client\Exception\Server $e) {
} catch (\Vonage\Client\Exception\Server $e) {
error_log("Server error: " . $e->getMessage());
exit(1);
}
4 changes: 2 additions & 2 deletions number-insights/advanced-cnam.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

$insights = $client->insights()->advancedCnam(INSIGHT_NUMBER);

Expand Down
4 changes: 2 additions & 2 deletions number-insights/advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

$insights = $client->insights()->advanced(INSIGHT_NUMBER);

Expand Down
4 changes: 2 additions & 2 deletions number-insights/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

$insights = $client->insights()->basic(INSIGHT_NUMBER);

Expand Down
4 changes: 2 additions & 2 deletions number-insights/standard-cnam.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

$insights = $client->insights()->standardCnam(INSIGHT_NUMBER);

Expand Down
4 changes: 2 additions & 2 deletions number-insights/standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

$insights = $client->insights()->standard(INSIGHT_NUMBER);

Expand Down
6 changes: 3 additions & 3 deletions numbers/cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

try {
$client->numbers()->cancel(NEXMO_NUMBER);
$client->numbers()->cancel(VONAGE_NUMBER);
echo "Number cancelled";
}

Expand Down
6 changes: 3 additions & 3 deletions numbers/list-owned.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

try {
$filter = new \Nexmo\Numbers\Filter\OwnedNumbers();
$filter = new \Vonage\Numbers\Filter\OwnedNumbers();
$filter
->setPattern((int) NUMBER_SEARCH_CRITERIA)
->setSearchPattern((int) NUMBER_SEARCH_PATTERN)
Expand Down
6 changes: 3 additions & 3 deletions numbers/purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

try {
$client->numbers()->purchase(NEXMO_NUMBER, COUNTRY_CODE);
$client->numbers()->purchase(VONAGE_NUMBER, COUNTRY_CODE);
echo "Number purchased";
} catch (Exception $e) {
echo "Error purchasing number";
Expand Down
12 changes: 6 additions & 6 deletions numbers/search-available.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php

use Nexmo\Numbers\Filter\AvailableNumbers;
use Nexmo\Entity\IterableAPICollection;
use Vonage\Numbers\Filter\AvailableNumbers;
use Vonage\Entity\IterableAPICollection;
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

/** @var IterableAPICollection $response */
$filter = new AvailableNumbers([
"pattern" => (int) NUMBER_SEARCH_CRITERIA,
dragonmantank marked this conversation as resolved.
Show resolved Hide resolved
"search_pattern" => (int) NUMBER_SEARCH_PATTERN,
"type" => NEXMO_NUMBER_TYPE,
"features" => NEXMO_NUMBER_FEATURES,
"type" => VONAGE_NUMBER_TYPE,
"features" => VONAGE_NUMBER_FEATURES,
]);
$response = $client->numbers()->searchAvailable(COUNTRY_CODE, $filter);
dragonmantank marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
8 changes: 4 additions & 4 deletions numbers/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

try {
$number = $client->numbers()->get(NEXMO_NUMBER);
$number->setAppId(NEXMO_APPLICATION_ID);
$number = $client->numbers()->get(VONAGE_NUMBER);
$number->setAppId(VONAGE_APPLICATION_ID);
$client->numbers()->update($number);
echo "Number updated" . PHP_EOL;

Expand Down
6 changes: 3 additions & 3 deletions redact/transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

// This request returns a 204 on success, and throws on error
$client->redact()->transaction(NEXMO_REDACT_ID, NEXMO_REDACT_TYPE);
$client->redact()->transaction(VONAGE_REDACT_ID, VONAGE_REDACT_TYPE);
6 changes: 3 additions & 3 deletions secret-management/create-a-secret.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

$secret = 'awes0meNewSekret!!;';

$client->account()->createSecret(NEXMO_API_KEY, $secret);
$client->account()->createSecret(VONAGE_API_KEY, $secret);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snippet does not work, and it appears that there's a bug in the SDK causing it to throw a not very helpful error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to that instance bug with the accounts API. This should be fixed in Vonage/vonage-php-sdk-core#248 but hasn't been released yet as we found it right after 2.3.1 was cut.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed this works with v2.3.2 which was just released, but please double-check.


Loading