-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.go
116 lines (83 loc) · 1.98 KB
/
users.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
package vrcapi
import (
"encoding/json"
"fmt"
"net/url"
)
/*
TODO API Endpoints
_SearchAllUsers
GetUserById
_UpdateUserInfo
_GetUserGroups
GetUserGroupRequests
GetUserCurrentRepresentedGroup
*/
func (api *VRChatAPI) SearchAllUsers(displayName string, max, offset int, findDeveloper bool) ([]User, error) {
if !api.LoggedIn {
return nil, fmt.Errorf("not logged in")
}
if max > 100 {
return nil, fmt.Errorf("max must be less than or equal to 100")
}
queryParams := url.Values{
"search": {displayName},
"n": {fmt.Sprintf("%d", max)},
"offset": {fmt.Sprintf("%d", offset)},
}
if findDeveloper {
queryParams.Add("developerType", "internal")
}
resp, err := api.SendRequest("GET", "users?"+queryParams.Encode(), "")
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, api.HandleResponeError(resp)
}
friends := []User{}
err = json.NewDecoder(resp.Body).Decode(&friends)
if err != nil {
return nil, err
}
return friends, nil
}
func (api *VRChatAPI) UpdateUserInfo(userID, jsonData string) (User, error) {
if !api.LoggedIn {
return User{}, fmt.Errorf("not logged in")
}
resp, err := api.SendRequest("PUT", "users/"+userID, jsonData)
if err != nil {
return User{}, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return User{}, api.HandleResponeError(resp)
}
user := User{}
err = json.NewDecoder(resp.Body).Decode(&user)
if err != nil {
return User{}, err
}
return user, nil
}
func (api *VRChatAPI) GetUserGroups(userId string) ([]LimitedUserGroups, error) {
if !api.LoggedIn {
return nil, fmt.Errorf("not logged in")
}
resp, err := api.SendRequest("GET", "users/"+userId+"/groups", "")
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, api.HandleResponeError(resp)
}
defer resp.Body.Close()
groups := []LimitedUserGroups{}
err = json.NewDecoder(resp.Body).Decode(&groups)
if err != nil {
return nil, err
}
return groups, nil
}