Skip to content

Commit 8592c1b

Browse files
lornajaneMark Lewin
authored andcommitted
Add secret management snippets (Vonage#18)
* Tidy up existing README examples * Bump library version to get secret management support * Add secret management code snippets * Update README.md
1 parent fef3f34 commit 8592c1b

File tree

7 files changed

+108
-35
lines changed

7 files changed

+108
-35
lines changed

.env-example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ APPLICATION_ID=635c2797-9295-4cdf-9232-d275f75ff096
44
PRIVATE_KEY=private.key
55
FROM=
66
TO_NUMBER=
7-
8-
# Number Insight building blocks
7+
NEXMO_SECRET_ID=
98
INSIGHT_NUMBER=

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,25 @@ For some of the examples you will need to [buy a number](https://dashboard.nexmo
3535

3636
| Code Sample |
3737
| ---------------------------------------- |
38-
| Send Phone Verification Code | [verify/request.php] |
39-
| Check Phone Verification Code | [verify/verify.php] |
40-
| Cancel Phone Verification | [verify/cancel.php] |
38+
| [Send Phone Verification Code](verify/request.php) |
39+
| [Check Phone Verification Code](verify/verify.php) |
40+
| [Cancel Phone Verification](verify/cancel.php) |
4141

42+
### Secret Management
4243

44+
| Code Sample |
45+
| ---------------------------------------- |
46+
| [List Secrets](secret-management/fetch-secrets.php) |
47+
| [Get a Secret](secret-management/get-a-secret.php) |
48+
| [Create a Secret](secret-management/create-a-secret.php) |
49+
| [Delete a Secret](secret-management/delete-a-secret.php) |
4350

4451
## Request More Examples
4552

4653
Please [raise an issue](/../../issues/) to request an example that isn't present within the quickstart. Pull requests will be gratefully received.
4754

4855
## Licenses
4956

50-
- The code samples in this repo is under [MIT](LICENSE)
57+
- The sample code in this repo is licensed under [MIT](LICENSE)
5158

52-
59+

composer.lock

Lines changed: 39 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
require_once __DIR__ . '/../config.php';
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
$basic = new \Nexmo\Client\Credentials\Basic($_ENV['NEXMO_API_KEY'], $_ENV['NEXMO_API_SECRET']);
6+
$client = new \Nexmo\Client($basic);
7+
8+
// set an environment variable API_KEY to work with secrets for a secondary key
9+
$api_key = isset($_ENV['API_KEY']) ? $_ENV['API_KEY'] : $_ENV['NEXMO_API_KEY'];
10+
$secret = 'awes0meNewSekret!!;';
11+
12+
$client->account()->createSecret($api_key, $secret);
13+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
require_once __DIR__ . '/../config.php';
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
$basic = new \Nexmo\Client\Credentials\Basic($_ENV['NEXMO_API_KEY'], $_ENV['NEXMO_API_SECRET']);
6+
$client = new \Nexmo\Client($basic);
7+
8+
// set an environment variable API_KEY to work with secrets for a secondary key
9+
$api_key = isset($_ENV['API_KEY']) ? $_ENV['API_KEY'] : $_ENV['NEXMO_API_KEY'];
10+
11+
try {
12+
$response = $client->account()->deleteSecret($api_key, $_ENV['NEXMO_SECRET_ID']);
13+
echo "OK\n";
14+
} catch(\Nexmo\Client\Exception\Request $e) {
15+
echo $e->getMessage();
16+
}
17+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
require_once __DIR__ . '/../config.php';
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
$basic = new \Nexmo\Client\Credentials\Basic($_ENV['NEXMO_API_KEY'], $_ENV['NEXMO_API_SECRET']);
6+
$client = new \Nexmo\Client($basic);
7+
8+
// set an environment variable API_KEY to work with secrets for a secondary key
9+
$api_key = isset($_ENV['API_KEY']) ? $_ENV['API_KEY'] : $_ENV['NEXMO_API_KEY'];
10+
11+
$response = $client->account()->listSecrets($api_key);
12+
foreach($response['secrets'] as $secret) {
13+
echo "ID: " . $secret['id'] . " (created " . $secret['created_at'] .")\n";
14+
}

secret-management/get-a-secret.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
require_once __DIR__ . '/../config.php';
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
$basic = new \Nexmo\Client\Credentials\Basic($_ENV['NEXMO_API_KEY'], $_ENV['NEXMO_API_SECRET']);
6+
$client = new \Nexmo\Client($basic);
7+
8+
// set an environment variable API_KEY to work with secrets for a secondary key
9+
$api_key = isset($_ENV['API_KEY']) ? $_ENV['API_KEY'] : $_ENV['NEXMO_API_KEY'];
10+
11+
$secret = $client->account()->getSecret($api_key, $_ENV['NEXMO_SECRET_ID']);
12+
echo "ID: " . $secret['id'] . " (created " . $secret['created_at'] .")\n";

0 commit comments

Comments
 (0)