Skip to content

Commit 5ac7dd7

Browse files
lornajaneMark Lewin
authored andcommitted
Switch environment vars for constants (Vonage#19)
1 parent 8592c1b commit 5ac7dd7

File tree

5 files changed

+15
-22
lines changed

5 files changed

+15
-22
lines changed

.env-example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
NEXMO_API_KEY=
22
NEXMO_API_SECRET=
3-
APPLICATION_ID=635c2797-9295-4cdf-9232-d275f75ff096
4-
PRIVATE_KEY=private.key
3+
APPLICATION_ID=
4+
PRIVATE_KEY=
55
FROM=
66
TO_NUMBER=
77
NEXMO_SECRET_ID=

secret-management/create-a-secret.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
require_once __DIR__ . '/../config.php';
33
require_once __DIR__ . '/../vendor/autoload.php';
44

5-
$basic = new \Nexmo\Client\Credentials\Basic($_ENV['NEXMO_API_KEY'], $_ENV['NEXMO_API_SECRET']);
5+
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
66
$client = new \Nexmo\Client($basic);
77

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'];
108
$secret = 'awes0meNewSekret!!;';
119

12-
$client->account()->createSecret($api_key, $secret);
10+
$client->account()->createSecret(NEXMO_API_KEY, $secret);
1311

secret-management/delete-a-secret.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
require_once __DIR__ . '/../config.php';
33
require_once __DIR__ . '/../vendor/autoload.php';
44

5-
$basic = new \Nexmo\Client\Credentials\Basic($_ENV['NEXMO_API_KEY'], $_ENV['NEXMO_API_SECRET']);
5+
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
66
$client = new \Nexmo\Client($basic);
77

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-
118
try {
12-
$response = $client->account()->deleteSecret($api_key, $_ENV['NEXMO_SECRET_ID']);
9+
$response = $client->account()->deleteSecret(NEXMO_API_KEY, NEXMO_SECRET_ID);
1310
echo "OK\n";
1411
} catch(\Nexmo\Client\Exception\Request $e) {
1512
echo $e->getMessage();

secret-management/fetch-secrets.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
require_once __DIR__ . '/../config.php';
33
require_once __DIR__ . '/../vendor/autoload.php';
44

5-
$basic = new \Nexmo\Client\Credentials\Basic($_ENV['NEXMO_API_KEY'], $_ENV['NEXMO_API_SECRET']);
5+
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
66
$client = new \Nexmo\Client($basic);
77

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);
8+
$response = $client->account()->listSecrets(NEXMO_API_KEY);
129
foreach($response['secrets'] as $secret) {
1310
echo "ID: " . $secret['id'] . " (created " . $secret['created_at'] .")\n";
1411
}

secret-management/get-a-secret.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
require_once __DIR__ . '/../config.php';
33
require_once __DIR__ . '/../vendor/autoload.php';
44

5-
$basic = new \Nexmo\Client\Credentials\Basic($_ENV['NEXMO_API_KEY'], $_ENV['NEXMO_API_SECRET']);
5+
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
66
$client = new \Nexmo\Client($basic);
77

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";
8+
try {
9+
$secret = $client->account()->getSecret(NEXMO_API_KEY, NEXMO_SECRET_ID);
10+
echo "ID: " . $secret['id'] . " (created " . $secret['created_at'] .")\n";
11+
} catch (\Nexmo\Client\Exception\Request $e) {
12+
echo $e->getMessage();
13+
}

0 commit comments

Comments
 (0)