Create a better way to generate the responding json #2

Merged
nupilios merged 1 commits from feature/interactive_endpoints into main 2021-09-05 17:45:29 +00:00

View File

@ -2,40 +2,66 @@
header('Content-Type: application/json');
$apiVersion = 0.13;
$apiVersion = '0.13';
$spaceName = 'Open-Lab Vorarlberg';
$openState = getOpenState();
echo sprintf('
{
"api": "%1$s",
"space": "Open-Lab Vorarlberg",
"logo": "https://open-lab.at/images/Logo/Logo.png",
"url": "https://open-lab.at",
"location": {
"address": "M2 Klaus, Treietstraße 17, Klaus, Vorarlberg, Austria",
"lon": 9.646033516048838,
"lat": 47.30509085141842
},
"contact": {
"email": "info@open-lab.at"
},
"issue_report_channels": [
"email"
$spaceapiArray = [
'api' => $apiVersion,
'space' => $spaceName,
'logo' => 'https://open-lab.at/images/Logo/Logo.png',
'url' => 'https://open-lab.at',
'location' => [
'address' => 'M² Klaus, Treietstraße 17, Klaus, Vorarlberg, Austria',
'lon' => 9.646033516048838,
'lat' => 47.30509085141842,
'timezone' => 'Europe/Vienna',
],
"state": {
"open": %2$s,
"message": "Open every tuesday from 16h"
}
}
', $apiVersion, $openState);
'contact' => [
'email' => 'info@open-lab.at',
'twitter' => '@OpenLabVlbg',
],
'issue_report_channels' => [
'email',
],
'state' => [
'open' => $openState,
],
'links' => [[
"name" => "Location Hilfe",
"url" => "https://open-lab.at/index.php/info/location",
"description" => "Genauere Beschreibung um den Raum zu finden",
]],
];
function getOpenState()
// Add a message if openlab is closed
if (false === $openState) {
$spaceapiArray['state']['message'] = 'Offen: Dienstags 16h-20h';
}
print json_encode($spaceapiArray);
function getOpenState(): bool
{
$fileName = './openState';
$fileHandle = fopen($fileName, 'r');
$contents = fread($fileHandle, filesize($fileName));
fclose($fileHandle);
return $contents;
if (strpos($contents,'true') !== false) {
return true;
}
return false;
}
function getMessageAccordingToState(bool $state)
{
if (true === $state) {
return 'Wir basteln wieder an unseren Projekte und freuen uns über neue Gesichter';
}
return 'Offen: Dienstags 16h-20h';
}