Skip to content

Commit 4f0b97b

Browse files
Merge pull request Vonage#33 from Nexmo/application-snippets
Added snippets for Application endpoint
2 parents 34bab62 + bd91f81 commit 4f0b97b

File tree

5 files changed

+174
-0
lines changed

5 files changed

+174
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../config.php';
4+
require_once __DIR__ . '/../vendor/autoload.php';
5+
6+
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
7+
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
8+
9+
$applicationClient = new \Nexmo\Application\Client();
10+
$applicationClient->setClient($client);
11+
12+
try {
13+
$application = $applicationClient->create(
14+
[
15+
'name' => 'Sample PHP V2 Application',
16+
'capabilities' => [
17+
'voice' => [
18+
'webhooks' => [
19+
'answer_url' => [
20+
'address' => "https://example.com/webhooks/answer",
21+
'http_method' => "GET"
22+
],
23+
'event_url' => [
24+
'address' => "https://example.com/webhooks/event",
25+
'http_method' => "POST"
26+
]
27+
]
28+
],
29+
'messages' => [
30+
'webhooks' => [
31+
'inbound_url' => [
32+
'address' => "https://example.com/webhooks/inbound",
33+
'http_method' => "POST"
34+
],
35+
'status_url' => [
36+
'address' => "https://example.com/webhooks/status",
37+
'http_method' => "POST"
38+
]
39+
]
40+
],
41+
'rtc' => [
42+
'webhooks' => [
43+
'event_url' => [
44+
'address' => "https://example.com/webhooks/rtcevent",
45+
'http_method' => "POST"
46+
]
47+
]
48+
]
49+
]
50+
]
51+
);
52+
53+
error_log($application->getId());
54+
error_log($application->getName());
55+
} catch (\InvalidArgumentException $e) {
56+
error_log($e->getMessage());
57+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../config.php';
4+
require_once __DIR__ . '/../vendor/autoload.php';
5+
6+
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
7+
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
8+
9+
$applicationClient = new \Nexmo\Application\Client();
10+
$applicationClient->setClient($client);
11+
12+
try {
13+
$isDeleted = $applicationClient->delete(MESSAGES_APPLICATION_ID);
14+
15+
if ($isDeleted) {
16+
error_log("Deleted application " . MESSAGES_APPLICATION_ID);
17+
} else {
18+
error_log("Could not delete application " . MESSAGES_APPLICATION_ID);
19+
}
20+
} catch (\Nexmo\Client\Exception\Request $e) {
21+
error_log("There was a problem with the request: " . $e->getMessage());
22+
} catch (\Nexmo\Client\Exception\Server $e) {
23+
error_log("The server encounted an error: " . $e->getMessage());
24+
}

applications/get-application.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../config.php';
4+
require_once __DIR__ . '/../vendor/autoload.php';
5+
6+
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
7+
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
8+
9+
$applicationClient = new \Nexmo\Application\Client();
10+
$applicationClient->setClient($client);
11+
12+
try {
13+
$application = $applicationClient->get(MESSAGES_APPLICATION_ID);
14+
15+
error_log($application->getId());
16+
error_log($application->getName());
17+
} catch (\Nexmo\Client\Exception\Request $e) {
18+
error_log("There was a problem with the request: " . $e->getMessage());
19+
} catch (\Nexmo\Client\Exception\Server $e) {
20+
error_log("The server encounted an error: " . $e->getMessage());
21+
}

applications/list-applications.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../config.php';
4+
require_once __DIR__ . '/../vendor/autoload.php';
5+
6+
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
7+
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
8+
9+
$applicationClient = new \Nexmo\Application\Client();
10+
$applicationClient->setClient($client);
11+
12+
foreach ($applicationClient as $application) {
13+
error_log($application->getId());
14+
error_log($application->getName());
15+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../config.php';
4+
require_once __DIR__ . '/../vendor/autoload.php';
5+
6+
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
7+
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
8+
9+
$applicationClient = new \Nexmo\Application\Client();
10+
$applicationClient->setClient($client);
11+
12+
try {
13+
$application = $applicationClient->update([
14+
'name' => 'Sample PHP V2 Application',
15+
'capabilities' => [
16+
'voice' => [
17+
'webhooks' => [
18+
'answer_url' => [
19+
'address' => "https://example.com/webhooks/answer",
20+
'http_method' => "GET"
21+
],
22+
'event_url' => [
23+
'address' => "https://example.com/webhooks/event",
24+
'http_method' => "POST"
25+
]
26+
]
27+
],
28+
'messages' => [
29+
'webhooks' => [
30+
'inbound_url' => [
31+
'address' => "https://example.com/webhooks/inbound",
32+
'http_method' => "POST"
33+
],
34+
'status_url' => [
35+
'address' => "https://example.com/webhooks/status",
36+
'http_method' => "POST"
37+
]
38+
]
39+
],
40+
'rtc' => [
41+
'webhooks' => [
42+
'event_url' => [
43+
'address' => "https://example.com/webhooks/rtcevent",
44+
'http_method' => "POST"
45+
]
46+
]
47+
]
48+
]
49+
],
50+
MESSAGES_APPLICATION_ID
51+
);
52+
53+
error_log($application->getId());
54+
error_log($application->getName());
55+
} catch (\InvalidArgumentException $e) {
56+
error_log($e->getMessage());
57+
}

0 commit comments

Comments
 (0)