-
Notifications
You must be signed in to change notification settings - Fork 21
/
hsgd.go
278 lines (256 loc) · 11.5 KB
/
hsgd.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package blizzard
import (
"context"
"fmt"
"strings"
"github.com/FuzzyStatic/blizzard/v3/hsgd"
)
// HSCardsSearch returns an up-to-date list of all cards matching the search criteria.
// For more information about the search parameters, see the Card Search Guide (https://develop.battle.net/documentation/hearthstone/guides/card-search).
func (c *Client) HSCardsSearch(ctx context.Context) (*hsgd.CardSearch, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
"/hearthstone/cards",
&hsgd.CardSearch{},
)
return dat.(*hsgd.CardSearch), header, err
}
// HSDetailedCardsSearch returns an up-to-date list of all cards matching the search criteria.
// Input values left blank, 0, or nil will return all values for the type.
// For more information about the search parameters, see the Card Search Guide (https://develop.battle.net/documentation/hearthstone/guides/card-search).
func (c *Client) HSDetailedCardsSearch(ctx context.Context, setSlug, classSlug, raritySlug, typeSlug, minionTypeSlug, keywordSlug, textFilter string,
manaCost, attack, health []int, page, pageSize int,
collectiblility hsgd.Collectibility, sort hsgd.Sort, order hsgd.Order) (*hsgd.CardSearch, *Header, error) {
pathAndQuery := "/hearthstone/cards" +
fmt.Sprintf("?collectible=%s", collectiblility) +
fmt.Sprintf("&sort=%s", sort) +
fmt.Sprintf("&order=%s", order)
if setSlug != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&set=%s", setSlug)
}
if classSlug != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&class=%s", classSlug)
}
if raritySlug != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&rarity=%s", raritySlug)
}
if typeSlug != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&type=%s", typeSlug)
}
if minionTypeSlug != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&minionType=%s", minionTypeSlug)
}
if keywordSlug != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&keyword=%s", keywordSlug)
}
if textFilter != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&textFilter=%s", textFilter)
}
if manaCost != nil {
pathAndQuery = pathAndQuery + fmt.Sprintf("&manaCost=%s", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(manaCost)), ","), "[]"))
}
if attack != nil {
pathAndQuery = pathAndQuery + fmt.Sprintf("&attack=%s", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(attack)), ","), "[]"))
}
if health != nil {
pathAndQuery = pathAndQuery + fmt.Sprintf("&health=%s", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(health)), ","), "[]"))
}
if page != 0 {
pathAndQuery = pathAndQuery + fmt.Sprintf("&page=%d", page)
}
if pageSize != 0 {
pathAndQuery = pathAndQuery + fmt.Sprintf("&pageSize=%d", pageSize)
}
dat, header, err := c.getStructDataNoNamespace(ctx,
pathAndQuery,
&hsgd.CardSearch{},
)
return dat.(*hsgd.CardSearch), header, err
}
// HSBattlegroundsCardsSearch returns an up-to-date list of all cards matching the search criteria for the specified game mode.
// Input values left blank, 0, or nil will return all values for the type.
// For more information about the search parameters, see the Card Search Guide (https://develop.battle.net/documentation/hearthstone/guides/card-search).
func (c *Client) HSBattlegroundsCardsSearch(ctx context.Context, raritySlug, typeSlug, minionTypeSlug, keywordSlug, textFilter string,
manaCost, attack, health []int, page, pageSize int,
tier []hsgd.Tier, collectiblility hsgd.Collectibility, sort hsgd.Sort, order hsgd.Order) (*hsgd.CardSearch, *Header, error) {
pathAndQuery := fmt.Sprintf("/hearthstone/cards?gameMode=%s", hsgd.GameModeBattlegrounds) +
fmt.Sprintf("&collectible=%s", collectiblility) +
fmt.Sprintf("&sort=%s", sort) +
fmt.Sprintf("&order=%s", order)
if raritySlug != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&rarity=%s", raritySlug)
}
if typeSlug != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&type=%s", typeSlug)
}
if minionTypeSlug != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&minionType=%s", minionTypeSlug)
}
if keywordSlug != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&keyword=%s", keywordSlug)
}
if textFilter != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&textFilter=%s", textFilter)
}
if manaCost != nil {
pathAndQuery = pathAndQuery + fmt.Sprintf("&manaCost=%s", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(manaCost)), ","), "[]"))
}
if attack != nil {
pathAndQuery = pathAndQuery + fmt.Sprintf("&attack=%s", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(attack)), ","), "[]"))
}
if health != nil {
pathAndQuery = pathAndQuery + fmt.Sprintf("&health=%s", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(health)), ","), "[]"))
}
if page != 0 {
pathAndQuery = pathAndQuery + fmt.Sprintf("&page=%d", page)
}
if pageSize != 0 {
pathAndQuery = pathAndQuery + fmt.Sprintf("&pageSize=%d", pageSize)
}
if health != nil {
pathAndQuery = pathAndQuery + fmt.Sprintf("&tier=%s", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(tier)), ","), "[]"))
}
dat, header, err := c.getStructDataNoNamespace(ctx,
pathAndQuery,
&hsgd.CardSearch{},
)
return dat.(*hsgd.CardSearch), header, err
}
// HSCardByIDOrSlug returns card by ID or slug.
// For more information about the search parameters, see the Card Search Guide (https://develop.battle.net/documentation/hearthstone/guides/card-search).
func (c *Client) HSCardByIDOrSlug(ctx context.Context, idOrSlug string, gameMode hsgd.GameMode) (*hsgd.Card, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
fmt.Sprintf("/hearthstone/cards/%s?gameMode=%s", idOrSlug, gameMode),
&hsgd.Card{},
)
return dat.(*hsgd.Card), header, err
}
// HSCardBackSearchAllLocales returns an up-to-date list of all card backs matching the search criteria for all locales.
// Input values left blank, 0, or nil will return all values for the type.
// For more information about the search parameters, see the Card Search Guide (https://develop.battle.net/documentation/hearthstone/guides/card-search).
func (c *Client) HSCardBackSearchAllLocales(ctx context.Context, cardBackCategory hsgd.CardBackCategory, textFilter string,
sort hsgd.Sort, order hsgd.Order) (*hsgd.CardBackSearchAllLocales, *Header, error) {
pathAndQuery := "/hearthstone/cardbacks" +
fmt.Sprintf("?sort=%s", sort) +
fmt.Sprintf("&order=%s", order)
if cardBackCategory != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&cardBackCategory=%s", cardBackCategory)
}
if textFilter != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&type=%s", textFilter)
}
dat, header, err := c.getStructDataNoNamespaceNoLocale(ctx,
pathAndQuery,
&hsgd.CardBackSearchAllLocales{},
)
return dat.(*hsgd.CardBackSearchAllLocales), header, err
}
// HSCardBackSearch returns an up-to-date list of all card backs matching the search criteria.
// Input values left blank, 0, or nil will return all values for the type.
// For more information about the search parameters, see the Card Search Guide (https://develop.battle.net/documentation/hearthstone/guides/card-search).
func (c *Client) HSCardBackSearch(ctx context.Context, cardBackCategory hsgd.CardBackCategory, textFilter string,
sort hsgd.Sort, order hsgd.Order) (*hsgd.CardBackSearch, *Header, error) {
pathAndQuery := "/hearthstone/cardbacks" +
fmt.Sprintf("?sort=%s", sort) +
fmt.Sprintf("&order=%s", order)
if cardBackCategory != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&cardBackCategory=%s", cardBackCategory)
}
if textFilter != "" {
pathAndQuery = pathAndQuery + fmt.Sprintf("&type=%s", textFilter)
}
dat, header, err := c.getStructDataNoNamespace(ctx,
pathAndQuery,
&hsgd.CardBackSearch{},
)
return dat.(*hsgd.CardBackSearch), header, err
}
// HSCardBackByIDOrSlug returns a specific card back by using card back ID or slug.
func (c *Client) HSCardBackByIDOrSlug(ctx context.Context, idOrSlug string) (*hsgd.CardBack, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
fmt.Sprintf("/hearthstone/cardbacks/%s", idOrSlug),
&hsgd.CardBack{},
)
return dat.(*hsgd.CardBack), header, err
}
// HSDeck Finds a deck by its deck code.
// For more information, see the Hearthstone Guide.
func (c *Client) HSDeck(ctx context.Context, deckCode string) (*hsgd.Deck, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
fmt.Sprintf("/hearthstone/deck/%s", deckCode),
&hsgd.Deck{},
)
return dat.(*hsgd.Deck), header, err
}
// HSMetadata returns information about the categorization of cards.
// Metadata includes the card set, set group (for example, Standard or Year of the Dragon), rarity, class, card type, minion type, and keywords.
// For more information, see the Hearthstone Guide.
func (c *Client) HSMetadata(ctx context.Context) (*hsgd.Metadata, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
"/hearthstone/metadata",
&hsgd.Metadata{},
)
return dat.(*hsgd.Metadata), header, err
}
// HSMetadataSets returns information about set metadata.
// For more information, see the Hearthstone Guide.
func (c *Client) HSMetadataSets(ctx context.Context) (*[]hsgd.Set, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
fmt.Sprintf("/hearthstone/metadata/%s", hsgd.MetadataTypeSets),
&[]hsgd.Set{},
)
return dat.(*[]hsgd.Set), header, err
}
// HSMetadataSetGroups returns information about set group metadata.
// For more information, see the Hearthstone Guide.
func (c *Client) HSMetadataSetGroups(ctx context.Context) (*[]hsgd.SetGroup, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
fmt.Sprintf("/hearthstone/metadata/%s", hsgd.MetadataTypeSetGroups),
&[]hsgd.SetGroup{},
)
return dat.(*[]hsgd.SetGroup), header, err
}
// HSMetadataTypes returns information about type metadata.
// For more information, see the Hearthstone Guide.
func (c *Client) HSMetadataTypes(ctx context.Context) (*[]hsgd.Type, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
fmt.Sprintf("/hearthstone/metadata/%s", hsgd.MetadataTypeTypes),
&[]hsgd.Type{},
)
return dat.(*[]hsgd.Type), header, err
}
// HSMetadataRarities returns information about rarity metadata.
// For more information, see the Hearthstone Guide.
func (c *Client) HSMetadataRarities(ctx context.Context) (*[]hsgd.Rarity, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
fmt.Sprintf("/hearthstone/metadata/%s", hsgd.MetadataTypeRarities),
&[]hsgd.Rarity{},
)
return dat.(*[]hsgd.Rarity), header, err
}
// HSMetadataClasses returns information about class metadata.
// For more information, see the Hearthstone Guide.
func (c *Client) HSMetadataClasses(ctx context.Context) (*[]hsgd.Class, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
fmt.Sprintf("/hearthstone/metadata/%s", hsgd.MetadataTypeClasses),
&[]hsgd.Class{},
)
return dat.(*[]hsgd.Class), header, err
}
// HSMetadataMinionTypes returns information about minion type metadata.
// For more information, see the Hearthstone Guide.
func (c *Client) HSMetadataMinionTypes(ctx context.Context) (*[]hsgd.MinionType, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
fmt.Sprintf("/hearthstone/metadata/%s", hsgd.MetadataTypeMinionTypes),
&[]hsgd.MinionType{},
)
return dat.(*[]hsgd.MinionType), header, err
}
// HSMetadataKeywords returns information about keyword metadata.
// For more information, see the Hearthstone Guide.
func (c *Client) HSMetadataKeywords(ctx context.Context) (*[]hsgd.Keyword, *Header, error) {
dat, header, err := c.getStructDataNoNamespace(ctx,
fmt.Sprintf("/hearthstone/metadata/%s", hsgd.MetadataTypeKeywords),
&[]hsgd.Keyword{},
)
return dat.(*[]hsgd.Keyword), header, err
}