-
Notifications
You must be signed in to change notification settings - Fork 0
/
allowed_libraries.php
42 lines (38 loc) · 1010 Bytes
/
allowed_libraries.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 'common.php';
use Scriptotek\Alma\Client as AlmaClient;
$method = $_SERVER['REQUEST_METHOD'];
if ($method === 'OPTIONS') {
http_response_code(200);
exit;
} else if ($method !== 'GET') {
http_response_code(400);
exit;
}
try {
$jwt_payload = validateJwt($_GET['jwt']);
if (!$jwt_payload) {
http_response_code(401);
exit;
}
$alma = new AlmaClient(ALMA_API_KEY, ALMA_REGION);
$allowedLibraries = [];
foreach ($alma->conf->libraries as $library) {
if (isAllowed($library->code)) {
$allowedLibraries[] = [
'code' => $library->code,
'name' => $library->name,
];
}
}
http_response_code(200);
header('Content-Type: application/json');
echo json_encode([
'allowInstitutionFees' => ALLOW_INSTITUTION_LEVEL_FEES,
'libraries' => $allowedLibraries,
]);
exit;
} catch (Throwable $e) {
http_response_code(500);
exit;
}