-
Notifications
You must be signed in to change notification settings - Fork 0
/
card-sets.go
72 lines (58 loc) · 1.62 KB
/
card-sets.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
package nrdb
import (
"fmt"
"net/url"
"time"
)
type CardSet struct {
Document[CardSetAttributes, CardSetRelationships]
}
type CardSetAttributes struct {
Name string `json:"name"`
CardCycleID string `json:"card_cycle_id"`
CardSetTypeID string `json:"card_set_type_id"`
DateRelease string `json:"date_release"`
FirstPrintingID string `json:"first_printing_id"`
LegacyCode string `json:"legacy_code"`
ReleasedBy string `json:"released_by"`
Size int `json:"size"`
UpdatedAt time.Time `json:"updated_at"`
}
type CardSetRelationships struct {
CardCycle *Relationship `json:"card_cycle"`
CardSetType *Relationship `json:"card_set_type"`
Cards *Relationship `json:"cards"`
Printings *Relationship `json:"printings"`
}
type CardSetFilter struct {
CardCycleID string
CardSetTypeID string
}
func (filter CardSetFilter) Query() (url.Values, error) {
query := url.Values{}
if filter.CardCycleID != "" {
query.Set("filter[card_cycle_id]", filter.CardCycleID)
}
if filter.CardSetTypeID != "" {
query.Set("filter[card_set_type_id]", filter.CardSetTypeID)
}
return query, nil
}
func (doc CardSet) String() string {
return fmt.Sprintf("%s (%s)", doc.Attributes.Name, doc.ID)
}
func (cl client) CardSets(filter *CardSetFilter) ([]*CardSet, error) {
var res Response[[]*CardSet]
var query url.Values
if filter != nil {
q, err := filter.Query()
if err != nil {
return nil, fmt.Errorf("encoding filter: %w", err)
}
query = q
}
if err := cl.nrdbReq("card_sets", &res, query); err != nil {
return nil, err
}
return res.Data, nil
}