-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathfriends.go
55 lines (45 loc) · 1.28 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
51
52
53
54
55
package steamapi
import (
"net/url"
"strconv"
)
// Relationship is a type of relationship
type Relationship string
const (
// All is a type of relationship
All Relationship = "all"
// Friend is a type of relationship
Friend Relationship = "friend"
)
// SteamFriend is a relationship between two steam users
type SteamFriend struct {
SteamID uint64 `json:",string"`
Relationship Relationship
FriendSince int64 `json:"friend_since"`
}
type playerFriendsListJSON struct {
Friendslist *struct {
Friends []SteamFriend
}
}
// GetFriendsList 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 GetFriendsList(steamID uint64, filter Relationship, apiKey string) ([]SteamFriend, error) {
var getFriendsList = NewSteamMethod("ISteamUser", "GetFriendList", 1)
data := url.Values{}
data.Add("key", apiKey)
data.Add("steamid", strconv.FormatUint(steamID, 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
}