-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter.go
113 lines (101 loc) · 3.38 KB
/
character.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
package raiderio
// CharacterQuery is a struct that represents the query parameters
// sent for a character profile request
type CharacterQuery struct {
Region *Region
Realm string
Name string
TalentLoadout bool
Gear bool
fields []string
}
// Character is a struct that represents the response from
// a character profile request
type Character struct {
Name string `json:"name"`
Race string `json:"race"`
Class string `json:"class"`
ActiveSpec string `json:"active_spec_name"`
ActiveRole string `json:"active_spec_role"`
Gender string `json:"gender"`
Faction string `json:"faction"`
Spec string `json:"spec"`
AchievementPoints int64 `json:"achievement_points"`
HonorableKills int64 `json:"honorable_kills"`
ThumbnailUrl string `json:"thumbnail_url"`
Region string `json:"region"`
Realm string `json:"realm"`
LastCrawledAt string `json:"last_crawled_at"`
ProfileUrl string `json:"profile_url"`
ProfileBanner string `json:"profile_banner"`
TalentLoadout TalentLoadout `json:"talentLoadout"`
Gear Gear `json:"gear"`
}
// Gear is a struct that represents the gear of a character
// in a character profile response
type Gear struct {
UpdatedAt string `json:"updated_at"`
ItemLevelEquipped int `json:"item_level_equipped"`
ItemLevelTotal int `json:"item_level_total"`
Items Items `json:"items"`
}
// Items is a struct that represents the items of a character
// in a character profile response
type Items struct {
Head Item `json:"head"`
Neck Item `json:"neck"`
Shoulder Item `json:"shoulder"`
Back Item `json:"back"`
Chest Item `json:"chest"`
Wrist Item `json:"wrist"`
Hands Item `json:"hands"`
Waist Item `json:"waist"`
Legs Item `json:"legs"`
Feet Item `json:"feet"`
Finger1 Item `json:"finger1"`
Finger2 Item `json:"finger2"`
Trinket1 Item `json:"trinket1"`
Trinket2 Item `json:"trinket2"`
Mainhand Item `json:"mainhand"`
Offhand Item `json:"offhand"`
Shirt Item `json:"shirt"`
Tabard Item `json:"tabard"`
}
// Item is a struct that represents a single item
type Item struct {
ID int `json:"item_id"`
ItemLevel int `json:"item_level"`
Icon string `json:"icon"`
Name string `json:"name"`
ItemQuality int `json:"item_quality"`
IsLegendary bool `json:"is_legendary"`
Gems []int `json:"gems"`
Bonuses []int `json:"bonuses"`
}
// TalentLoadout is a struct of a talent loadout
// It includes the spec id and talent loadout string
type TalentLoadout struct {
LoadoutSpecID int `json:"loadout_spec_id"`
LoadoutText string `json:"loadout_text"`
}
// validateCharacterQuery creates and validates a CharacterQuery struct
// It returns an error if any of the required parameters are empty
// or if the fields are invalid
func validateCharacterQuery(cq *CharacterQuery) error {
if cq.Region == nil {
return ErrInvalidRegion
}
if cq.Realm == "" {
return ErrInvalidRealm
}
if cq.Name == "" {
return ErrInvalidCharName
}
if cq.TalentLoadout {
cq.fields = append(cq.fields, "talents")
}
if cq.Gear {
cq.fields = append(cq.fields, "gear")
}
return nil
}