-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuser.go
More file actions
150 lines (114 loc) · 3.54 KB
/
user.go
File metadata and controls
150 lines (114 loc) · 3.54 KB
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
package sendbird
type UserRequest struct {
RequestDefaults
Id string `json:"id,omitempty"`
Nickname string `json:"nickname,omitempty"`
ImageUrl string `json:"image_url,omitempty"`
IssueAccessToken bool `json:"issue_access_token,omitempty"`
}
type BlockRequest struct {
RequestDefaults
Id string `json:"id"`
TargetId string `json:"target_id,omitempty"`
}
type DeactivateRequest struct {
RequestDefaults
Id string `json:"id"`
}
type User struct {
Id string `json:"id,omitempty"`
UserId string `json:"user_id,omitempty"`
Nickname string `json:"nickname"`
Picture string `json:"picture"`
AccessToken string `json:"access_token,omitempty"`
IsActive bool `json:"is_active,omitempty"`
}
// UserService is an interface for interfacing with the User
// endpoints of the Sendbird API
type UserService interface {
Create(*UserRequest) (*User, *Response, error)
Update(params *UserRequest) (*User, *Response, error)
Auth(params *UserRequest) (*User, *Response, error)
Block(params *BlockRequest) (*Response, error)
UnBlock(params *BlockRequest) (*Response, error)
Deactivate(params *DeactivateRequest) (*Response, error)
}
// UserServiceOp handles communication with the User related methods of
// the Sendbird API.
type UserServiceOp struct {
client *SendbirdClient
}
var _ UserService = &UserServiceOp{}
// Create creates a new user account using id / nickname / profile image combination
func (s *UserServiceOp) Create(params *UserRequest) (*User, *Response, error) {
path := "/user/create"
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, *params)
createdUser := new(User)
resp, err := s.client.Do(req, createdUser)
// log.Info(resp)
if err != nil {
return nil, resp, err
}
return createdUser, resp, nil
}
// Update updates a user
func (s *UserServiceOp) Update(params *UserRequest) (*User, *Response, error) {
path := "/user/update"
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, *params)
updatedUser := new(User)
resp, err := s.client.Do(req, updatedUser)
if err != nil {
return nil, resp, err
}
return updatedUser, resp, nil
}
// Auth retrieve a user's information
func (s *UserServiceOp) Auth(params *UserRequest) (*User, *Response, error) {
path := "/user/auth"
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, *params)
user := new(User)
resp, err := s.client.Do(req, user)
if err != nil {
return nil, resp, err
}
return user, resp, nil
}
// Block blocks a target user
func (s *UserServiceOp) Block(params *BlockRequest) (*Response, error) {
path := "/user/block"
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, *params)
var i interface{}
resp, err := s.client.Do(req, i)
if err != nil {
return resp, err
}
return resp, nil
}
// Unblock unblocks a target user.
func (s *UserServiceOp) UnBlock(params *BlockRequest) (*Response, error) {
path := "/user/unblock"
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, *params)
var i interface{}
resp, err := s.client.Do(req, i)
if err != nil {
return resp, err
}
return resp, nil
}
// Deactivate deactivates a user.
func (s *UserServiceOp) Deactivate(params *DeactivateRequest) (*Response, error) {
path := "/user/deactivate"
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, *params)
var i interface{}
resp, err := s.client.Do(req, i)
if err != nil {
return resp, err
}
return resp, nil
}