-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.php
79 lines (74 loc) · 2.62 KB
/
engine.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use RingCentral\SDK\Http\HttpException;
use RingCentral\SDK\Http\ApiResponse;
use RingCentral\SDK\SDK;
session_start();
if (isset($_SESSION['env'])){
$env_file = $_SESSION['env'];
$dotenv = new Dotenv\Dotenv(__DIR__, $env_file);
$dotenv->load();
}else{
unset($_SESSION['tokens']);
header("Location: http://localhost:5000");
exit();
}
$rcsdk = new SDK(getenv('RC_CLIENT_ID'), getenv('RC_CLIENT_SECRET'), getenv('RC_SERVER_URL'));
$platform = $rcsdk->platform();
if (isset($_REQUEST['oauth2callback'])){
if (isset($_GET['code'])) {
$qs = $platform->parseAuthRedirectUrl($_SERVER['QUERY_STRING']);
$qs["redirectUri"] = getenv('RC_REDIRECT_URL');
try {
$platform->login($qs);
echo "Login success";
$_SESSION['tokens'] = $platform->auth()->data();
} catch (\RingCentral\SDK\Http\ApiException $e) {
print 'Expected HTTP Error: ' . $e->getMessage() . PHP_EOL;
}
}
exit();
}else{
if (isset($_SESSION['tokens'])){
$platform->auth()->setData((array)$_SESSION['tokens']);
if (!$platform->loggedIn()) {
header("Location: http://localhost:5000");
exit();
}
if (isset($_REQUEST['logout'])){
unset($_SESSION['tokens']);
$platform->logout();
header("Location: http://localhost:5000");
exit();
}elseif (isset($_REQUEST['api'])){
if ($_REQUEST['api'] == "extension") {
$endpoint = "/restapi/v1.0/account/~/extension";
callGetRequest($platform, $endpoint, null);
}elseif ($_REQUEST['api'] == "extension-call-log") {
$endpoint = "/restapi/v1.0/account/~/extension/~/call-log";
$params = array(
'fromDate' => '2018-12-01T00:00:00.000Z',
);
callGetRequest($platform, $endpoint, $params);
}elseif ($_REQUEST['api'] == "account-call-log") {
$endpoint = "/restapi/v1.0/account/~/call-log";
$params = array(
'fromDate' => '2018-12-01T00:00:00.000Z',
);
callGetRequest($platform, $endpoint, $params);
}
}
}else{
header("Location: http://localhost:5000");
exit();
}
}
function callGetRequest($platform, $endpoint, $params){
try {
$resp = $platform->get($endpoint, $params);
echo $resp->text();
} catch (\RingCentral\SDK\Http\ApiException $e) {
print 'Expected HTTP Error: ' . $e->getMessage() . PHP_EOL;
}
}
?>