-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaccount.go
268 lines (238 loc) · 8.08 KB
/
account.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
package gw2api
import (
"fmt"
"net/url"
"strconv"
)
// Account includes all general information
type Account struct {
ID string `json:"id"`
Name string `json:"name"`
World int `json:"world"`
Guilds []string `json:"guilds"`
Access string `json:"access"`
Created string `json:"created"`
FractalLevel int `json:"fractal_level"`
DailyAP int `json:"daily_ap"`
MonthlyAP int `json:"monthly_ap"`
WvWRank int `json:"wvw_rank"`
}
// Account fetches the general account information
// Requires authentication
func (gw2 *GW2Api) Account() (acc Account, err error) {
ver := "v2"
tag := "account"
err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermAccount, nil, &acc)
return
}
// BankItem describes an item stored in the players normal bank
type BankItem struct {
ID int `json:"id"`
Count int `json:"count"`
Skin int `json:"skin"`
Upgrades []int `json:"upgrades"`
Infusions []int `json:"infusions"`
}
// AccountBank returns an array of objects, each representing an item slot in
// the vault. If a slot is empty, it will return null. The amount of slots/bank
// tabs is implied by the length of the array.
// Requires authentication
func (gw2 *GW2Api) AccountBank() (items []BankItem, err error) {
ver := "v2"
tag := "account/bank"
err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermInventory, nil, &items)
return
}
// AccountDyes returns an array of dyes unlocked by the player. The IDs can be
// resolved via ColorIds()
// Requires authentication
func (gw2 *GW2Api) AccountDyes() (dyes []int, err error) {
ver := "v2"
tag := "account/dyes"
err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermUnlocks, nil, &dyes)
return
}
// MaterialItem represents a material stored in the material storage of the
// player
// Requires authentication
type MaterialItem struct {
ID int `json:"id"`
Count int `json:"count"`
Category int `json:"category"`
}
// AccountMaterials returns an array of objects, each representing a material that
// can be stored in the vault. Every material will be returned, even if they
// have a count of 0
// Requires authentication
func (gw2 *GW2Api) AccountMaterials() (items []MaterialItem, err error) {
ver := "v2"
tag := "account/materials"
params := url.Values{}
err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermInventory, params, &items)
return
}
// AccountSkins returns an array of skins unlocked by the player. The IDs can be
// resolved via SkinIds()
// Requires authentication
func (gw2 *GW2Api) AccountSkins() (skins []int, err error) {
ver := "v2"
tag := "account/dyes"
err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermUnlocks, nil, &skins)
return
}
// WalletCurrency represents a currency and the amount owned by the player
type WalletCurrency struct {
ID int `json:"id"`
Value int `json:"value"`
}
// AccountWallet returns an array of currencies owned by the player. The IDs can be
// resolved via CurrencyIds()
// Requires authentication
func (gw2 *GW2Api) AccountWallet() (currency []WalletCurrency, err error) {
ver := "v2"
tag := "account/materials"
err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermWallet, nil, ¤cy)
return
}
// Characters returns an array of character names associated with the account.
// The names can be used to request detailed information via CharacterIds()
// Requires authentication
func (gw2 *GW2Api) Characters() (res []string, err error) {
ver := "v2"
tag := "characters"
err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermCharacter, nil, &res)
return
}
// CraftingDiscipline contains information about learned crafting discplines on
// the character and shows their active state
type CraftingDiscipline struct {
Discipline string `json:"discipline"`
Rating int `json:"rating"`
Active bool `json:"active"`
}
// Specialization represents the currently selected one and includes all active
// traits on the character
type Specialization struct {
ID int `json:"id"`
Traits []int `json:"trait"`
}
// Specalizations is a meta object which holds the specalizations associated
// with the different game types
type Specalizations struct {
PvE []Specialization `json:"pve"`
PvP []Specialization `json:"pvp"`
WvW []Specialization `json:"wvw"`
}
// InventoryItem Item in a characters inventory and their count
type InventoryItem struct {
ID int `json:"id"`
Count int `json:"count"`
}
// Bag on the character with size and inventory
type Bag struct {
ID int `json:"id"`
Size int `json:"size"`
Inventory []InventoryItem `json:"inventory"`
}
// Equipment worn by the character
type Equipment struct {
ID int `json:"id"`
Slot string `json:"slot"`
Upgrades []int `json:"upgrades"`
Infusions []int `json:"infusions"`
Skin int `json:"skin"`
}
// PetSelection for rangers
type PetSelection struct {
Terrestrial []int `json:"terrestrial"`
Aquatic []int `json:"aquatic"`
}
// SkillSelection shows the currently selected heals, utility elite and legends
type SkillSelection struct {
Legends []string `json:"legends"`
Heal int `json:"heal"`
Utility []int `json:"utility"`
Elite int `json:"elite"`
Pets PetSelection `json:"pets"`
}
// Skills per game type
type Skills struct {
PvE SkillSelection `json:"pve"`
PvP SkillSelection `json:"pvp"`
WvW SkillSelection `json:"wvw"`
}
// EquipmentPvP selected items in PvP mode
type EquipmentPvP struct {
// references PvPAmulets
Amulet int `json:"amulet"`
Rune int `json:"rune"`
// UI order left to right
Sigils []int `json:"sigils"`
}
// Character combines all information about the character
type Character struct {
Name string `json:"name"`
Race string `json:"race"`
Gender string `json:"gender"`
Profession string `json:"profession"`
Level int `json:"level"`
Guild string `json:"guild"`
Created string `json:"created"`
Age int `json:"age"`
Deaths int `json:"deaths"`
Crafting []CraftingDiscipline `json:"crafting"`
Specalization Specalizations `json:"specalization"`
Skill Skills `json:"skills"`
Bags []Bag `json:"bags"`
Equipment []Equipment `json:"equipment"`
EquipmentPvP EquipmentPvP `json:"equipment_pvp"`
}
// CharacterIds requests detailed information about the characters requested via
// the IDs. The IDs can also be character names as e.g. provided by the
// Characters() API Call
// Requires authentication
func (gw2 *GW2Api) CharacterIds(ids ...string) (chars []Character, err error) {
ver := "v2"
tag := "characters"
params := url.Values{}
params.Add("ids", commaList(ids))
err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermCharacter, params, &chars)
return
}
// CharactersPage allows pagination for the character objects and enables the
// request of all character objects
// Requires authentication
func (gw2 *GW2Api) CharactersPage(page, pageSize int) (chars []Character, err error) {
if page < 0 {
return nil, fmt.Errorf("Page parameter cannot be a negative number!")
}
ver := "v2"
tag := "characters"
params := url.Values{}
params.Add("page", strconv.Itoa(page))
if pageSize >= 0 {
params.Add("page_size", strconv.Itoa(pageSize))
}
err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermCharacter, params, &chars)
return
}
// AccountMinis returns the ids of all unlocked minis in the accounts collection
func (gw2 *GW2Api) AccountMinis() (minis []int, err error) {
ver := "v2"
tag := "account/minis"
err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermUnlocks, nil, &minis)
return
}
// SharedInventorySlot Self-explanatory
type SharedInventorySlot struct {
ID int `json:"id"`
Count int `json:"count"`
Binding string `json:"binding"`
}
// SharedInventory returns the list of items currently in the shared inventory
func (gw2 *GW2Api) SharedInventory() (slots []SharedInventorySlot, err error) {
ver := "v2"
tag := "account/inventory"
err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermInventory, nil, &slots)
return
}