go-itg/itglue/organization-types.go

48 lines
1.2 KiB
Go
Raw Normal View History

package itglue
import (
"encoding/json"
"fmt"
"time"
)
type OrganizationTypeData struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
Name string `json:"name"`
CreatedAt time.Time `json:"created-at"`
UpdatedAt time.Time `json:"updated-at"`
Synced bool `json:"synced"`
} `json:"attributes"`
}
type OrganizationType struct {
2018-07-22 08:24:52 +00:00
Data struct{ OrganizationTypeData } `json:"data"`
Meta struct{ Metadata } `json:"metadata"`
Links struct{ Links } `json:"links"`
}
type OrganizationTypeList struct {
2018-07-22 08:24:52 +00:00
Data []struct{ OrganizationTypeData } `json:"data"`
Meta struct{ Metadata } `json:"metadata"`
Links struct{ Links } `json:"links"`
}
///organization_types
func (itg *ITGAPI) GetOrganizationTypes() (*OrganizationTypeList, error) {
2018-07-23 01:35:10 +00:00
req := itg.NewRequest("/organization_types", "GET", nil)
err := req.Do()
if err != nil {
2018-07-23 01:35:10 +00:00
return nil, fmt.Errorf("request failed for %s: %s", req.RestAction, err)
}
organizationTypes := &OrganizationTypeList{}
2018-07-23 01:35:10 +00:00
err = json.Unmarshal(req.Body, organizationTypes)
if err != nil {
return nil, fmt.Errorf("could not get organization types: %s", err)
}
return organizationTypes, nil
}