DevicesApi

This commit is contained in:
xinatorus 2020-04-24 21:54:25 +02:00
parent b4cfffc432
commit 5519d46ca2
3 changed files with 21 additions and 2 deletions

View File

@ -18,4 +18,6 @@ $router->any('/ajax', 'Ajax');
$router->any('/log', 'Log'); $router->any('/log', 'Log');
$router->any('/rooms', 'Rooms'); $router->any('/rooms', 'Rooms');
$router->get('/api/devices', 'DevicesApi@getAllDevices');
$router->run($_SERVER['REQUEST_METHOD'], '/'.(isset($_GET['url']) ? $_GET['url'] : '')); $router->run($_SERVER['REQUEST_METHOD'], '/'.(isset($_GET['url']) ? $_GET['url'] : ''));

17
app/api/DevicesApi.php Normal file
View File

@ -0,0 +1,17 @@
<?php
class DevicesApi extends ApiController{
public function getAllDevices(){
$this->requireAuth();
$response = [];
// TODO: process the request
$this->response($response);
}
public function getDevicesByRoom($roomId){
}
}

View File

@ -17,7 +17,7 @@ class ApiController {
} }
} }
function requireAuth(){ private function requireAuth(){
if (isset($this->headers['HTTP_AUTHORIZATION'])) { if (isset($this->headers['HTTP_AUTHORIZATION'])) {
// TODO: call appropriate class/method // TODO: call appropriate class/method
$authManager = new AuthManager(); $authManager = new AuthManager();
@ -30,7 +30,7 @@ class ApiController {
} }
} }
function response($data = [], $httpCode = '200'){ private function response($data = [], $httpCode = '200'){
http_response_code($httpCode); http_response_code($httpCode);
echo json_encode($data); echo json_encode($data);
} }