33 die ('Commandline only! ' );
44}
55
6+ function createAPIReadline () : APIClient {
7+ $ check = array (
8+ 'URI ' => fn (string $ u ) => @filter_var ($ u , FILTER_VALIDATE_URL , FILTER_FLAG_HOST_REQUIRED | FILTER_FLAG_SCHEME_REQUIRED ),
9+ 'Group/ Username ' => fn (string $ g ) => preg_match ('/^[A-Za-z0-9]+$/ ' , $ g ) === 1 ,
10+ 'Device ' => fn (string $ n ) => preg_match ( '/^[A-Za-z0-9\-]+$/ ' , $ n ) === 1 ,
11+ 'Device Token ' => fn (string $ t ) => preg_match ('/^[A-Za-z0-9]+$/ ' , $ t ) === 1
12+ );
13+ $ tabs = array (
14+ 'URI ' => 3 ,
15+ 'Group/ Username ' => 1 ,
16+ 'Device ' => 3 ,
17+ 'Device Token ' => 2
18+ );
19+ $ data = array ();
20+
21+ echo "Please create a Device in the Webinterface, then fill in details: " . PHP_EOL ;
22+ foreach ($ check as $ name => $ checker ){
23+ do {
24+ $ input = trim (readline ($ name . ': ' . str_repeat ("\t" , $ tabs [$ name ])));
25+ if (empty ($ input ) || !$ checker ($ input ) ){
26+ echo "\tError invalid format! " . PHP_EOL ;
27+ }
28+ else {
29+ $ data [$ name ] = $ input ;
30+ }
31+ } while ( empty ( $ data [$ name ] ) );
32+ }
33+
34+ return new APIClient (
35+ $ data ['URI ' ],
36+ $ data ['Group/ Username ' ],
37+ $ data ['Device ' ],
38+ $ data ['Device Token ' ]
39+ );
40+ }
41+
642class APIClient {
743
844 private string $ uri ;
@@ -22,7 +58,7 @@ private function postToServer(string $endpoint, array $data = array()) : array {
2258 'http ' => array (
2359 'method ' => 'POST ' ,
2460 'header ' => 'Content-Type: application/x-www-form-urlencoded ' ,
25- // 'ignore_errors' => true,
61+ 'ignore_errors ' => true ,
2662 'content ' => http_build_query (array (
2763 'group ' => $ this ->groupId ,
2864 'token ' => $ this ->token ,
@@ -51,8 +87,13 @@ private function postToServer(string $endpoint, array $data = array()) : array {
5187 return array ();
5288 }
5389
54- public function listFiles () : array {
55- return $ this ->postToServer ('list ' );
90+ public function listFiles (int $ timeMin , int $ timeMax ) : array {
91+ return $ this ->postToServer (
92+ 'list ' ,
93+ array (
94+ 'timeMin ' => $ timeMin ,
95+ 'timeMax ' => $ timeMax
96+ ));
5697 }
5798
5899 public function getFile ( string $ file , string $ device ) : array {
0 commit comments