go-itg/itglue/user-metrics.go

54 lines
1.3 KiB
Go
Raw Normal View History

2018-07-22 09:35:55 +00:00
package itglue
import (
"encoding/json"
"fmt"
)
type UserMetricData struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
UserID int `json:"user-id"`
OrganizationID int `json:"organization-id"`
Created int `json:"created"`
Viewed int `json:"viewed"`
Edited int `json:"edited"`
Deleted int `json:"deleted"`
Date string `json:"date"`
ResourceType string `json:"resource-type"`
} `json:"attributes"`
}
type UserMetric struct {
Data struct{ UserMetricData } `json:"data"`
Meta struct{ Metadata } `json:"metadata"`
Links struct{ Links } `json:"links"`
}
type UserMetricList struct {
Data []struct{ UserMetricData } `json:"data"`
Meta struct{ Metadata } `json:"metadata"`
Links struct{ Links } `json:"links"`
}
func (itg *ITGAPI) GetUserMetrics() (*UserMetricList, error) {
itgurl, err := itg.BuildURL("/user_metrics")
if err != nil {
return nil, fmt.Errorf("could not build URL: %s", err)
}
body, err := itg.GetRequest(itgurl)
if err != nil {
return nil, fmt.Errorf("request failed: %s", err)
}
userMetrics := &UserMetricList{}
err = json.Unmarshal(body, userMetrics)
if err != nil {
return nil, fmt.Errorf("could not get users: %s", err)
}
return userMetrics, nil
}