private function connectToLiveServer($server) { $sdk = new SDK('foo', 'bar', $server); $platform = $sdk->getPlatform(); $res = $platform->apiCall(new Request('GET', ''), false)->getJson(); $this->assertEquals('v1.0', $res->uriString); }
protected function getSDK($authorized = true) { date_default_timezone_set('UTC'); $sdk = new SDK('whatever', 'whatever', 'https://whatever', 'SDKTests', SDK::VERSION, $authorized, $authorized); if ($authorized) { $sdk->mockRegistry()->authenticationMock(); $sdk->platform()->login('18881112233', null, 'password'); } return $sdk; }
protected function getSDK($authorized = true) { date_default_timezone_set('UTC'); $sdk = new SDK('whatever', 'whatever', 'https://whatever'); if ($authorized) { $sdk->getPubnubFactory()->useMock(true); $sdk->getClient()->useMock(true)->getMockRegistry()->add(new AuthenticationMock()); $sdk->getPlatform()->authorize('18881112233', null, 'password', true); } return $sdk; }
<?php require_once __DIR__ . '/_bootstrap.php'; use RingCentral\SDK\SDK; // Create SDK instance $credentials = (require __DIR__ . '/_credentials.php'); $rcsdk = new SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server'], 'Demo', '1.0.0'); $platform = $rcsdk->platform(); // Authorize $platform->login($credentials['username'], $credentials['extension'], $credentials['password'], true); // 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; // Create a CSV file to log the records $status = "Success"; $dir = $credentials['dateFrom']; $fname = "recordings_{$dir}.csv"; $fdir = "/Recordings/{$dir}"; if (is_dir($fdir) === false) { mkdir($fdir, 0777, true); } $file = fopen($fname, 'w'); $fileHeaders = array("RecordingID", "ContentURI", "Filename", "DownloadStatus"); fputcsv($file, $fileHeaders); $fileContents = array(); $timePerRecording = 6; foreach ($callLogRecords as $i => $callLogRecord) { $id = $callLogRecord->recording->id; $uri = $callLogRecord->recording->contentUri; $apiResponse = $platform->get($callLogRecord->recording->contentUri); $ext = $apiResponse->response()->getHeader('Content-Type')[0] == 'audio/mpeg' ? 'mp3' : 'wav'; $start = microtime(true);
<?php require_once __DIR__ . '/_bootstrap.php'; use RingCentral\SDK\SDK; // Create SDK instance $credentials = (require __DIR__ . '/_credentials.php'); $rcsdk = new SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server'], 'Demo', '1.0.0'); $platform = $rcsdk->platform(); // Authorize $platform->login($credentials['username'], $credentials['extension'], $credentials['password']); // Find Fax-enabled phone number that belongs to extension $phoneNumbers = $platform->get('/account/~/extension/~/phone-number', array('perPage' => 'max'))->json()->records; print 'Fax Phone Number: ' . $credentials['username'] . PHP_EOL; // 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'); //print $request->getBody() . PHP_EOL; $response = $platform->sendRequest($request); print 'Sent Fax ' . $response->json()->uri . PHP_EOL;
private function connectToLiveServer($server) { $sdk = new SDK('foo', 'bar', $server); $res = $sdk->platform()->get('', array(), array(), array('skipAuthCheck' => true))->json(); $this->assertEquals('v1.0', $res->uriString); }
<?php require_once __DIR__ . '/_bootstrap.php'; use RingCentral\SDK\SDK; use RingCentral\SDK\Subscription\Events\NotificationEvent; use RingCentral\SDK\Subscription\Events\SuccessEvent; use RingCentral\SDK\Subscription\Subscription; $credentials = (require '_credentials.php'); $credentials = (require __DIR__ . '/_credentials.php'); $rcsdk = new SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server'], 'Demo', '1.0.0'); $platform = $rcsdk->platform(); // Authorize $platform->login($credentials['username'], $credentials['extension'], $credentials['password']); // Subscription $subscription = $rcsdk->createSubscription(); $subscription->addEvents(array('/account/~/extension/~/message-store', '/account/~/extension/~/presence')); $subscription->setKeepPolling(true); $subscription->addListener(Subscription::EVENT_NOTIFICATION, function (NotificationEvent $e) { print 'Notification' . print_r($e->payload(), true) . PHP_EOL; }); print 'Subscribing' . PHP_EOL; $subscription->addListener(Subscription::EVENT_TIMEOUT, function () { print 'Timeout' . PHP_EOL; }); $subscription->addListener(Subscription::EVENT_RENEW_SUCCESS, function (SuccessEvent $e) { print 'Renewed' . PHP_EOL; }); $subscription->register(); print 'End' . PHP_EOL;
<?php require_once __DIR__ . '/_bootstrap.php'; use RingCentral\SDK\SDK; $credentials = (require __DIR__ . '/_credentials.php'); // Create SDK instance $rcsdk = new SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server'], 'Demo', '1.0.0'); $platform = $rcsdk->getPlatform(); // Authorize $platform->authorize($credentials['username'], $credentials['extension'], $credentials['password'], true); // Load extensions $extensions = $platform->get('/account/~/extension', array('perPage' => 10))->getJson()->records; print 'Users loaded ' . count($extensions) . PHP_EOL; // Load presence $presences = $platform->get('/account/~/extension/' . $extensions[0]->id . ',' . $extensions[0]->id . '/presence')->getMultipart(); print 'Presence loaded ' . $extensions[0]->name . ' - ' . $presences[0]->getJson()->presenceStatus . ', ' . $extensions[0]->name . ' - ' . $presences[1]->getJson()->presenceStatus . PHP_EOL; print_r($platform->get('/account/~/extension', array('perPage' => 10))->getRequest());
<?php require_once __DIR__ . '/_bootstrap.php'; use RingCentral\SDK\SDK; // Create SDK instance $credentials = (require __DIR__ . '/_credentials.php'); $rcsdk1 = new SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server'], 'Demo', '1.0.0'); $rcsdk2 = new SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server'], 'Demo', '1.0.0'); $platform1 = $rcsdk1->platform(); $platform2 = $rcsdk2->platform(); $platform1->login($credentials['username'], $credentials['extension'], $credentials['password']); print 'Platform1 Authorized' . PHP_EOL; // Share P1 auth data with P2 $platform2->auth()->setData($platform1->auth()->data()); // Make first refresh $platform1->refresh(); try { // Attempt to make second refresh $platform2->refresh(); print 'Tokens should be identical' . PHP_EOL; print $platform1->auth()->accessToken() . PHP_EOL; print $platform2->auth()->accessToken() . PHP_EOL; } catch (\Exception $e) { print 'Failed to do double refresh: ' . $e->getMessage() . PHP_EOL; print $e->getTraceAsString() . PHP_EOL; $extension = $platform1->get('/account/~/extension/~')->json(); print 'Platform1 is still alive though: ' . $extension->name . PHP_EOL; }
<?php require_once __DIR__ . '/_bootstrap.php'; use RingCentral\SDK\SDK; use RingCentral\SDK\Subscription\Events\NotificationEvent; use RingCentral\SDK\Subscription\Subscription; $credentials = (require __DIR__ . '/_credentials.php'); // Create SDK instance $rcsdk = new SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server'], 'Demo', '1.0.0'); $platform = $rcsdk->getPlatform(); // Authorize $platform->authorize($credentials['username'], $credentials['extension'], $credentials['password'], true); // Subscription $subscription = $rcsdk->getSubscription(); $subscription->addEvents(array('/account/~/extension/~/message-store')); $subscription->setKeepPolling(false); $subscription->on(Subscription::EVENT_NOTIFICATION, function (NotificationEvent $e) { print 'Notification' . print_r($e->getPayload(), true) . PHP_EOL; }); print 'Subscribing' . PHP_EOL; $subscription->register(); print 'End' . PHP_EOL;