|
@@ -0,0 +1,37 @@
|
|
|
+package discourse
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+// AboutResponse - Structure of a discourse user api response
|
|
|
+type AboutResponse struct {
|
|
|
+ About About `json:"about"`
|
|
|
+ Errors []string `json:"errors"`
|
|
|
+ ErrorType string `json:"error_type"`
|
|
|
+}
|
|
|
+
|
|
|
+// About data for the site
|
|
|
+type About struct {
|
|
|
+ Version string `json:"version"`
|
|
|
+}
|
|
|
+
|
|
|
+// GetAbout - Get a discourse site about
|
|
|
+func GetAbout(config APIConfig) (About, error) {
|
|
|
+ url := fmt.Sprintf("%s/about.json", config.Endpoint)
|
|
|
+
|
|
|
+ req, _ := newGetRequest(config, url)
|
|
|
+ client := getClient()
|
|
|
+ response, _ := client.Do(req)
|
|
|
+
|
|
|
+ var result *AboutResponse
|
|
|
+ json.NewDecoder(response.Body).Decode(&result)
|
|
|
+
|
|
|
+ if result.ErrorType != "" {
|
|
|
+ return About{}, fmt.Errorf("Failed to get discourse user. Error: %s", strings.Join(result.Errors, "; "))
|
|
|
+ }
|
|
|
+
|
|
|
+ return result.About, nil
|
|
|
+}
|