Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added snippets for Application endpoint
  • Loading branch information
dragonmantank committed Aug 22, 2019
commit bd91f819abe5ed7321b57cf57bf0baeb1705da77
57 changes: 57 additions & 0 deletions applications/create-application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

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));

$applicationClient = new \Nexmo\Application\Client();
$applicationClient->setClient($client);

try {
$application = $applicationClient->create(
[
'name' => 'Sample PHP V2 Application',
'capabilities' => [
'voice' => [
'webhooks' => [
'answer_url' => [
'address' => "https://example.com/webhooks/answer",
'http_method' => "GET"
],
'event_url' => [
'address' => "https://example.com/webhooks/event",
'http_method' => "POST"
]
]
],
'messages' => [
'webhooks' => [
'inbound_url' => [
'address' => "https://example.com/webhooks/inbound",
'http_method' => "POST"
],
'status_url' => [
'address' => "https://example.com/webhooks/status",
'http_method' => "POST"
]
]
],
'rtc' => [
'webhooks' => [
'event_url' => [
'address' => "https://example.com/webhooks/rtcevent",
'http_method' => "POST"
]
]
]
]
]
);

error_log($application->getId());
error_log($application->getName());
} catch (\InvalidArgumentException $e) {
error_log($e->getMessage());
}
24 changes: 24 additions & 0 deletions applications/delete-application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

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));

$applicationClient = new \Nexmo\Application\Client();
$applicationClient->setClient($client);

try {
$isDeleted = $applicationClient->delete(MESSAGES_APPLICATION_ID);

if ($isDeleted) {
error_log("Deleted application " . MESSAGES_APPLICATION_ID);
} else {
error_log("Could not delete application " . MESSAGES_APPLICATION_ID);
}
} catch (\Nexmo\Client\Exception\Request $e) {
error_log("There was a problem with the request: " . $e->getMessage());
} catch (\Nexmo\Client\Exception\Server $e) {
error_log("The server encounted an error: " . $e->getMessage());
}
21 changes: 21 additions & 0 deletions applications/get-application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

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));

$applicationClient = new \Nexmo\Application\Client();
$applicationClient->setClient($client);

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

error_log($application->getId());
error_log($application->getName());
} catch (\Nexmo\Client\Exception\Request $e) {
error_log("There was a problem with the request: " . $e->getMessage());
} catch (\Nexmo\Client\Exception\Server $e) {
error_log("The server encounted an error: " . $e->getMessage());
}
15 changes: 15 additions & 0 deletions applications/list-applications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

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));

$applicationClient = new \Nexmo\Application\Client();
$applicationClient->setClient($client);

foreach ($applicationClient as $application) {
error_log($application->getId());
error_log($application->getName());
}
57 changes: 57 additions & 0 deletions applications/update-application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

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));

$applicationClient = new \Nexmo\Application\Client();
$applicationClient->setClient($client);

try {
$application = $applicationClient->update([
'name' => 'Sample PHP V2 Application',
'capabilities' => [
'voice' => [
'webhooks' => [
'answer_url' => [
'address' => "https://example.com/webhooks/answer",
'http_method' => "GET"
],
'event_url' => [
'address' => "https://example.com/webhooks/event",
'http_method' => "POST"
]
]
],
'messages' => [
'webhooks' => [
'inbound_url' => [
'address' => "https://example.com/webhooks/inbound",
'http_method' => "POST"
],
'status_url' => [
'address' => "https://example.com/webhooks/status",
'http_method' => "POST"
]
]
],
'rtc' => [
'webhooks' => [
'event_url' => [
'address' => "https://example.com/webhooks/rtcevent",
'http_method' => "POST"
]
]
]
]
],
MESSAGES_APPLICATION_ID
);

error_log($application->getId());
error_log($application->getName());
} catch (\InvalidArgumentException $e) {
error_log($e->getMessage());
}