2018-07-23 00:51:25 +00:00
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" `
}
2018-07-23 02:06:08 +00:00
//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.
2018-07-23 00:51:25 +00:00
func ( itg * ITGAPI ) GetFlexibleAssets ( flexibleAssetTypeID int ) error {
2018-07-23 01:35:10 +00:00
req := itg . NewRequest ( "/flexible_assets" , "GET" , nil )
2018-07-23 02:06:08 +00:00
req . RawURLValues = fmt . Sprintf ( "filter[flexible_asset_type_id]=%d" , flexibleAssetTypeID )
2018-07-23 01:35:10 +00:00
err := req . Do ( )
2018-07-23 00:51:25 +00:00
if err != nil {
2018-07-23 01:35:10 +00:00
return fmt . Errorf ( "request failed for %s: %s" , req . RestAction , err )
2018-07-23 00:51:25 +00:00
}
2018-07-23 01:35:10 +00:00
fmt . Println ( string ( req . Body ) )
2018-07-23 00:51:25 +00:00
/ *
flexibleAssets := & FlexibleAssetList { }
2018-07-23 01:35:10 +00:00
err = json . Unmarshal ( req . Body , flexibleAssets )
2018-07-23 00:51:25 +00:00
if err != nil {
return nil , fmt . Errorf ( "could not get flexible asset: %s" , err )
}
return flexibleAssets , nil
* /
return nil
}