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) {
|
2018-07-23 01:35:10 +00:00
|
|
|
req := itg.NewRequest("/user_metrics", "GET", nil)
|
|
|
|
err := req.Do()
|
2018-07-22 09:35:55 +00:00
|
|
|
if err != nil {
|
2018-07-23 01:35:10 +00:00
|
|
|
return nil, fmt.Errorf("request failed for %s: %s", req.RestAction, err)
|
2018-07-22 09:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
userMetrics := &UserMetricList{}
|
2018-07-23 01:35:10 +00:00
|
|
|
err = json.Unmarshal(req.Body, userMetrics)
|
2018-07-22 09:35:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not get users: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return userMetrics, nil
|
|
|
|
}
|