Skip to content

Commit 985427e

Browse files
committed
statistics
1 parent 38413de commit 985427e

File tree

5 files changed

+152
-62
lines changed

5 files changed

+152
-62
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ client.CharacterReputations(realm string, name string)
6161
client.CharacterProfessions(realm string, name string)
6262
client.CharacterInfo(realm string, name string)
6363
client.CharacterHunterPets(realm string, name string)
64+
client.CharacterStatistics(realm string, name string)
6465
```
6566

6667
You can also use the client like this

statistics.go

+133-56
Original file line numberDiff line numberDiff line change
@@ -6,71 +6,148 @@ import (
66
)
77

88
type Statistics struct {
9-
Health int64 `json:"health"`
10-
Power int64 `json:"power"`
9+
SpellCrit struct {
10+
Rating float64 `json:"rating"`
11+
RatingBonus float64 `json:"rating_bonus"`
12+
Value float64 `json:"value"`
13+
} `json:"spell_crit"`
14+
ManaRegenCombat float64 `json:"mana_regen_combat"`
15+
Power float64 `json:"power"`
16+
VersatilityDamageDoneBonus float64 `json:"versatility_damage_done_bonus"`
17+
MainHandDps float64 `json:"main_hand_dps"`
18+
OffHandDps float64 `json:"off_hand_dps"`
19+
Block struct {
20+
Rating float64 `json:"rating"`
21+
RatingBonus float64 `json:"rating_bonus"`
22+
Value float64 `json:"value"`
23+
} `json:"block"`
24+
RangedHaste struct {
25+
Rating float64 `json:"rating"`
26+
RatingBonus float64 `json:"rating_bonus"`
27+
Value float64 `json:"value"`
28+
} `json:"ranged_haste"`
1129
PowerType struct {
12-
Name string `json:"name"`
13-
Id int64 `json:"id"`
30+
Key struct {
31+
Href string `json:"href"`
32+
} `json:"key"`
33+
Name string `json:"name"`
34+
Id float64 `json:"id"`
1435
} `json:"power_type"`
15-
Speed float64 `json:"speed"`
16-
Strength PrimaryStat `json:"strength"`
17-
Agility PrimaryStat `json:"agility"`
18-
Intellect PrimaryStat `json:"intellect"`
19-
Stamina PrimaryStat `json:"stamina"`
20-
MeleeCrit Rating `json:"melee_crit"`
21-
MeleeHaste Rating `json:"melee_haste"`
22-
Mastery Rating `json:"mastery"`
23-
BonusArmor float64 `json:"bonus_armor"`
24-
Lifesteal Rating `json:"lifesteal"`
25-
Versatility int64 `json:"versatility"`
26-
VersatilityDamageDoneBonus float64 `json:"versatility_damage_done_bonus"`
27-
VersatilityHealingDoneBonus float64 `json:"versatility_healing_done_bonus"`
28-
VersatilityDamageTakenBonus float64 `json:"versatility_damage_taken_bonus"`
29-
Avoidance Rating `json:"avoidance"`
30-
AttackPower int64 `json:"attack_power"`
31-
MainHandDamageMin float64 `json:"main_hand_damage_min"`
32-
MainHandDamageMax float64 `json:"main_hand_damage_max"`
33-
MainHandSpeed float64 `json:"main_hand_speed"`
34-
MainHandDps float64 `json:"main_hand_dps"`
35-
OffHandDamageMin float64 `json:"off_hand_damage_min"`
36-
OffHandDamageMax float64 `json:"off_hand_damage_max"`
37-
OffHandSpeed float64 `json:"off_hand_speed"`
38-
OffHandDps float64 `json:"off_hand_dps"`
39-
SpellPower int64 `json:"spell_power"`
40-
SpellPenetration int64 `json:"spell_penetration"`
41-
SpellCrit Rating `json:"spell_crit"`
42-
ManaRegen float64 `json:"mana_regen"`
43-
ManaRegenCombat float64 `json:"mana_regen_combat"`
44-
Armor PrimaryStat `json:"armor"`
45-
Dodge Rating `json:"dodge"`
46-
Parry Rating `json:"parry"`
47-
Block Rating `json:"block"`
48-
RangedCrit Rating `json:"ranged_crit"`
49-
RangedHaste Rating `json:"ranged_haste"`
50-
SpellHaste Rating `json:"spell_haste"`
36+
Lifesteal struct {
37+
Rating float64 `json:"rating"`
38+
RatingBonus float64 `json:"rating_bonus"`
39+
Value float64 `json:"value"`
40+
} `json:"lifesteal"`
41+
VersatilityHealingDoneBonus float64 `json:"versatility_healing_done_bonus"`
42+
MainHandDamageMax float64 `json:"main_hand_damage_max"`
43+
Avoidance struct {
44+
Rating float64 `json:"rating"`
45+
RatingBonus float64 `json:"rating_bonus"`
46+
} `json:"avoidance"`
47+
ManaRegen float64 `json:"mana_regen"`
48+
Health float64 `json:"health"`
49+
Strength struct {
50+
Base float64 `json:"base"`
51+
Effective float64 `json:"effective"`
52+
} `json:"strength"`
53+
Intellect struct {
54+
Base float64 `json:"base"`
55+
Effective float64 `json:"effective"`
56+
} `json:"intellect"`
57+
VersatilityDamageTakenBonus float64 `json:"versatility_damage_taken_bonus"`
58+
Dodge struct {
59+
Rating float64 `json:"rating"`
60+
RatingBonus float64 `json:"rating_bonus"`
61+
Value float64 `json:"value"`
62+
} `json:"dodge"`
63+
Speed struct {
64+
RatingBonus float64 `json:"rating_bonus"`
65+
Rating float64 `json:"rating"`
66+
} `json:"speed"`
67+
MeleeCrit struct {
68+
Rating float64 `json:"rating"`
69+
RatingBonus float64 `json:"rating_bonus"`
70+
Value float64 `json:"value"`
71+
} `json:"melee_crit"`
72+
MainHandSpeed float64 `json:"main_hand_speed"`
73+
OffHandDamageMin float64 `json:"off_hand_damage_min"`
74+
OffHandSpeed float64 `json:"off_hand_speed"`
75+
SpellPower float64 `json:"spell_power"`
76+
RangedCrit struct {
77+
Rating float64 `json:"rating"`
78+
RatingBonus float64 `json:"rating_bonus"`
79+
Value float64 `json:"value"`
80+
} `json:"ranged_crit"`
81+
MainHandDamageMin float64 `json:"main_hand_damage_min"`
82+
OffHandDamageMax float64 `json:"off_hand_damage_max"`
83+
SpellPenetration float64 `json:"spell_penetration"`
84+
Parry struct {
85+
Rating float64 `json:"rating"`
86+
RatingBonus float64 `json:"rating_bonus"`
87+
Value float64 `json:"value"`
88+
} `json:"parry"`
89+
MeleeHaste struct {
90+
Rating float64 `json:"rating"`
91+
RatingBonus float64 `json:"rating_bonus"`
92+
Value float64 `json:"value"`
93+
} `json:"melee_haste"`
94+
Mastery struct {
95+
Rating float64 `json:"rating"`
96+
RatingBonus float64 `json:"rating_bonus"`
97+
Value float64 `json:"value"`
98+
} `json:"mastery"`
99+
BonusArmor float64 `json:"bonus_armor"`
100+
AttackPower float64 `json:"attack_power"`
101+
Character struct {
102+
Key struct {
103+
Href string `json:"href"`
104+
} `json:"key"`
105+
Name string `json:"name"`
106+
Id float64 `json:"id"`
107+
Realm struct {
108+
Slug string `json:"slug"`
109+
Key struct {
110+
Href string `json:"href"`
111+
} `json:"key"`
112+
Name string `json:"name"`
113+
Id float64 `json:"id"`
114+
} `json:"realm"`
115+
} `json:"character"`
116+
Agility struct {
117+
Base float64 `json:"base"`
118+
Effective float64 `json:"effective"`
119+
} `json:"agility"`
120+
SpellHaste struct {
121+
Value float64 `json:"value"`
122+
Rating float64 `json:"rating"`
123+
RatingBonus float64 `json:"rating_bonus"`
124+
} `json:"spell_haste"`
125+
Links struct {
126+
Self struct {
127+
Href string `json:"href"`
128+
} `json:"self"`
129+
} `json:"_links"`
130+
Stamina struct {
131+
Base float64 `json:"base"`
132+
Effective float64 `json:"effective"`
133+
} `json:"stamina"`
134+
Versatility float64 `json:"versatility"`
135+
Armor struct {
136+
Base float64 `json:"base"`
137+
Effective float64 `json:"effective"`
138+
} `json:"armor"`
51139
}
52140

53-
type PrimaryStat struct {
54-
Base int64 `json:"base"`
55-
Effective int64 `json:"effective"`
56-
}
57-
58-
type Rating struct {
59-
Rating int `json:"rating"`
60-
RatingBonus float64 `json:"rating_bonus"`
61-
Value float64 `json:"value"`
62-
}
63-
64-
func (req RequestFunc) CharacterStats(realm string, name string) (stats interface{}, err error) {
141+
func (req RequestFunc) CharacterStatistics(realm string, name string) (s Statistics, err error) {
65142
url := fmt.Sprintf("/profile/wow/character/%s/%s/statistics", realm, name)
66143
body, err := req(url)
67144
if err != nil {
68-
return nil, err
145+
return
69146
}
70147

71-
err = json.Unmarshal(body, &stats)
148+
err = json.Unmarshal(body, &s)
72149
if err != nil {
73-
return nil, err
150+
return
74151
}
75-
return stats, nil
152+
return
76153
}

statistics_test.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@ package wowapi_test
22

33
import (
44
"testing"
5+
6+
"github.com/raph6/wowapi"
57
)
68

7-
func TestCharacterStats(t *testing.T) {
9+
func TestCharacterStatistics(t *testing.T) {
810
// Test with a valid character
9-
stats, err := req.CharacterStats("kirin-tor", "vimdiesel")
11+
var statsStruct wowapi.Statistics
12+
stats, err := req.CharacterStatistics("kirin-tor", "vimdiesel")
1013
if err != nil {
1114
t.Errorf("Failed to get character stats: %v", err)
1215
}
13-
if stats == nil {
16+
if stats == statsStruct {
1417
t.Error("No stats returned")
1518
}
1619

1720
// Test with an invalid character
18-
stats, err = req.CharacterStats("invalidrealmname", "invalidcharactername")
21+
stats, err = req.CharacterStatistics("invalidrealm", "invalidcharactername")
1922
if err == nil {
2023
t.Error("Expected an error, but none was returned")
2124
}
22-
if stats != nil {
25+
if stats != statsStruct {
2326
t.Error("Expected no stats, but some were returned")
2427
}
2528
}

wowapi.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func Client(ApiClientId string, ApiSecret string, region string, lang string) (R
5151
urlEnd := "?namespace=profile-" + region + "&locale=" + lang
5252

5353
return func(url string) ([]byte, error) {
54-
url = urlStart + url + urlEnd
54+
url = urlStart + strings.ToLower(url) + urlEnd
5555
req, err := http.NewRequest("GET", url, nil)
5656
if err != nil {
5757
return nil, err

wowapi_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ func TestMain(m *testing.M) {
1414
token := os.Getenv("API_CLIENT_ID")
1515
secret := os.Getenv("API_SECRET")
1616
var err error
17+
_, err = wowapi.Client(token, secret, "xx", "fr_FR")
18+
if err == nil {
19+
panic("Expected an error, but none was returned, region wrong")
20+
}
21+
_, err = wowapi.Client(token, secret, "eu", "xx")
22+
if err == nil {
23+
panic("Expected an error, but none was returned, lang wrong")
24+
}
25+
1726
req, err = wowapi.Client(token, secret, "eu", "fr_FR")
1827
if err != nil {
1928
panic(err)

0 commit comments

Comments
 (0)