-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
56 lines (52 loc) · 1.95 KB
/
functions.php
File metadata and controls
56 lines (52 loc) · 1.95 KB
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
<?php
// Wczytaj .env jeśli jeszcze nie było
if (!function_exists('loadEnvFile')) {
function loadEnvFile($path = __DIR__ . '/.env') {
if (!file_exists($path)) return;
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) continue;
[$key, $value] = explode('=', $line, 2);
$key = trim($key);
$value = trim($value, " \t\n\r\0\x0B\"'");
putenv("$key=$value");
}
}
}
if (!function_exists('login')) {
function login($username, $password) {
$ch = curl_init("https://emodul.eu/api/v1/authentication");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"username" => $username,
"password" => $password
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
$resp = curl_exec($ch);
curl_close($ch);
return json_decode($resp, true);
}
}
if (!function_exists('getModules')) {
function getModules($userId, $token) {
$url = "https://emodul.eu/api/v1/users/{$userId}/modules";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $token"]);
$resp = curl_exec($ch);
curl_close($ch);
return json_decode($resp, true);
}
}
if (!function_exists('getModuleDetails')) {
function getModuleDetails($userId, $udid, $token) {
$url = "https://emodul.eu/api/v1/users/{$userId}/modules/{$udid}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $token"]);
$resp = curl_exec($ch);
curl_close($ch);
return json_decode($resp, true);
}
}