-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcharacter.go
More file actions
70 lines (62 loc) · 1.78 KB
/
character.go
File metadata and controls
70 lines (62 loc) · 1.78 KB
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
package wow
import (
"errors"
"fmt"
)
type Character struct {
AchievementPoints int
Battlegroup string
ClassId int `json:"class"`
class string
CalcClass string
Gender int
Level int
Name string
Race int
Realm string
Thumbnail string
LastModified uint
Guild *SimpleGuild
Feed []*FeedEntry
Items *ItemList
Stats *CharacterStats
Professions *ProfessionList
Reputation []*Reputation
Titles []*Title
Achievements *AchievementList
Talents []*CharacterTalentList
Appearance *CharacterAppearance
Mounts *MountList
Pets *PetList
PetSlots []*PetSlot
Progression *ProgressionList
PvP *PvPList
Quests []int
TotalHonorableKills int
ApiClient *ApiClient
}
func NewCharacter(client *ApiClient) *Character {
return &Character{ApiClient: client}
}
// Character#Class() retrieves the name of the class of the character via the
func (c *Character) Class() (string, error) {
if c.ApiClient == nil {
return "", errors.New("Character instance does not have an ApiClient reference. Please set ApiClient before calling Class(). c.ApiClient = NewApiClient(\"US\", \"\")")
}
if c.ClassId == 0 {
return "", errors.New("Character instance does not have a class id.")
}
classes, err := c.ApiClient.GetClasses()
if err != nil {
return "", err
}
for _, class := range classes {
if c.ClassId == class.Id {
c.class = class.Name
}
}
if c.class == "" {
return "", errors.New(fmt.Sprintf("%d is not a valid class id", c.ClassId))
}
return c.class, nil
}