-
Notifications
You must be signed in to change notification settings - Fork 2
/
userstats.go
141 lines (112 loc) · 4.51 KB
/
userstats.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
package kettle
import (
"net/http"
"github.com/dghubble/sling"
)
// ISteamUserStatsService provides access to information about a user's stats.
type ISteamUserStatsService struct {
sling *sling.Sling
}
func newISteamUserStatsService(sling *sling.Sling) *ISteamUserStatsService {
return &ISteamUserStatsService{
sling: sling.Path("ISteamUserStats/"),
}
}
// GetPlayerAchievementsParams are the parameters for ISteamUserStatsService.GetPlayerAchievements
type GetPlayerAchievementsParams struct {
SteamID int64 `url:"steamid"`
AppID int64 `url:"appid"`
Lang string `url:"l,omitempty"`
}
type playerAchievementsResp struct {
PlayerStats PlayerStats `json:"playerstats"`
}
// PlayerStats are returned from ISteamUserStatsService.GetPlayerAchievements
type PlayerStats struct {
SteamID string `json:"steamID"`
GameName string `json:"gameName"`
Achievements []Achievement `json:"achievements"`
Success bool `json:"success"`
}
// Achievement is part of the PlayerStats returned from ISteamUserStatsService.GetPlayerAchievements
type Achievement struct {
APIName string `json:"apiname"`
Achieved int `json:"achieved"`
}
// GetPlayerAchievements Returns a list of achievements for this user by app id
// https://wiki.teamfortress.com/wiki/WebAPI/GetPlayerAchievements
// https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerAchievements_.28v0001.29
func (s *ISteamUserStatsService) GetPlayerAchievements(params *GetPlayerAchievementsParams) (*PlayerStats, *http.Response, error) {
response := new(playerAchievementsResp)
resp, err := s.sling.New().Get("GetPlayerAchievements/v1/").QueryStruct(params).ReceiveSuccess(response)
return &response.PlayerStats, resp, err
}
type gameAchievementResp struct {
AchievementPercentages achievementPercentages `json:"achievementpercentages"`
}
type achievementPercentages struct {
Achievements []GameAchievement `json:"achievements"`
}
// GameAchievement is the response for ISteamUserStatsService.GetGlobalAchievementPercentagesForApp
type GameAchievement struct {
Name string `json:"name"`
Percent float64 `json:"percent"`
}
// GetGlobalAchievementPercentagesForApp Statistics showing how much of the player base have unlocked various achievements.
// https://wiki.teamfortress.com/wiki/WebAPI/GetGlobalAchievementPercentagesForApp
// https://developer.valvesoftware.com/wiki/Steam_Web_API#GetGlobalAchievementPercentagesForApp_.28v0002.29
func (s *ISteamUserStatsService) GetGlobalAchievementPercentagesForApp(gameid int64) ([]GameAchievement, *http.Response, error) {
response := new(gameAchievementResp)
type params struct {
GameID int64 `url:"gameid"`
}
p := ¶ms{
GameID: gameid,
}
resp, err := s.sling.New().Get("GetGlobalAchievementPercentagesForApp/v2/").QueryStruct(p).ReceiveSuccess(response)
return response.AchievementPercentages.Achievements, resp, err
}
type schemaResp struct {
Game GameSchema `json:"game"`
}
// GameSchema is the response for ISteamUserStatsService.GetSchemaForGame
type GameSchema struct {
GameName string `json:"gameName"`
GameVersion string `json:"gameVersion"`
AvailableGameStats Stats `json:"availableGameStats"`
}
// Stats are the listed achievements for a GameSchema
type Stats struct {
Achievements []SchemaAchievement `json:"achievements"`
Stats []SchemaStat `json:"stats"`
}
// SchemaAchievement is an achievement for Stats part of ISteamUserStatsService.GetSchemaForGame
type SchemaAchievement struct {
Name string `json:"name"`
DefaultValue int `json:"defaultvalue"`
DisplayName string `json:"displayName"`
Hidden int `json:"hidden"`
Description string `json:"description"`
Icon string `json:"icon"`
IconGray string `json:"icongray"`
}
// SchemaStat is a stat for Stats part of ISteamUserStatsService.GetSchemaForGame
type SchemaStat struct {
Name string `json:"name"`
DefaultValue int `json:"defaultvalue"`
DisplayName string `json:"displayName"`
}
// GetSchemaForGame returns gamename, gameversion and availablegamestats
// https://wiki.teamfortress.com/wiki/WebAPI/GetSchemaForGame
// https://developer.valvesoftware.com/wiki/Steam_Web_API#GetSchemaForGame_.28v2.29
func (s *ISteamUserStatsService) GetSchemaForGame(appid int64) (*GameSchema, *http.Response, error) {
response := new(schemaResp)
type params struct {
AppID int64 `url:"appid"`
}
p := ¶ms{
AppID: appid,
}
resp, err := s.sling.New().Get("GetSchemaForGame/v2/").QueryStruct(p).ReceiveSuccess(response)
return &response.Game, resp, err
}