Skip to content

Commit

Permalink
Remove username andd password from Demo files and added support of JWT
Browse files Browse the repository at this point in the history
  • Loading branch information
SushilMallRC committed Aug 5, 2024
1 parent 69a4f0d commit 79fb87c
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 112 deletions.
14 changes: 6 additions & 8 deletions demo/_credentialsSample.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<?php

return array(
'username' => '18881112233', // your RingCentral account phone number
'extension' => null, // or number
'password' => 'yourPassword',
'clientId' => 'yourClientId',
'clientId' => 'yourClientId',
'clientSecret' => 'yourClientSecret',
'server' => 'https://platform.ringcentral.com', // for production - https://platform.ringcentral.com
'smsNumber' => '18882223344', // any of SMS-enabled numbers on your RingCentral account
'server' => 'https://platform.ringcentral.com', // for production - https://platform.ringcentral.com
'smsNumber' => '18882223344', // any of SMS-enabled numbers on your RingCentral account
'mobileNumber' => '16501112233', // your own mobile number to which script will send sms
'dateFrom' => 'yyyy-mm-dd', // dateFrom
'dateTo' => 'yyyy-mm-dd' // dateTo
'dateFrom' => 'yyyy-mm-dd', // dateFrom
'dateTo' => 'yyyy-mm-dd', // dateTo
"RC_JWT" => 'JWT'
);
6 changes: 3 additions & 3 deletions demo/authData.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

require_once(__DIR__ . '/_bootstrap.php');
require_once (__DIR__ . '/_bootstrap.php');

use RingCentral\SDK\SDK;

// Create SDK instance

$credentials = require(__DIR__ . '/_credentials.php');
$credentials = require (__DIR__ . '/_credentials.php');

$rcsdk = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');

Expand Down Expand Up @@ -40,7 +40,7 @@

print 'Auth exception: ' . $e->getMessage() . PHP_EOL;

$auth = $platform->login($credentials['username'], $credentials['extension'], $credentials['password']);
$auth = $platform->login(["jwt" => $credentials['RC_JWT']]);

print 'Authorized' . PHP_EOL;

Expand Down
91 changes: 46 additions & 45 deletions demo/callRecording.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

require_once(__DIR__ . '/_bootstrap.php');
require_once (__DIR__ . '/_bootstrap.php');

use RingCentral\SDK\SDK;



// Create SDK instance

$credentials = require(__DIR__ . '/_credentials.php');
$credentials = require (__DIR__ . '/_credentials.php');


$rcsdk = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');
Expand All @@ -17,78 +17,79 @@

// Authorize

$platform->login($credentials['username'], $credentials['extension'], $credentials['password'], true);
$platform->login(["jwt" => $credentials['RC_JWT']]);

// Find call log records with recordings

$callLogRecords = $platform->get('/account/~/extension/~/call-log', array(
'type' => 'Voice',
'withRecording' => 'True',
'dateFrom' => $credentials['dateFrom'],
'dateTo' => $credentials['dateTo']))
->json()->records;
'type' => 'Voice',
'withRecording' => 'True',
'dateFrom' => $credentials['dateFrom'],
'dateTo' => $credentials['dateTo']
)
)
->json()->records;

// Create a CSV file to log the records

$status = "Success";
$dir = $credentials['dateFrom'];
$fname = "recordings_${dir}.csv";
$fdir = "/Recordings/${dir}";
$status = "Success";
$dir = $credentials['dateFrom'];
$fname = "recordings_${dir}.csv";
$fdir = "/Recordings/${dir}";

if (is_dir($fdir) === false)
{
mkdir($fdir, 0777, true);
}
if (is_dir($fdir) === false) {
mkdir($fdir, 0777, true);
}

$file = fopen($fname,'w');
$file = fopen($fname, 'w');

$fileHeaders = array("RecordingID","ContentURI","Filename","DownloadStatus");
$fileHeaders = array("RecordingID", "ContentURI", "Filename", "DownloadStatus");

fputcsv($file, $fileHeaders);
fputcsv($file, $fileHeaders);

$fileContents = array();
$fileContents = array();


$timePerRecording = 6;
$timePerRecording = 6;

foreach ($callLogRecords as $i => $callLogRecord) {
foreach ($callLogRecords as $i => $callLogRecord) {

$id = $callLogRecord->recording->id;
$id = $callLogRecord->recording->id;


$uri = $callLogRecord->recording->contentUri;
$uri = $callLogRecord->recording->contentUri;


$apiResponse = $platform->get($callLogRecord->recording->contentUri);
$apiResponse = $platform->get($callLogRecord->recording->contentUri);

$ext = ($apiResponse->response()->getHeader('Content-Type')[0] == 'audio/mpeg')
? 'mp3' : 'wav';
$ext = ($apiResponse->response()->getHeader('Content-Type')[0] == 'audio/mpeg')
? 'mp3' : 'wav';

$start = microtime(true);
$start = microtime(true);

file_put_contents("${fdir}/recording_${id}.${ext}", $apiResponse->raw());
file_put_contents("${fdir}/recording_${id}.${ext}", $apiResponse->raw());

$filename = "recording_${id}.${ext}";
$filename = "recording_${id}.${ext}";

if(filesize("${fdir}/recording_${id}.${ext}") == 0) {
$status = "failure";
}
if (filesize("${fdir}/recording_${id}.${ext}") == 0) {
$status = "failure";
}

file_put_contents("${fdir}/recording_${id}.json", json_encode($callLogRecord));
file_put_contents("${fdir}/recording_${id}.json", json_encode($callLogRecord));

$end=microtime(true);
$end = microtime(true);

// Check if the recording completed wihtin 6 seconds.
$time = ($end*1000 - $start * 1000);
if($time < $timePerRecording) {
sleep($timePerRecording-$time);
}
// Check if the recording completed wihtin 6 seconds.
$time = ($end * 1000 - $start * 1000);
if ($time < $timePerRecording) {
sleep($timePerRecording - $time);
}

$fileContents = array($id, $uri, $filename, $status);
fputcsv($file, $fileContents);
$fileContents = array($id, $uri, $filename, $status);
fputcsv($file, $fileContents);

}
}

fclose($file);
fclose($file);

?>
?>
6 changes: 3 additions & 3 deletions demo/doubleRefresh.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php

require_once(__DIR__ . '/_bootstrap.php');
require_once (__DIR__ . '/_bootstrap.php');

use RingCentral\SDK\SDK;

// Create SDK instance

$credentials = require(__DIR__ . '/_credentials.php');
$credentials = require (__DIR__ . '/_credentials.php');

$rcsdk1 = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');
$rcsdk2 = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');

$platform1 = $rcsdk1->platform();
$platform2 = $rcsdk2->platform();

$platform1->login($credentials['username'], $credentials['extension'], $credentials['password']);
$platform1->login(["jwt" => $credentials['RC_JWT']]);

print 'Platform1 Authorized' . PHP_EOL;

Expand Down
8 changes: 4 additions & 4 deletions demo/errorHandling.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

require_once(__DIR__ . '/_bootstrap.php');
require_once (__DIR__ . '/_bootstrap.php');

use RingCentral\SDK\Http\ApiException;
use RingCentral\SDK\SDK;


// Create SDK instance

$credentials = require(__DIR__ . '/_credentials.php');
$credentials = require (__DIR__ . '/_credentials.php');

$rcsdk = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');

$platform = $rcsdk->platform();

// Authorize

$platform->login($credentials['username'], $credentials['extension'], $credentials['password']);
$platform->login(["jwt" => $credentials['RC_JWT']]);

// Load something nonexistent

Expand All @@ -26,7 +26,7 @@

} catch (ApiException $e) {

$message = $e->getMessage() . ' (from backend) at URL ' . (string)$e->apiResponse()->request()->getUri();
$message = $e->getMessage() . ' (from backend) at URL ' . (string) $e->apiResponse()->request()->getUri();

print 'Expected HTTP Error: ' . $message . PHP_EOL;

Expand Down
8 changes: 4 additions & 4 deletions demo/extensions.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php

require_once(__DIR__ . '/_bootstrap.php');
require_once (__DIR__ . '/_bootstrap.php');

use RingCentral\SDK\SDK;

// Create SDK instance

$credentials = require(__DIR__ . '/_credentials.php');
$credentials = require (__DIR__ . '/_credentials.php');

$rcsdk = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');

$platform = $rcsdk->platform();

// Authorize

$platform->login($credentials['username'], $credentials['extension'], $credentials['password']);
$platform->login(["jwt" => $credentials['RC_JWT']]);

// Load extensions

Expand All @@ -25,7 +25,7 @@
// Load presence

$presences = $platform->get('/account/~/extension/' . $extensions[0]->id . ',' . $extensions[0]->id . '/presence')
->multipart();
->multipart();

print 'Presence loaded ' .
$extensions[0]->name . ' - ' . $presences[0]->json()->presenceStatus . ', ' .
Expand Down
26 changes: 14 additions & 12 deletions demo/fax.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
<?php

require_once(__DIR__ . '/_bootstrap.php');
require_once (__DIR__ . '/_bootstrap.php');

use RingCentral\SDK\SDK;

// Create SDK instance

$credentials = require(__DIR__ . '/_credentials.php');
$credentials = require (__DIR__ . '/_credentials.php');

$rcsdk = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');

$platform = $rcsdk->platform();

// Authorize

$platform->login($credentials['username'], $credentials['extension'], $credentials['password']);
$platform->login(["jwt" => $credentials['RC_JWT']]);

// Send Fax

$request = $rcsdk->createMultipartBuilder()
->setBody(array(
'to' => array(
array('phoneNumber' => $credentials['username']),
),
'faxResolution' => 'High',
))
->add('Plain Text', 'file.txt')
->add(fopen('https://developers.ringcentral.com/assets/images/ico_case_crm.png', 'r'))
->request('/account/~/extension/~/fax');
->setBody(
array(
'to' => array(
array('phoneNumber' => $credentials['username']),
),
'faxResolution' => 'High',
)
)
->add('Plain Text', 'file.txt')
->add(fopen('https://developers.ringcentral.com/assets/images/ico_case_crm.png', 'r'))
->request('/account/~/extension/~/fax');

//print $request->getBody() . PHP_EOL;

Expand Down
24 changes: 13 additions & 11 deletions demo/mms.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php

require_once(__DIR__ . '/_bootstrap.php');
require_once (__DIR__ . '/_bootstrap.php');

use RingCentral\SDK\SDK;

// Create SDK instance

$credentials = require(__DIR__ . '/_credentials.php');
$credentials = require (__DIR__ . '/_credentials.php');

$rcsdk = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');

$platform = $rcsdk->platform();

// Authorize

$platform->login($credentials['username'], $credentials['extension'], $credentials['password']);
$platform->login(["jwt" => $credentials['RC_JWT']]);

// Find SMS-enabled phone number that belongs to extension

Expand All @@ -39,14 +39,16 @@
// Send Fax

$request = $rcsdk->createMultipartBuilder()
->setBody(array(
'from' => array('phoneNumber' => $smsNumber),
'to' => array(
array('phoneNumber' => $credentials['mobileNumber']),
),
))
->add(fopen('https://developers.ringcentral.com/assets/images/ico_case_crm.png', 'r'))
->request('/account/~/extension/~/sms');
->setBody(
array(
'from' => array('phoneNumber' => $smsNumber),
'to' => array(
array('phoneNumber' => $credentials['mobileNumber']),
),
)
)
->add(fopen('https://developers.ringcentral.com/assets/images/ico_case_crm.png', 'r'))
->request('/account/~/extension/~/sms');

//print $request->getBody() . PHP_EOL;

Expand Down
Loading

0 comments on commit 79fb87c

Please sign in to comment.