From b77c319000375081b23f1f491e1485bf5be34ab8 Mon Sep 17 00:00:00 2001 From: Sander van Leeuwen Date: Mon, 24 Apr 2023 11:45:37 +0200 Subject: [PATCH 1/2] Expose `site.json` though API --- src/DiscourseAPI.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/DiscourseAPI.php b/src/DiscourseAPI.php index 3de972b..09454f7 100644 --- a/src/DiscourseAPI.php +++ b/src/DiscourseAPI.php @@ -1305,4 +1305,12 @@ public function getTopTopics( string $period = 'yearly', string $userName = 'sys return $res; } -} \ No newline at end of file + + /** + * @throws Exception + */ + public function getSite(): stdClass + { + return $this->_getRequest('/site.json'); + } +} From 5e9c522fa3b4de87e0f8a1c678dbce895381cbd6 Mon Sep 17 00:00:00 2001 From: Sander van Leeuwen Date: Mon, 24 Apr 2023 11:55:14 +0200 Subject: [PATCH 2/2] Return actual contents and throw exception when empty / failed. --- src/DiscourseAPI.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/DiscourseAPI.php b/src/DiscourseAPI.php index 09454f7..e194a80 100644 --- a/src/DiscourseAPI.php +++ b/src/DiscourseAPI.php @@ -21,6 +21,7 @@ use CURLFile; use DateTime; use Exception; +use RuntimeException; use stdClass; use function is_int; @@ -1311,6 +1312,12 @@ public function getTopTopics( string $period = 'yearly', string $userName = 'sys */ public function getSite(): stdClass { - return $this->_getRequest('/site.json'); + $result = $this->_getRequest('/site.json'); + + if (!is_object($result) || !isset($result->apiresult)) { + throw new RuntimeException('Failed fetching site info'); + } + + return $result->apiresult; } }