-
Notifications
You must be signed in to change notification settings - Fork 0
/
flexible-asset-fields.go
63 lines (56 loc) · 2.12 KB
/
flexible-asset-fields.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package itglue
import (
"encoding/json"
"fmt"
"time"
)
type FlexibleAssetFieldData struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
Order int `json:"order"`
Name string `json:"name"`
Kind string `json:"kind"`
Hint interface{} `json:"hint"`
Decimals int `json:"decimals"`
TagType interface{} `json:"tag-type"`
Required bool `json:"required"`
UseForTitle bool `json:"use-for-title"`
Expiration bool `json:"expiration"`
ShowInList bool `json:"show-in-list"`
NameKey string `json:"name-key"`
CreatedAt time.Time `json:"created-at"`
UpdatedAt time.Time `json:"updated-at"`
FlexibleAssetTypeID int `json:"flexible-asset-type-id"`
DefaultValue interface{} `json:"default-value"`
} `json:"attributes"`
Relationships struct {
FlexibleAssetType struct {
FlexibleAssetType
} `json:"flexible-asset-type"`
} `json:"relationships"`
}
type FlexibleAssetField struct {
Data struct{ FlexibleAssetFieldData } `json:"data"`
Meta struct{ Metadata } `json:"meta"`
Links struct{ Links } `json:"links"`
}
type FlexibleAssetFieldList struct {
Data []struct{ FlexibleAssetFieldData } `json:"data"`
Meta struct{ Metadata } `json:"meta"`
Links struct{ Links } `json:"links"`
}
func (itg *ITGAPI) GetFlexibleAssetFields(flexibleAssetTypeID int, pageNumber int) (*FlexibleAssetFieldList, error) {
req := itg.NewRequest(fmt.Sprintf("/flexible_asset_types/%d/relationships/flexible_asset_fields", flexibleAssetTypeID), "GET", nil)
req.Page = pageNumber
err := req.Do()
if err != nil {
return nil, fmt.Errorf("request failed for %s: %s", req.RestAction, err)
}
flexibleAssetFields := &FlexibleAssetFieldList{}
err = json.Unmarshal(req.Body, flexibleAssetFields)
if err != nil {
return nil, fmt.Errorf("could not get flexible asset fields: %s", err)
}
return flexibleAssetFields, nil
}