Add Users and User-Metrics

This commit is contained in:
Steven Polley 2018-07-22 03:35:55 -06:00
parent 99d8b2bede
commit 8e6d0743c3
2 changed files with 116 additions and 0 deletions

53
itglue/user-metrics.go Normal file
View File

@ -0,0 +1,53 @@
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
}

63
itglue/users.go Normal file
View File

@ -0,0 +1,63 @@
package itglue
import (
"encoding/json"
"fmt"
"time"
)
type UserData struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
FirstName string `json:"first-name"`
LastName string `json:"last-name"`
Name string `json:"name"`
RoleName string `json:"role-name"`
Email string `json:"email"`
InvitationSentAt time.Time `json:"invitation-sent-at"`
InvitationAcceptedAt time.Time `json:"invitation-accepted-at"`
CurrentSignInAt time.Time `json:"current-sign-in-at"`
CurrentSignInIP string `json:"current-sign-in-ip"`
LastSignInAt time.Time `json:"last-sign-in-at"`
LastSignInIP string `json:"last-sign-in-ip"`
Reputation int `json:"reputation"`
CreatedAt time.Time `json:"created-at"`
UpdatedAt time.Time `json:"updated-at"`
MyGlueAccountID interface{} `json:"my-glue-account-id"`
Avatar string `json:"avatar"`
MyGlue bool `json:"my-glue"`
} `json:"attributes"`
}
type User struct {
Data struct{ UserData } `json:"data"`
Meta struct{ Metadata } `json:"metadata"`
Links struct{ Links } `json:"links"`
}
type UserList struct {
Data []struct{ UserData } `json:"data"`
Meta struct{ Metadata } `json:"metadata"`
Links struct{ Links } `json:"links"`
}
func (itg *ITGAPI) GetUsers() (*UserList, error) {
itgurl, err := itg.BuildURL("/users")
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)
}
users := &UserList{}
err = json.Unmarshal(body, users)
if err != nil {
return nil, fmt.Errorf("could not get users: %s", err)
}
return users, nil
}