From 7bf2c31db31f85fc1408c3287809271ad81ec515 Mon Sep 17 00:00:00 2001 From: Felix Albrigtsen Date: Sat, 18 May 2024 20:05:13 +0200 Subject: [PATCH] feat: adds spaceapi endpoint (#57) A basic implementation of the https://spaceapi.io/ specification. Tested working door sensor status. Added basic info about us, our website, git forge and wiki. Co-authored with @sindos and @oysteikt. Reviewed-on: https://git.pvv.ntnu.no/Projects/nettsiden/pulls/57 Co-authored-by: Felix Albrigtsen Co-committed-by: Felix Albrigtsen --- nix/module.nix | 4 +++ www/spaceapi.php | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 www/spaceapi.php diff --git a/nix/module.nix b/nix/module.nix index f278ab9..1b4c7bd 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -198,6 +198,10 @@ in fastcgi_pass unix:${config.services.phpfpm.pools."pvv-nettsiden".socket}; ''; + "= /spaceapi.php".extraConfig = '' + add_header Content-Type application/json; + ''; + # based on https://simplesamlphp.org/docs/stable/simplesamlphp-install.html#configuring-nginx "^~ /simplesaml/" = { alias = "${finalPackage}/${finalPackage.passthru.simplesamlphpPath}/public/"; diff --git a/www/spaceapi.php b/www/spaceapi.php new file mode 100644 index 0000000..04964a8 --- /dev/null +++ b/www/spaceapi.php @@ -0,0 +1,68 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +$door = new \pvv\side\Door($pdo); +$doorEntry = (object)($door->getCurrent()); + +?> +{ + "api_compatibility": ["14"], + "space": "Programvareverkstedet", + "logo": "https://git.pvv.ntnu.no/assets/img/logo.png", + "url": "https://www.pvv.ntnu.no/", + "location": { + "ext_campus": "NTNU Gløshaugen", + "ext_room_name": "Oppredning/Gruvedrift, Floor 2, Room 247", + "ext_mazemap": "https://link.mazemap.com/2n2HWa7H", + "address": "Sem Sælands vei 1, 7034 Trondheim, Norway", + "timezone": "Europe/Oslo", + "lon": 10.242, + "lat": 63.250 + }, + "contact": { + "irc": "irc://irc.pvv.ntnu.no/pvv", + "email": "pvv@pvv.ntnu.no", + "ext_discord": "https://discord.gg/8VTBr6Q", + "gopher": "gopher://isvegg.pvv.ntnu.no", + "matrix": "#pvv:pvv.ntnu.no" + }, + "issue_report_channels": ["email"], + "state": { + "open": open ? "true" : "false"); ?>, + "lastchange": time ? $doorEntry->time : 0); ?>, + "message": "open ? "open for public, members are present" : "closed"); ?>" + }, + "feeds": { + "wiki": { + "type": "atom", + "url": "https://www.pvv.ntnu.no/w/api.php?hidebots=1&urlversion=1&action=feedrecentchanges&feedformat=atom" + }, + "calendar": { + "type": "html", + "url": "https://www.pvv.ntnu.no/hendelser/" + } + }, + "projects": [ + "https://github.com/Programvareverkstedet/", + "https://git.pvv.ntnu.no/", + "https://www.pvv.ntnu.no/prosjekt/" + ], + "links": [ + { + "name": "YouTube", + "url": "https://www.youtube.com/@pvvntnu5640" + }, + { + "name": "LinkedIn", + "url": "https://www.linkedin.com/company/pvvntnu/" + }, + { + "name": "Facebook", + "url": "https://www.facebook.com/pvvntnu/" + } + ] +}