This repository has been archived by the owner on Apr 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
clubhouseapi.go
227 lines (209 loc) · 7.08 KB
/
clubhouseapi.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
// Package clubhouseapi handle work with clubhouse
package clubhouseapi
import (
"encoding/json"
"fmt"
"strings"
"github.com/lafin/http"
)
var url = "https://www.clubhouseapi.com/api"
var headers = map[string]string{
"Connection": "keep-alive",
"Content-Type": "application/json",
"Host": "www.clubhouseapi.com",
"Accept": "application/json",
"Accept-Language": "en-US;q=1",
"User-Agent": "clubhouse/304 (iPhone; iOS 14.4; Scale/2.00)",
"CH-Languages": "en-US",
"CH-Locale": "en_US",
"CH-AppVersion": "0.1.28",
"CH-AppBuild": "304",
"CH-DeviceId": "(null)",
"CH-UserID": "(null)",
}
// StartPhoneNumberAuth is a method of logging in by phone
func StartPhoneNumberAuth(phoneNumber string) (StartPhoneNumberAuthResponse, error) {
var data StartPhoneNumberAuthResponse
response, err := http.Post(fmt.Sprintf("%s/start_phone_number_auth", url), strings.NewReader(fmt.Sprintf(`{"phone_number":"%s"}`, phoneNumber)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// CompletePhoneNumberAuth is a method of completing phone authentication
func CompletePhoneNumberAuth(phoneNumber, verificationCode string) (CompletePhoneNumberAuthResponse, error) {
var data CompletePhoneNumberAuthResponse
response, err := http.Post(fmt.Sprintf("%s/complete_phone_number_auth", url), strings.NewReader(fmt.Sprintf(`{"verification_code":"%s","phone_number":"%s"}`, verificationCode, phoneNumber)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// GetChannels is a method of getting all channels
func GetChannels() (GetChannelsResponse, error) {
var data GetChannelsResponse
response, err := http.Get(fmt.Sprintf("%s/get_channels", url), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// JoinChannel is a method to join a channel
func JoinChannel(channel string) (JoinChannelResponse, error) {
var data JoinChannelResponse
response, err := http.Post(fmt.Sprintf("%s/join_channel", url), strings.NewReader(fmt.Sprintf(`{"channel":"%s","attribution_source":"feed","attribution_details":"eyJpc19leHBsb3JlIjpmYWxzZSwicmFuayI6MX0="}`, channel)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// LeaveChannel is a method to leave a channel
func LeaveChannel(channel string) (LeaveChannelResponse, error) {
var data LeaveChannelResponse
response, err := http.Post(fmt.Sprintf("%s/leave_channel", url), strings.NewReader(fmt.Sprintf(`{"channel":"%s"}`, channel)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// ActivePing is a method to ping
func ActivePing(channel string) (ActivePingResponse, error) {
var data ActivePingResponse
response, err := http.Post(fmt.Sprintf("%s/active_ping", url), strings.NewReader(fmt.Sprintf(`{"channel":"%s"}`, channel)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// RefreshToken is a method for getting a new access token
func RefreshToken(refreshToken string) (RefreshTokenResponse, error) {
var data RefreshTokenResponse
response, err := http.Post(fmt.Sprintf("%s/refresh_token", url), strings.NewReader(fmt.Sprintf(`{"refresh":"%s"}`, refreshToken)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// Follow is a user follow method
func Follow(userID int) (FollowResponse, error) {
var data FollowResponse
response, err := http.Post(fmt.Sprintf("%s/follow", url), strings.NewReader(fmt.Sprintf(`{"source":9,"source_topic_id":null,"user_id":%d,"user_ids":null}`, userID)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// Unfollow is a user unfollow method
func Unfollow(userID int) (UnfollowResponse, error) {
var data UnfollowResponse
response, err := http.Post(fmt.Sprintf("%s/unfollow", url), strings.NewReader(fmt.Sprintf(`{"user_id":%d}`, userID)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// GetFollowing is a get following method
func GetFollowing(userID, pageSize, page int) (GetFollowingResponse, error) {
if pageSize == 0 {
pageSize = 400
}
if page == 0 {
page = 1
}
var data GetFollowingResponse
response, err := http.Post(fmt.Sprintf("%s/get_following?page_size=%d&page=%d", url, pageSize, page), strings.NewReader(fmt.Sprintf(`{"user_id":%d}`, userID)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// GetFollowers is a get followers method
func GetFollowers(userID, pageSize, page int) (GetFollowersResponse, error) {
if pageSize == 0 {
pageSize = 400
}
if page == 0 {
page = 1
}
var data GetFollowersResponse
response, err := http.Post(fmt.Sprintf("%s/get_followers?page_size=%d&page=%d", url, pageSize, page), strings.NewReader(fmt.Sprintf(`{"user_id":%d}`, userID)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// GetProfile is a get profile method
func GetProfile(userID int) (GetProfileResponse, error) {
var data GetProfileResponse
response, err := http.Post(fmt.Sprintf("%s/get_profile", url), strings.NewReader(fmt.Sprintf(`{"user_id":%d}`, userID)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// AudienceReply is a raise hand method
func AudienceReply(channel string, raiseHand bool) (AudienceReplyResponse, error) {
var data AudienceReplyResponse
response, err := http.Post(fmt.Sprintf("%s/audience_reply", url), strings.NewReader(fmt.Sprintf(`{"channel":"%s","raise_hands":%t,"unraise_hands":%t}`, channel, raiseHand, !raiseHand)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// AcceptSpeakerInvite is an accept speaker invite method
func AcceptSpeakerInvite(channel string, userID int) (AcceptSpeakerInviteResponse, error) {
var data AcceptSpeakerInviteResponse
response, err := http.Post(fmt.Sprintf("%s/accept_speaker_invite", url), strings.NewReader(fmt.Sprintf(`{"channel":"%s","user_id":%d}`, channel, userID)), headers)
if err != nil {
return data, err
}
if err := json.Unmarshal(response, &data); err != nil {
return data, err
}
return data, nil
}
// AddCredentials is a method of adding credentials such as User ID or Access Token
func AddCredentials(credentials map[string]string) {
for k, v := range credentials {
headers[k] = v
}
}