-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.go
394 lines (331 loc) · 12.9 KB
/
user.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
package clubhouse
import (
"net/http"
"time"
)
type BaseUserProfile struct {
Name *string `json:"name"`
PhotoURL *string `json:"photo_url"`
UserID int `json:"user_id"`
Username *string `json:"username"`
}
type FollowerUserProfile struct {
BaseUserProfile
Bio *string `json:"bio"`
LastActiveMinutes *int `json:"last_active_minutes"`
Twitter *string `json:"twitter"`
}
type FollowingUserProfile struct {
BaseUserProfile
Bio *string `json:"bio"`
Twitter *string `json:"twitter"`
}
type SearchUserProfile struct {
BaseUserProfile
Bio *string `json:"bio"`
UserID int `json:"user_id,string"` // User IDs are returned as strings in search results
}
type UserProfile struct {
BaseUserProfile
Bio *string `json:"bio"`
BioLinks []BioLink `json:"bio_links"`
CanEditDisplayname bool `json:"can_edit_displayname"`
CanEditName bool `json:"can_edit_name"`
CanEditUsername bool `json:"can_edit_username"`
CanReceiveDirectPayment bool `json:"can_receive_direct_payment"`
Clubs []Club `json:"clubs"`
DirectPaymentFeeFixed float64 `json:"direct_payment_fee_fixed"`
DirectPaymentFeeRate float64 `json:"direct_payment_fee_rate"`
Displayname *string `json:"displayname"`
FollowsMe bool `json:"follows_me"`
HasVerifiedEmail bool `json:"has_verified_email"`
Instagram *string `json:"instagram"`
InvitedByClub *Club `json:"invited_by_club"`
InvitedByUserProfile *BaseUserProfile `json:"invited_by_user_profile"`
IsBlockedByNetwork bool `json:"is_blocked_by_network"`
MutualFollows []BaseUserProfile `json:"mutual_follows"`
MutualFollowsCount int `json:"mutual_follows_count"`
NotificationType *int `json:"notification_type"`
NumFollowers int `json:"num_followers"`
NumFollowing int `json:"num_following"`
TimeCreated time.Time `json:"time_created"`
Topics []Topic `json:"topics"`
Twitter *string `json:"twitter"`
UpcomingEvents []Event `json:"upcoming_events"`
Url *string `json:"url"`
}
type BioLink struct {
Length int `json:"length"`
Position int `json:"position"`
TargetID int `json:"target_id"`
Type string `json:"type"`
}
type AddEmailParams struct {
Email string `json:"email"`
}
type AddEmailResponse struct {
Response
}
func (c *Client) AddEmail(params *UpdateNameParams) (*AddEmailResponse, *http.Response, error) {
apiRes := new(AddEmailResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("add_email").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type BlockParams struct {
UserID int `json:"user_id,omitempty"`
Username string `json:"username,omitempty"`
}
type BlockResponse struct {
Response
}
func (c *Client) Block(params *BlockParams) (*BlockResponse, *http.Response, error) {
apiRes := new(BlockResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("block").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type FollowParams struct {
Source int `json:"source"` // TODO: Document all sources
SourceTopicID *int `json:"source_topic_id"`
UserIDS *[]int `json:"user_ids"`
UserID int `json:"user_id"`
}
type FollowResponse struct {
Response
}
func (c *Client) Follow(params *FollowParams) (*FollowResponse, *http.Response, error) {
apiRes := new(FollowResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("follow").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type GetFollowersParams struct {
UserID int `url:"user_id"`
Page *int `json:"-" url:"page,omitempty"`
PageSize *int `json:"-" url:"page_size,omitempty"`
}
type GetFollowersResponse struct {
PageResponse
Users []FollowerUserProfile `json:"users"`
}
func (c *Client) GetFollowers(params *GetFollowersParams) (*GetFollowersResponse, *http.Response, error) {
apiRes := new(GetFollowersResponse)
apiError := new(APIError)
res, err := c.sling.New().Get("get_followers").QueryStruct(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type GetFollowingParams struct {
UserID int `url:"user_id"`
Page *int `json:"-" url:"page,omitempty"`
PageSize *int `json:"-" url:"page_size,omitempty"`
}
type GetFollowingResponse struct {
PageResponse
Clubs []Club `json:"clubs"`
Users []FollowingUserProfile `json:"users"`
}
func (c *Client) GetFollowing(params *GetFollowingParams) (*GetFollowingResponse, *http.Response, error) {
apiRes := new(GetFollowingResponse)
apiError := new(APIError)
res, err := c.sling.New().Get("get_following").QueryStruct(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type GetMutualFollowsParams struct {
UserID int `url:"user_id"`
Page *int `json:"-" url:"page,omitempty"`
PageSize *int `json:"-" url:"page_size,omitempty"`
}
type GetMutualFollowsResponse struct {
PageResponse
Users []FollowerUserProfile `json:"users"`
}
func (c *Client) GetMutualFollows(params *GetMutualFollowsParams) (*GetMutualFollowsResponse, *http.Response, error) {
apiRes := new(GetMutualFollowsResponse)
apiError := new(APIError)
res, err := c.sling.New().Get("get_mutual_follows").QueryStruct(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type GetOnlineFriendsParams struct{}
type GetOnlineFriendsResponse struct {
Clubs []struct {
Club
IsAdmin bool `json:"is_admin"`
OnlineMembers []BaseUserProfile `json:"online_members"`
} `json:"clubs"`
Users []struct {
BaseUserProfile
Channel *string `json:"channel,omitempty"`
IsSpeaker *bool `json:"is_speaker,omitempty"`
LastActiveMinutes int `json:"last_active_minutes"`
Topic *string `json:"topic,omitempty"`
} `json:"users"`
}
func (c *Client) GetOnlineFriends() (*GetOnlineFriendsResponse, *http.Response, error) {
params := &GetOnlineFriendsParams{}
apiRes := new(GetOnlineFriendsResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("get_online_friends").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type GetProfileParams struct {
UserID int `json:"user_id,omitempty"`
Username string `json:"username,omitempty"`
}
type GetProfileResponse struct {
Response
UserProfile UserProfile `json:"user_profile"`
}
func (c *Client) GetProfile(params *GetProfileParams) (*GetProfileResponse, *http.Response, error) {
apiRes := new(GetProfileResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("get_profile").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type GetRecentChannelsSpeakersParams struct {
Page *int `json:"-" url:"page,omitempty"`
PageSize *int `json:"-" url:"page_size,omitempty"`
}
type GetRecentChannelsSpeakersResponse struct {
PageResponse
Users []FollowingUserProfile `json:"users"`
}
func (c *Client) GetRecentChannelsSpeakers(params *GetRecentChannelsSpeakersParams) (*GetRecentChannelsSpeakersResponse, *http.Response, error) {
apiRes := new(GetRecentChannelsSpeakersResponse)
apiError := new(APIError)
res, err := c.sling.New().Get("get_recent_channels_speakers").QueryStruct(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type InviteToAppParams struct {
Message *string `json:"message"`
Name *string `json:"name"`
PhoneNumber string `json:"phone_number"`
}
type InviteToAppResponse struct {
Response
}
func (c *Client) InviteToApp(params *InviteToAppParams) (*InviteToAppResponse, *http.Response, error) {
apiRes := new(InviteToAppResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("invite_to_app").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type MeParams struct {
ReturnBlockedIds bool `json:"return_blocked_ids"`
TimezoneIdentifier string `json:"timezone_identifier"`
ReturnFollowingIds bool `json:"return_following_ids"`
}
type MeResponse struct {
Response
AccessToken string `json:"access_token"`
ActionableNotificationsCount int `json:"actionable_notifications_count"`
AuthToken string `json:"auth_token"`
BlockedIds *[]int `json:"blocked_ids"`
Email string `json:"email"`
FeatureFlags []string `json:"feature_flags"`
FollowingIds *[]int `json:"following_ids"`
HasUnreadNotifications bool `json:"has_unread_notifications"`
IsAdmin bool `json:"is_admin"`
IsAmbassador bool `json:"is_ambassador"`
NotificationsEnabled bool `json:"notifications_enabled"`
NumInvites int `json:"num_invites"`
RefreshToken string `json:"refresh_token"`
ServiceStatus *struct {
ButtonTitle string `json:"button_title"`
Message string `json:"message"`
Title string `json:"title"`
URL string `json:"url"`
} `json:"service_status"`
UserProfile BaseUserProfile `json:"user_profile"`
}
func (c *Client) Me(params *MeParams) (*MeResponse, *http.Response, error) {
apiRes := new(MeResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("me").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type SearchUsersParams struct {
CofollowsOnly bool `json:"cofollows_only" url:"-"`
FollowersOnly bool `json:"followers_only" url:"-"`
FollowingOnly bool `json:"following_only" url:"-"`
Query string `json:"query" url:"-"`
Page *int `json:"-" url:"page,omitempty"`
PageSize *int `json:"-" url:"page_size,omitempty"`
}
type SearchUsersResponse struct {
PageResponse
QueryID string `json:"query_id"`
Users []SearchUserProfile `json:"users"`
}
func (c *Client) SearchUsers(params *SearchUsersParams) (*SearchUsersResponse, *http.Response, error) {
apiRes := new(SearchUsersResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("search_users").BodyJSON(params).QueryStruct(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type UnblockParams struct {
UserID int `json:"user_id,omitempty"`
Username string `json:"username,omitempty"`
}
type UnblockResponse struct {
Response
}
func (c *Client) Unblock(params *UnblockParams) (*UnblockResponse, *http.Response, error) {
apiRes := new(UnblockResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("unblock").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type UnfollowParams struct {
UserID int `json:"user_id,omitempty"`
Username string `json:"username,omitempty"`
}
type UnfollowResponse struct {
Response
}
func (c *Client) Unfollow(params *UnfollowParams) (*UnfollowResponse, *http.Response, error) {
apiRes := new(UnfollowResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("unfollow").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type UpdateBioParams struct {
Bio string `json:"bio"`
}
type UpdateBioResponse struct {
Response
}
func (c *Client) UpdateBio(params *UpdateBioParams) (*UpdateBioResponse, *http.Response, error) {
apiRes := new(UpdateBioResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("update_bio").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type UpdateNameParams struct {
Name string `json:"name"`
}
type UpdateNameResponse struct {
Response
ErrorMessage *string `json:"error_message"`
}
func (c *Client) UpdateName(params *UpdateNameParams) (*UpdateNameResponse, *http.Response, error) {
apiRes := new(UpdateNameResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("update_name").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}
type UpdateUsernameParams struct {
TwitterToken *string `json:"twitter_token"`
TwitterSecret *string `json:"twitter_secret"`
Username string `json:"username"`
}
type UpdateUsernameResponse struct {
Response
ErrorMessage *string `json:"error_message"`
}
func (c *Client) UpdateUsername(params *UpdateUsernameParams) (*UpdateUsernameResponse, *http.Response, error) {
apiRes := new(UpdateUsernameResponse)
apiError := new(APIError)
res, err := c.sling.New().Post("update_username").BodyJSON(params).Receive(apiRes, apiError)
return apiRes, res, relevantError(err, *apiError)
}