Selaa lähdekoodia

Added version check api to dashboard

thisnthat 4 vuotta sitten
vanhempi
commit
277b163ec7
1 muutettua tiedostoa jossa 22 lisäystä ja 0 poistoa
  1. 22 0
      dashboard.go

+ 22 - 0
dashboard.go

@@ -50,3 +50,25 @@ func GetDashboard(config APIConfig) (Dashboard, error) {
 
 	return Dashboard{}, fmt.Errorf("Unexpected response from discourse server at %s -- %s", url, response.Status)
 }
+
+// GetVersionCheck will retrieve the admin version check dat from discourse
+func GetVersionCheck(config APIConfig) (VersionCheck, error) {
+	url := fmt.Sprintf("%s/admin/version_check.json", config.Endpoint)
+
+	req, _ := newGetRequest(config, url)
+	client := getClient()
+	response, err := client.Do(req)
+
+	if err != nil {
+		return VersionCheck{}, fmt.Errorf("Unable to connect to discourse server at %s -- %s", url, err)
+	}
+
+	if response.StatusCode == http.StatusOK || response.StatusCode == http.StatusForbidden {
+		var result *VersionCheck
+		json.NewDecoder(response.Body).Decode(&result)
+
+		return *result, nil
+	}
+
+	return VersionCheck{}, fmt.Errorf("Unexpected response from discourse server at %s -- %s", url, response.Status)
+}