-
Notifications
You must be signed in to change notification settings - Fork 0
/
formats.go
92 lines (75 loc) · 1.94 KB
/
formats.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package nrdb
import (
"fmt"
"time"
)
func (cl client) Format(formatID string) (*Format, error) {
var res Response[Format]
if err := cl.nrdbReq(fmt.Sprintf("formats/%s", formatID), &res, nil); err != nil {
return nil, err
}
return &res.Data, nil
}
func (cl client) Formats() ([]*Format, error) {
var res Response[[]*Format]
if err := cl.nrdbReq("formats", &res, nil); err != nil {
return nil, err
}
return res.Data, nil
}
type Format struct {
Document[FormatAttributes, FormatRelationships]
}
func (doc Format) String() string {
return fmt.Sprintf("%s (%s)", doc.Attributes.Name, doc.ID)
}
func (doc Format) Name() string {
if doc.Attributes == nil {
return ""
}
return doc.Attributes.Name
}
func (doc Format) ActiveCardPoolID() string {
if doc.Attributes == nil {
return ""
}
return doc.Attributes.ActiveCardPoolID
}
func (doc Format) ActiveRestrictionID() string {
if doc.Attributes == nil {
return ""
}
return doc.Attributes.ActiveRestrictionID
}
func (doc Format) ActiveSnapshotID() string {
if doc.Attributes == nil {
return ""
}
return doc.Attributes.ActiveSnapshotID
}
func (doc Format) RestrictionIDs() []string {
if doc.Attributes == nil {
return nil
}
return doc.Attributes.RestrictionIDs
}
func (doc Format) SnapshotIDs() []string {
if doc.Attributes == nil {
return nil
}
return doc.Attributes.SnapshotIDs
}
type FormatAttributes struct {
Name string `json:"name"`
ActiveCardPoolID string `json:"active_card_pool_id"`
ActiveRestrictionID string `json:"active_restriction_id"`
ActiveSnapshotID string `json:"active_snapshot_id"`
RestrictionIDs []string `json:"restriction_ids"`
SnapshotIDs []string `json:"snapshot_ids"`
UpdatedAt time.Time `json:"updated_at"`
}
type FormatRelationships struct {
CardPools *Relationship `json:"card_pools"`
Restrictions *Relationship `json:"restrictions"`
Snapshots *Relationship `json:"snapshots"`
}