From 2c035878ed944afcb9e1a7fd2e1d4473d12cef85 Mon Sep 17 00:00:00 2001 From: malle-pietje Date: Tue, 28 Aug 2018 14:44:49 +0200 Subject: [PATCH] - added stat_speedtest_results() method/function to collect results from scheduled speed tests - added list_backups() method/function to list auto backups --- examples/README.md | 1 + src/Client.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/examples/README.md b/examples/README.md index 28db31d..53d0ea4 100755 --- a/examples/README.md +++ b/examples/README.md @@ -1,4 +1,5 @@ ## API client class usage examples + This directory contains some PHP code examples which demonstrate usage of the PHP API client class and can be used as a good starting point for your own custom code. ### Usage diff --git a/src/Client.php b/src/Client.php index e108638..d44242a 100755 --- a/src/Client.php +++ b/src/Client.php @@ -665,6 +665,28 @@ class Client return $this->process_response($response); } + /** + * Method to fetch speed test results + * ---------------------------------- + * returns an array of speed test result objects + * optional parameter = Unix timestamp in milliseconds + * optional parameter = Unix timestamp in milliseconds + * + * NOTES: + * - defaults to the past 24 hours + * - requires a USG + */ + public function stat_speedtest_results($start = null, $end = null) + { + if (!$this->is_loggedin) return false; + $end = is_null($end) ? ((time())*1000) : intval($end); + $start = is_null($start) ? $end-(24*3600*1000) : intval($start); + $json = ['attrs' => ['xput_download','xput_upload','latency','time'], 'start' => $start, 'end' => $end]; + $json = json_encode($json); + $response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/archive.speedtest', 'json='.$json); + return $this->process_response($response); + } + /** * Show all login sessions * ----------------------- @@ -1047,6 +1069,20 @@ class Client return $this->process_response($response); } + /** + * List auto backups + * --------------------------- + * return an array containing objects with backup details on success + */ + public function list_backups() + { + if (!$this->is_loggedin) return false; + $mac = strtolower($mac); + $json = json_encode(['cmd' => 'list-backups']); + $response = $this->exec_curl('/api/s/'.$this->site.'/cmd/backup', 'json='.$json); + return $this->process_response($response); + } + /** * List sites * ----------