go-itg/itglue/flexible-assets.go

57 lines
1.6 KiB
Go

package itglue
import (
"fmt"
"time"
)
type FlexibleAssetData 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 FlexibleAsset struct {
Data struct{ FlexibleAssetData } `json:"data"`
Meta struct{ Metadata } `json:"metadata"`
Links struct{ Links } `json:"links"`
}
type FlexibleAssetList struct {
Data []struct{ FlexibleAssetData } `json:"data"`
Meta struct{ Metadata } `json:"metadata"`
Links struct{ Links } `json:"links"`
}
//Rather than a "GetFlexibleAssets", we need to implement getters for each flexible asset type. This should probably be automated and go code should be generated by some external program.
func (itg *ITGAPI) GetFlexibleAssets(flexibleAssetTypeID int) error {
req := itg.NewRequest("/flexible_assets", "GET", nil)
req.RawURLValues = fmt.Sprintf("filter[flexible_asset_type_id]=%d", flexibleAssetTypeID)
err := req.Do()
if err != nil {
return fmt.Errorf("request failed for %s: %s", req.RestAction, err)
}
fmt.Println(string(req.Body))
/*
flexibleAssets := &FlexibleAssetList{}
err = json.Unmarshal(req.Body, flexibleAssets)
if err != nil {
return nil, fmt.Errorf("could not get flexible asset: %s", err)
}
return flexibleAssets, nil
*/
return nil
}