hanze/iwa-panda2

api tests (e68c6aadbddf893a630b2810aa412a9aeec47c09)
Repositories | README.md

commit e68c6aadbddf893a630b2810aa412a9aeec47c09
parent fad453ab019313c1999581365033fbd551cb0b8d
Author: Gerco van Woudenbergh <[email protected]>
Date:   Wed, 28 Jun 2023 21:49:22 +0200

api tests

Diffstat:
MController/api/api.php23++++++++++++++++++-----
Mindex.php3++-
2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/Controller/api/api.php b/Controller/api/api.php @@ -18,14 +18,27 @@ function storeData($dataArray): void{ $db->close(); } -$test = function(&$vars){ +$get_windchill = function(&$vars){ $token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'; - $url = 'http://86.92.67.21/api/windchill'; + if(isset($vars['since'])){ + $since = $vars['since']; + }else{ + $since = "curdate()"; + } + $url = 'http://86.92.67.21/api/windchill/' . $since; $connect = new Model\Connect($url, $token); $response = $connect->connect(); - var_dump($response); - foreach($response as $obj){ - echo "city " . $obj->city . " windchill corrected:" . $obj->windchill . "<br>"; + storeData($response); +}; +$get_graph = function(&$vars){ + $token = 'ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684'; + if(isset($vars['since'])){ + $since = $vars['since']; + }else{ + $since = "curdate()"; } + $url = 'http://86.92.67.21/api/graph/' . $since; + $connect = new Model\Connect($url, $token); + $response = $connect->connect(); storeData($response); }; \ No newline at end of file diff --git a/index.php b/index.php @@ -14,7 +14,8 @@ $router->addRoute(["POST"], "/login", function($vars){ login_handler(); }); -$router->addRoute(['GET', 'POST'], "/test", $test); +$router->addRoute(['GET', 'POST'], "/windchill/:since", $get_windchill); +$router->addRoute(['GET', 'POST'], "/graph/:since", $get_graph); //logout $router->addRoute(["POST", "GET"], "/logout", function($vars){ include "Controller/logout/logout.php";