forked from Philipp15b/go-steamapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
friends.go
50 lines (41 loc) · 1.1 KB
/
friends.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
package steamapi
import (
"net/url"
"strconv"
)
type Relationship string
const (
All Relationship = "all"
Friend = "friend"
)
type SteamFriend struct {
SteamId uint64 `json:",string"`
Relationship Relationship
FriendSince int64 `json:"friend_since"`
}
type playerFriendsListJson struct {
Friendslist *struct {
Friends []SteamFriend
}
}
var getFriendsList = NewSteamMethod("ISteamUser", "GetFriendList", 1)
// Fetches the friends of the given steam id and returns the result.
//
// It returns nil if the profile is private or if there were no friends
// found for the given relationship. In either one of both cases, no error
// is returned.
func (api *Api) GetFriendsList(id uint64, filter Relationship) ([]SteamFriend, error) {
data := url.Values{}
data.Add("key", api.GetApiKey())
data.Add("steamid", strconv.FormatUint(id, 10))
data.Add("relationship", string(filter))
var resp playerFriendsListJson
err := getFriendsList.Request(data, &resp)
if err != nil {
return nil, err
}
if resp.Friendslist == nil {
return nil, nil
}
return resp.Friendslist.Friends, nil
}