From 5519d46ca2c6ea609ab322562fb2ce5738375c88 Mon Sep 17 00:00:00 2001 From: xinatorus Date: Fri, 24 Apr 2020 21:54:25 +0200 Subject: [PATCH] DevicesApi --- app/Routes.php | 2 ++ app/api/DevicesApi.php | 17 +++++++++++++++++ library/ApiController.php | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/api/DevicesApi.php diff --git a/app/Routes.php b/app/Routes.php index bd217ff..a719639 100644 --- a/app/Routes.php +++ b/app/Routes.php @@ -18,4 +18,6 @@ $router->any('/ajax', 'Ajax'); $router->any('/log', 'Log'); $router->any('/rooms', 'Rooms'); +$router->get('/api/devices', 'DevicesApi@getAllDevices'); + $router->run($_SERVER['REQUEST_METHOD'], '/'.(isset($_GET['url']) ? $_GET['url'] : '')); diff --git a/app/api/DevicesApi.php b/app/api/DevicesApi.php new file mode 100644 index 0000000..856acb5 --- /dev/null +++ b/app/api/DevicesApi.php @@ -0,0 +1,17 @@ +requireAuth(); + $response = []; + + // TODO: process the request + + $this->response($response); + } + + public function getDevicesByRoom($roomId){ + + } +} diff --git a/library/ApiController.php b/library/ApiController.php index cca7f62..5a23985 100644 --- a/library/ApiController.php +++ b/library/ApiController.php @@ -17,7 +17,7 @@ class ApiController { } } - function requireAuth(){ + private function requireAuth(){ if (isset($this->headers['HTTP_AUTHORIZATION'])) { // TODO: call appropriate class/method $authManager = new AuthManager(); @@ -30,7 +30,7 @@ class ApiController { } } - function response($data = [], $httpCode = '200'){ + private function response($data = [], $httpCode = '200'){ http_response_code($httpCode); echo json_encode($data); }