-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.php
42 lines (32 loc) · 1.14 KB
/
ajax.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
<?php
require_once 'bootstrap.php';
use KangarooRewards\Api\KangarooApi;
use KangarooRewards\OAuth2\Client\Provider\Kangaroo as KangarooProvider;
try {
$kangaroo = new KangarooProvider([
'clientId' => App\Config::CLIENT_ID,
'clientSecret' => App\Config::CLIENT_SECRET,
'redirectUri' => App\Config::REDIRECT_URI_OAUTH,
]);
$accessToken = App\Utils::retrieveToken($kangaroo);
$api = new KangarooApi([
'access_token' => $accessToken->getToken(),
'base_api_url' => App\Config::KANGAROO_API_BASE_URL,
'headers' => ['X-Application-Key' => App\Config::X_APPLICATION_KEY],
]);
} catch (Exception $e) {
// print_r($e);
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
json_encode(['message' => $e->getMessage()]);
exit;
}
header('Content-Type: application/json');
if (isset($_GET['q']) && $_GET['q'] === 'branches') {
$resourceOwner = $api->me(['include' => 'branches']);
$branches = $resourceOwner['included']['branches'];
header('HTTP/1.1 200 OK');
echo json_encode($branches);
exit;
}
header('HTTP/1.1 204 No Content');