forked from Philipp15b/go-steamapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiles.go
111 lines (94 loc) · 2.8 KB
/
profiles.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
package steamapi
import (
"net/url"
"strconv"
"strings"
)
// CommunityVisibilityState contains the visibility of the user
type CommunityVisibilityState int
const (
// Private community visibility state
Private CommunityVisibilityState = 1
// FriendsOnly community visibility state
FriendsOnly CommunityVisibilityState = 2
// Public community visibility state
Public CommunityVisibilityState = 3
)
// PersonaState is the visibility state
type PersonaState int
const (
// Offline persona state is also
// used when the steam user has set his profile
// to private.
Offline PersonaState = iota
// Online is online
Online
// Busy is busy
Busy
// Away is away
Away
// Snooze is sniooze
Snooze
// LookingToTrade is looking to trade
LookingToTrade
// LookingToPlay is looking ot play
LookingToPlay
)
// PlayerSummary gives an overall state of the user in steam community
type PlayerSummary struct {
SteamID uint64 `json:",string"`
CommunityVisibilityState CommunityVisibilityState
ProfileURL string
ProfileState int // Set to 1 if the player has configured the profile.
PersonaName string
LastLogoff int64
PersonaState PersonaState
SmallAvatarURL string `json:"avatar"` // 32x32
MediumAvatarURL string `json:"avatarmedium"` // 64x64
LargeAvatarURL string `json:"avatarfull"` // 184x184
TimeCreated int64 `json:",omitempty"`
RealName string `json:",omitempty"`
GameExtraInfo string `json:",omitempty"`
PrimaryClanID uint64 `json:",string,omitempty"`
}
type playerSummaryJSON struct {
Response struct {
Players []PlayerSummary
}
}
// GetPlayerSummaries Fetches the player summaries for the given Steam Ids.
func GetPlayerSummaries(ids []uint64, apiKey string) ([]PlayerSummary, error) {
var getPlayerSummaries = NewSteamMethod("ISteamUser", "GetPlayerSummaries", 2)
strIds := make([]string, len(ids))
for _, id := range ids {
strIds = append(strIds, strconv.FormatUint(id, 10))
}
vals := url.Values{}
vals.Add("key", apiKey)
vals.Add("steamids", strings.Join(strIds, ","))
var resp playerSummaryJSON
err := getPlayerSummaries.Request(vals, &resp)
if err != nil {
return nil, err
}
return resp.Response.Players, nil
}
// ResolveVanityURLResponse resolves the response from steam
type ResolveVanityURLResponse struct {
Success int
SteamID uint64 `json:",omitempty,string"`
Message string `json:",omitempty"`
}
// ResolveVanityURL should return a response
func ResolveVanityURL(vanityURL string, apiKey string) (*ResolveVanityURLResponse, error) {
var resolveVanityURL = NewSteamMethod("ISteamUser", "ResolveVanityURL", 1)
data := url.Values{}
data.Add("key", apiKey)
data.Add("vanityURL", vanityURL)
var resp ResolveVanityURLResponse
err := resolveVanityURL.Request(data, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}