-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
51 lines (44 loc) · 1.22 KB
/
index.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
<?php
require_once('vendor/autoload.php');
require_once('config.php');
ini_set('session.save_path', '');
session_start();
// Acuity OAuth Connection
$acuity = new AcuitySchedulingOAuth([
'accessToken' => $_SESSION['acuityAccessToken'],
'clientId' => CLIENT_ID,
'clientSecret' => CLIENT_SECRET,
'redirectUri' => REDIRECT_URI
]);
// Router:
$method = $_SERVER['REQUEST_METHOD'];
$path = $_SERVER['PATH_INFO'] ? $_SERVER['PATH_INFO'] : '/';
if ($method === 'GET' && $path === '/') {
if ($acuity->isConnected()) {
$me = $acuity->request('me');
$today = strftime('%Y-%m-%d');
$agenda = $acuity->request('appointments', [
'query' => [
'minDate' => $today,
'maxDate' => $today
]
]);
} else {
$authorizationUrl = $acuity->getAuthorizeUrl(['scope' => 'api-v1']);
}
include 'templates/index.tpl.php';
} else
if ($method === 'GET' && $path === '/oauth2') {
$response = $acuity->requestAccessToken($_GET['code']);
$accessToken = $response['access_token'];
if ($accessToken) {
$_SESSION['acuityAccessToken'] = $accessToken;
header('Location: /');
}
} else
if ($method === 'GET' && $path === '/disconnect') {
session_destroy();
header('Location: /');
} else {
// 404
}