go-itg/itglue/flexible-asset-types.go

51 lines
1.4 KiB
Go
Raw Permalink Normal View History

2018-07-22 16:06:05 +00:00
package itglue
import (
"encoding/json"
"fmt"
"time"
)
type FlexibleAssetTypeData struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
Name string `json:"name"`
Description string `json:"description"`
CreatedAt time.Time `json:"created-at"`
UpdatedAt time.Time `json:"updated-at"`
Icon string `json:"icon"`
Enabled bool `json:"enabled"`
} `json:"attributes"`
Relationships struct {
} `json:"relationships"`
}
type FlexibleAssetType struct {
Data struct{ FlexibleAssetTypeData } `json:"data"`
Meta struct{ Metadata } `json:"metadata"`
Links struct{ Links } `json:"links"`
}
type FlexibleAssetTypeList struct {
Data []struct{ FlexibleAssetTypeData } `json:"data"`
Meta struct{ Metadata } `json:"metadata"`
Links struct{ Links } `json:"links"`
}
func (itg *ITGAPI) GetFlexibleAssetTypes() (*FlexibleAssetTypeList, error) {
2018-07-23 01:35:10 +00:00
req := itg.NewRequest("/flexible_asset_types", "GET", nil)
err := req.Do()
2018-07-22 16:06:05 +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 16:06:05 +00:00
}
flexibleAssetTypes := &FlexibleAssetTypeList{}
2018-07-23 01:35:10 +00:00
err = json.Unmarshal(req.Body, flexibleAssetTypes)
2018-07-22 16:06:05 +00:00
if err != nil {
return nil, fmt.Errorf("could not get flexible asset types: %s", err)
}
return flexibleAssetTypes, nil
}