Completed
Push — master ( 84a22b...cf3721 )
by Luca
02:04
created

UserModel   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 331
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 35
lcom 1
cbo 2
dl 0
loc 331
rs 9
c 0
b 0
f 0

35 Methods

Rating   Name   Duplication   Size   Complexity  
A loginToUserAccount() 0 4 1
A logoutOfUserAccount() 0 4 1
A getAuthenticatedUser() 0 4 1
A createUser() 0 4 1
A getUsers() 0 4 1
A getUsersByIds() 0 4 1
A searchUsers() 0 4 1
A autocompleteUsers() 0 4 1
A getUser() 0 4 1
A updateUser() 0 4 1
A deactivateUserAccount() 0 4 1
A patchUser() 0 4 1
A updateUserRoles() 0 4 1
A updateUserActive() 0 4 1
A getUserProfileImage() 0 4 1
A setUserProfileImage() 0 4 1
A getUserByUsername() 0 4 1
A resetPassword() 0 4 1
A updateUserMfa() 0 4 1
A generateMfaSecret() 0 4 1
A checkMfa() 0 4 1
A updateUserPassword() 0 4 1
A sendPasswordResetEmail() 0 4 1
A getUserByEmail() 0 4 1
A getUserSessions() 0 4 1
A revokeUserSession() 0 4 1
A attachMobileDevice() 0 4 1
A getUserAudits() 0 4 1
A verifyUserEmail() 0 4 1
A sendVerificationEmail() 0 4 1
A switchLoginMethod() 0 4 1
A createToken() 0 4 1
A getTokens() 0 4 1
A getToken() 0 4 1
A revokeToken() 0 4 1
1
<?php
2
/**
3
 * This Driver is based entirely on official documentation of the Mattermost Web
4
 * Services API and you can extend it by following the directives of the documentation.
5
 *
6
 * God bless this mess.
7
 *
8
 * @author Luca Agnello <[email protected]>
9
 * @link https://api.mattermost.com/
10
 */
11
12
namespace Gnello\Mattermost\Models;
13
14
/**
15
 * Class UserEntity
16
 *
17
 * @package Gnello\MattermostRestApi\Entities
18
 */
19
class UserModel extends AbstractModel
20
{
21
    /**
22
     * @var string
23
     */
24
    public static $endpoint = '/users';
25
26
    /**
27
     * @param array $requestOptions
28
     * @return \Psr\Http\Message\ResponseInterface
29
     */
30
    public function loginToUserAccount(array $requestOptions)
31
    {
32
        return $this->client->post(self::$endpoint . '/login', $requestOptions);
33
    }
34
35
    /**
36
     * @return \Psr\Http\Message\ResponseInterface
37
     */
38
    public function logoutOfUserAccount()
39
    {
40
        return $this->client->post(self::$endpoint . '/logout');
41
    }
42
43
    /**
44
     * @return \Psr\Http\Message\ResponseInterface
45
     */
46
    public function getAuthenticatedUser()
47
    {
48
        return $this->client->get(self::$endpoint . '/me');
49
    }
50
51
    /**
52
     * @param array $requestOptions
53
     * @return \Psr\Http\Message\ResponseInterface
54
     */
55
    public function createUser(array $requestOptions)
56
    {
57
        return $this->client->post(self::$endpoint, $requestOptions);
58
    }
59
60
    /**
61
     * @param array $requestOptions
62
     * @return \Psr\Http\Message\ResponseInterface
63
     */
64
    public function getUsers(array $requestOptions)
65
    {
66
        return $this->client->get(self::$endpoint, $requestOptions);
67
    }
68
69
    /**
70
     * @param $requestOptions
71
     * @return \Psr\Http\Message\ResponseInterface
72
     */
73
    public function getUsersByIds(array $requestOptions)
74
    {
75
        return $this->client->post(self::$endpoint . '/ids', $requestOptions);
76
    }
77
78
    /**
79
     * @param array $requestOptions
80
     * @return \Psr\Http\Message\ResponseInterface
81
     */
82
    public function searchUsers(array $requestOptions)
83
    {
84
        return $this->client->post(self::$endpoint . '/search', $requestOptions);
85
    }
86
87
    /**
88
     * @param array $requestOptions
89
     * @return \Psr\Http\Message\ResponseInterface
90
     */
91
    public function autocompleteUsers(array $requestOptions)
92
    {
93
        return $this->client->get(self::$endpoint . '/autocomplete', $requestOptions);
94
    }
95
96
    /**
97
     * @param $userId
98
     * @return \Psr\Http\Message\ResponseInterface
99
     */
100
    public function getUser($userId)
101
    {
102
        return $this->client->get(self::$endpoint . '/' . $userId);
103
    }
104
105
    /**
106
     * @param $userId
107
     * @param array $requestOptions
108
     * @return \Psr\Http\Message\ResponseInterface
109
     */
110
    public function updateUser($userId, array $requestOptions)
111
    {
112
        return $this->client->put(self::$endpoint . '/' . $userId, $requestOptions);
113
    }
114
115
    /**
116
     * @param $userId
117
     * @return \Psr\Http\Message\ResponseInterface
118
     */
119
    public function deactivateUserAccount($userId)
120
    {
121
        return $this->client->delete(self::$endpoint . '/' . $userId);
122
    }
123
124
    /**
125
     * @param $userId
126
     * @param array $requestOptions
127
     * @return \Psr\Http\Message\ResponseInterface
128
     */
129
    public function patchUser($userId, array $requestOptions)
130
    {
131
        return $this->client->put(self::$endpoint . '/' . $userId . '/patch', $requestOptions);
132
    }
133
134
    /**
135
     * @param $userId
136
     * @param array $requestOptions
137
     * @return \Psr\Http\Message\ResponseInterface
138
     */
139
    public function updateUserRoles($userId, array $requestOptions)
140
    {
141
        return $this->client->put(self::$endpoint . '/' . $userId . '/roles', $requestOptions);
142
    }
143
144
    /**
145
     * @param $userId
146
     * @param array $requestOptions
147
     * @return \Psr\Http\Message\ResponseInterface
148
     */
149
    public function updateUserActive($userId, array $requestOptions)
150
    {
151
        return $this->client->put(self::$endpoint . '/' . $userId . '/active', $requestOptions);
152
    }
153
154
    /**
155
     * @param $userId
156
     * @return \Psr\Http\Message\ResponseInterface
157
     */
158
    public function getUserProfileImage($userId)
159
    {
160
        return $this->client->get(self::$endpoint . '/' . $userId . '/image');
161
    }
162
163
    /**
164
     * @param $userId
165
     * @param array $requestOptions
166
     * @return \Psr\Http\Message\ResponseInterface
167
     */
168
    public function setUserProfileImage($userId, array $requestOptions)
169
    {
170
        return $this->client->post(self::$endpoint . '/' . $userId . '/image', $requestOptions, 'multipart');
171
    }
172
173
    /**
174
     * @param $username
175
     * @return \Psr\Http\Message\ResponseInterface
176
     */
177
    public function getUserByUsername($username)
178
    {
179
        return $this->client->get(self::$endpoint . '/username/' . $username);
180
    }
181
182
    /**
183
     * @param $requestOptions
184
     * @return \Psr\Http\Message\ResponseInterface
185
     */
186
    public function resetPassword(array $requestOptions)
187
    {
188
        return $this->client->post(self::$endpoint . '/password/reset', $requestOptions);
189
    }
190
    
191
    /**
192
     * @param $userId
193
     * @param $requestOptions
194
     * @return \Psr\Http\Message\ResponseInterface
195
     */
196
    public function updateUserMfa($userId, array $requestOptions)
197
    {
198
        return $this->client->put(self::$endpoint . '/' . $userId . '/mfa', $requestOptions);
199
    }
200
201
    /**
202
     * @param $userId
203
     * @param $requestOptions
204
     * @return \Psr\Http\Message\ResponseInterface
205
     */
206
    public function generateMfaSecret($userId, array $requestOptions)
207
    {
208
        return $this->client->post(self::$endpoint . '/' . $userId . '/mfa/generate', $requestOptions);
209
    }
210
211
    /**
212
     * @param $requestOptions
213
     * @return \Psr\Http\Message\ResponseInterface
214
     */
215
    public function checkMfa(array $requestOptions)
216
    {
217
        return $this->client->post(self::$endpoint . '/mfa', $requestOptions);
218
    }
219
220
    /**
221
     * @param $userId
222
     * @param $requestOptions
223
     * @return \Psr\Http\Message\ResponseInterface
224
     */
225
    public function updateUserPassword($userId, array $requestOptions)
226
    {
227
        return $this->client->put(self::$endpoint . '/' . $userId . '/password', $requestOptions);
228
    }
229
230
    /**
231
     * @param $requestOptions
232
     * @return \Psr\Http\Message\ResponseInterface
233
     */
234
    public function sendPasswordResetEmail(array $requestOptions)
235
    {
236
        return $this->client->post(self::$endpoint . '/password/reset/send', $requestOptions);
237
    }
238
239
    /**
240
     * @param $email
241
     * @return \Psr\Http\Message\ResponseInterface
242
     */
243
    public function getUserByEmail($email)
244
    {
245
        return $this->client->get(self::$endpoint . '/email/' . $email);
246
    }
247
248
    /**
249
     * @param $userId
250
     * @return \Psr\Http\Message\ResponseInterface
251
     */
252
    public function getUserSessions($userId)
253
    {
254
        return $this->client->get(self::$endpoint . '/' . $userId . '/sessions');
255
    }
256
257
    /**
258
     * @param $userId
259
     * @param array $requestOptions
260
     * @return \Psr\Http\Message\ResponseInterface
261
     */
262
    public function revokeUserSession($userId, array $requestOptions)
263
    {
264
        return $this->client->post(self::$endpoint . '/' . $userId . '/sessions/revoke', $requestOptions);
265
    }
266
267
    /**
268
     * @param $requestOptions
269
     * @return \Psr\Http\Message\ResponseInterface
270
     */
271
    public function attachMobileDevice(array $requestOptions)
272
    {
273
        return $this->client->put(self::$endpoint . '/sessions/device', $requestOptions);
274
    }
275
276
    /**
277
     * @param $userId
278
     * @return \Psr\Http\Message\ResponseInterface
279
     */
280
    public function getUserAudits($userId)
281
    {
282
        return $this->client->get(self::$endpoint . '/' . $userId . '/audits');
283
    }
284
285
    /**
286
     * @param array $requestOptions
287
     * @return \Psr\Http\Message\ResponseInterface
288
     */
289
    public function verifyUserEmail(array $requestOptions)
290
    {
291
        return $this->client->post(self::$endpoint . '/email/verify', $requestOptions);
292
    }
293
294
    /**
295
     * @param array $requestOptions
296
     * @return \Psr\Http\Message\ResponseInterface
297
     */
298
    public function sendVerificationEmail(array $requestOptions)
299
    {
300
        return $this->client->post(self::$endpoint . '/email/verify/send', $requestOptions);
301
    }
302
303
    /**
304
     * @param array $requestOptions
305
     * @return \Psr\Http\Message\ResponseInterface
306
     */
307
    public function switchLoginMethod(array $requestOptions)
308
    {
309
        return $this->client->post(self::$endpoint . '/login/switch', $requestOptions);
310
    }
311
312
    /**
313
     * @param $userId
314
     * @param $requestOptions
315
     * @return \Psr\Http\Message\ResponseInterface
316
     */
317
    public function createToken($userId, array $requestOptions)
318
    {
319
        return $this->client->post(self::$endpoint . '/' . $userId . '/tokens', $requestOptions);
320
    }
321
322
    /**
323
     * @param $userId
324
     * @param $requestOptions
325
     * @return \Psr\Http\Message\ResponseInterface
326
     */
327
    public function getTokens($userId, array $requestOptions)
328
    {
329
        return $this->client->get(self::$endpoint . '/' . $userId . '/tokens', $requestOptions);
330
    }
331
332
    /**
333
     * @param $tokenId
334
     * @return \Psr\Http\Message\ResponseInterface
335
     */
336
    public function getToken($tokenId)
337
    {
338
        return $this->client->get(self::$endpoint . '/tokens/' . $tokenId);
339
    }
340
341
    /**
342
     * @param $requestOptions
343
     * @return \Psr\Http\Message\ResponseInterface
344
     */
345
    public function revokeToken(array $requestOptions)
346
    {
347
        return $this->client->post(self::$endpoint . '/users/tokens/revoke', $requestOptions);
348
    }
349
}
350