<?php require_once __DIR__ . '/_bootstrap.php'; use RingCentral\http\HttpException; use RingCentral\http\Response; use RingCentral\SDK; $credentials = (require __DIR__ . '/_credentials.php'); // Create SDK instance $rcsdk = new SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server']); $platform = $rcsdk->getPlatform(); // Authorize $platform->authorize($credentials['username'], $credentials['extension'], $credentials['password'], true); // Load something nonexistent try { $platform->get('/account/~/whatever'); } catch (HttpException $e) { $response = $e->getResponse(); if ($response instanceof Response) { // Response has been received $message = $response->getError() . ' (from backend) at URL ' . $e->getRequest()->getUrl(); } else { // No response received, request failed to start $message = $e->getMessage(); } print 'Expected HTTP Error: ' . $message . PHP_EOL; }
protected function getSDK($authorized = true) { date_default_timezone_set('UTC'); $sdk = new SDK('whatever', 'whatever', 'https://whatever'); $context = $sdk->getContext(); $context->usePubnubStub(true)->useRequestStub(true); if ($authorized) { $context->getMocks()->add(new AuthenticationMock()); $sdk->getPlatform()->authorize('18881112233', null, 'password', true); } return $sdk; }
<?php require_once __DIR__ . '/_bootstrap.php'; use RingCentral\SDK; use RingCentral\subscription\events\NotificationEvent; use RingCentral\subscription\Subscription; $credentials = (require __DIR__ . '/_credentials.php'); // Create SDK instance $rcsdk = new SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server']); $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;
public function testConstructor() { $sdk = new SDK('foo', 'bar', 'baz'); $this->assertNotEquals($sdk->getPlatform(), null); }