summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Twilio/Jwt/Grants/ProgrammableVoiceGrant.php148
-rw-r--r--Twilio/Tests/Unit/Jwt/AccessTokenTest.php28
2 files changed, 176 insertions, 0 deletions
diff --git a/Twilio/Jwt/Grants/ProgrammableVoiceGrant.php b/Twilio/Jwt/Grants/ProgrammableVoiceGrant.php
new file mode 100644
index 0000000..1f3da79
--- /dev/null
+++ b/Twilio/Jwt/Grants/ProgrammableVoiceGrant.php
@@ -0,0 +1,148 @@
+<?php
+
+
+namespace Twilio\Jwt\Grants;
+
+
+class ProgrammableVoiceGrant implements Grant {
+
+ private $outgoingApplicationSid;
+ private $outgoingApplicationParams;
+ private $pushCredentialSid;
+ private $endpointId;
+
+ /**
+ * Returns the outgoing application sid
+ *
+ * @return string the outgoing application sid
+ */
+ public function getOutgoingApplicationSid()
+ {
+ return $this->outgoingApplicationSid;
+ }
+
+ /**
+ * Set the outgoing application sid of the grant
+ *
+ * @param string $outgoingApplicationSid outgoing application sid of grant
+ *
+ * @return $this updated grant
+ */
+ public function setOutgoingApplicationSid($outgoingApplicationSid)
+ {
+ $this->outgoingApplicationSid = $outgoingApplicationSid;
+ return $this;
+ }
+
+ /**
+ * Returns the outgoing application params
+ *
+ * @return array the outgoing application params
+ */
+ public function getOutgoingApplicationParams()
+ {
+ return $this->outgoingApplicationParams;
+ }
+
+ /**
+ * Set the outgoing application of the the grant
+ *
+ * @param string $sid outgoing application sid of the grant
+ * @param string $params params to pass the the application
+ *
+ * @return $this updated grant
+ */
+ public function setOutgoingApplication($sid, $params) {
+ $this->outgoingApplicationSid = $sid;
+ $this->outgoingApplicationParams = $params;
+ return $this;
+ }
+
+ /**
+ * Returns the push credential sid
+ *
+ * @return string the push credential sid
+ */
+ public function getPushCredentialSid()
+ {
+ return $this->pushCredentialSid;
+ }
+
+ /**
+ * Set the push credential sid
+ *
+ * @param string $pushCredentialSid
+ *
+ * @return $this updated grant
+ */
+ public function setPushCredentialSid($pushCredentialSid)
+ {
+ $this->pushCredentialSid = $pushCredentialSid;
+ return $this;
+ }
+
+ /**
+ * Returns the endpoint id
+ *
+ * @return string the endpoint id
+ */
+ public function getEndpointId()
+ {
+ return $this->endpointId;
+ }
+
+ /**
+ * Set the endpoint id
+ *
+ * @param string $endpointId endpoint id
+ *
+ * @return $this updated grant
+ */
+ public function setEndpointId($endpointId)
+ {
+ $this->endpointId = $endpointId;
+ return $this;
+ }
+
+ /**
+ * Returns the grant type
+ *
+ * @return string type of the grant
+ */
+ public function getGrantKey()
+ {
+ return "programmable_voice";
+ }
+
+ /**
+ * Returns the grant data
+ *
+ * @return array data of the grant
+ */
+ public function getPayload()
+ {
+ $payload = array();
+ if ($this->outgoingApplicationSid) {
+ $outgoing = array();
+ $outgoing['application_sid'] = $this->outgoingApplicationSid;
+
+ if ($this->outgoingApplicationParams) {
+ $outgoing['params'] = $this->outgoingApplicationParams;
+ }
+
+ $payload['outgoing'] = $outgoing;
+ }
+
+ if ($this->pushCredentialSid) {
+ $payload['push_credential_sid'] = $this->pushCredentialSid;
+ }
+
+ if ($this->endpointId) {
+ $payload['endpoint_id'] = $this->endpointId;
+ }
+
+ return $payload;
+ }
+
+
+} \ No newline at end of file
diff --git a/Twilio/Tests/Unit/Jwt/AccessTokenTest.php b/Twilio/Tests/Unit/Jwt/AccessTokenTest.php
index 4bea715..287eb3c 100644
--- a/Twilio/Tests/Unit/Jwt/AccessTokenTest.php
+++ b/Twilio/Tests/Unit/Jwt/AccessTokenTest.php
@@ -4,6 +4,7 @@ namespace Twilio\Tests\Unit\Jwt;
use Twilio\Jwt\Grants\ConversationsGrant;
use Twilio\Jwt\Grants\IpMessagingGrant;
+use Twilio\Jwt\Grants\ProgrammableVoiceGrant;
use Twilio\Jwt\JWT;
use Twilio\Tests\Unit\UnitTest;
use Twilio\Jwt\AccessToken;
@@ -108,4 +109,31 @@ class AccessTokenTest extends UnitTest {
$this->assertEquals('{}', json_encode($payload->grants->ip_messaging));
}
+ function testProgrammableVoiceGrant() {
+ $scat = new AccessToken(self::ACCOUNT_SID, self::SIGNING_KEY_SID, 'secret');
+ $scat->setIdentity('test identity');
+
+ $pvg = new ProgrammableVoiceGrant();
+ $pvg->setOutgoingApplication('AP123', array('foo' => 'bar'));
+
+ $scat->addGrant($pvg);
+
+ $token = $scat->toJWT();
+
+ $this->assertNotNull($token);
+ $payload = JWT::decode($token, 'secret');
+ $this->validateClaims($payload);
+
+ $grants = json_decode(json_encode($payload->grants), true);
+ $this->assertEquals(2, count($grants));
+ $this->assertEquals('test identity', $payload->grants->identity);
+
+ $decodedGrant = $grants['programmable_voice'];
+ $outgoing = $decodedGrant['outgoing'];
+ $this->assertEquals('AP123', $outgoing['application_sid']);
+
+ $params = $outgoing['params'];
+ $this->assertEquals('bar', $params['foo']);
+ }
+
} \ No newline at end of file