Completed
Push — master ( 222ae3...326e49 )
by Luca
02:02
created

UserModel::returnUserDefaultProfileImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
use GuzzleHttp\RequestOptions;
15
use Psr\Http\Message\ResponseInterface;
16
17
/**
18
 * Class UserEntity
19
 *
20
 * @package Gnello\MattermostRestApi\Entities
21
 */
22
class UserModel extends AbstractModel
23
{
24
    /**
25
     * @var string
26
     */
27
    public static $endpoint = '/users';
28
29
    /**
30
     * @param array $requestOptions
31
     * @return ResponseInterface
32
     */
33
    public function loginToUserAccount(array $requestOptions)
34
    {
35
        return $this->client->post(self::$endpoint . '/login', $requestOptions);
36
    }
37
38
    /**
39
     * @return ResponseInterface
40
     */
41
    public function logoutOfUserAccount()
42
    {
43
        return $this->client->post(self::$endpoint . '/logout');
44
    }
45
46
    /**
47
     * @return ResponseInterface
48
     */
49
    public function getAuthenticatedUser()
50
    {
51
        return $this->client->get(self::$endpoint . '/me');
52
    }
53
54
    /**
55
     * @param array $requestOptions
56
     * @return ResponseInterface
57
     */
58
    public function createUser(array $requestOptions)
59
    {
60
        return $this->client->post(self::$endpoint, $requestOptions);
61
    }
62
63
    /**
64
     * @param array $requestOptions
65
     * @return ResponseInterface
66
     */
67
    public function getUsers(array $requestOptions)
68
    {
69
        return $this->client->get(self::$endpoint, $requestOptions);
70
    }
71
72
    /**
73
     * @param array $requestOptions
74
     * @return ResponseInterface
75
     */
76
    public function getUsersByIds(array $requestOptions)
77
    {
78
        return $this->client->post(self::$endpoint . '/ids', $requestOptions);
79
    }
80
81
    /**
82
     * @param array $requestOptions
83
     * @return ResponseInterface
84
     */
85
    public function searchUsers(array $requestOptions)
86
    {
87
        return $this->client->post(self::$endpoint . '/search', $requestOptions);
88
    }
89
90
    /**
91
     * @param array $requestOptions
92
     * @return ResponseInterface
93
     */
94
    public function autocompleteUsers(array $requestOptions)
95
    {
96
        return $this->client->get(self::$endpoint . '/autocomplete', $requestOptions);
97
    }
98
99
    /**
100
     * @param $userId
101
     * @return ResponseInterface
102
     */
103
    public function getUser($userId)
104
    {
105
        return $this->client->get(self::$endpoint . '/' . $userId);
106
    }
107
108
    /**
109
     * @param $userId
110
     * @param array $requestOptions
111
     * @return ResponseInterface
112
     */
113
    public function updateUser($userId, array $requestOptions)
114
    {
115
        return $this->client->put(self::$endpoint . '/' . $userId, $requestOptions);
116
    }
117
118
    /**
119
     * @param $userId
120
     * @return ResponseInterface
121
     */
122
    public function deactivateUserAccount($userId)
123
    {
124
        return $this->client->delete(self::$endpoint . '/' . $userId);
125
    }
126
127
    /**
128
     * @param $userId
129
     * @param array $requestOptions
130
     * @return ResponseInterface
131
     */
132
    public function patchUser($userId, array $requestOptions)
133
    {
134
        return $this->client->put(self::$endpoint . '/' . $userId . '/patch', $requestOptions);
135
    }
136
137
    /**
138
     * @param $userId
139
     * @param array $requestOptions
140
     * @return ResponseInterface
141
     */
142
    public function updateUserRoles($userId, array $requestOptions)
143
    {
144
        return $this->client->put(self::$endpoint . '/' . $userId . '/roles', $requestOptions);
145
    }
146
147
    /**
148
     * @param $userId
149
     * @param array $requestOptions
150
     * @return ResponseInterface
151
     */
152
    public function updateUserActive($userId, array $requestOptions)
153
    {
154
        return $this->client->put(self::$endpoint . '/' . $userId . '/active', $requestOptions);
155
    }
156
157
    /**
158
     * @param $userId
159
     * @return ResponseInterface
160
     */
161
    public function getUserProfileImage($userId)
162
    {
163
        return $this->client->get(self::$endpoint . '/' . $userId . '/image');
164
    }
165
166
    /**
167
     * @param $userId
168
     * @param array $requestOptions
169
     * @return ResponseInterface
170
     */
171
    public function setUserProfileImage($userId, array $requestOptions)
172
    {
173
        return $this->client->post(self::$endpoint . '/' . $userId . '/image', $requestOptions, RequestOptions::MULTIPART);
174
    }
175
176
    /**
177
     * @param $userId
178
     * @return ResponseInterface
179
     */
180
    public function deleteUserProfileImage($userId)
181
    {
182
        return $this->client->delete(self::$endpoint . '/' . $userId . '/image');
183
    }
184
185
    /**
186
     * @param $userId
187
     * @return ResponseInterface
188
     */
189
    public function returnUserDefaultProfileImage($userId)
190
    {
191
        return $this->client->get(self::$endpoint . '/' . $userId . '/image/default');
192
    }
193
194
    /**
195
     * @param $username
196
     * @return ResponseInterface
197
     */
198
    public function getUserByUsername($username)
199
    {
200
        return $this->client->get(self::$endpoint . '/username/' . $username);
201
    }
202
203
    /**
204
     * @param $requestOptions
205
     * @return ResponseInterface
206
     */
207
    public function getUsersByUsernames(array $requestOptions)
208
    {
209
        return $this->client->post(self::$endpoint . '/usernames/', $requestOptions);
210
    }
211
212
    /**
213
     * @param array $requestOptions
214
     * @return ResponseInterface
215
     */
216
    public function resetPassword(array $requestOptions)
217
    {
218
        return $this->client->post(self::$endpoint . '/password/reset', $requestOptions);
219
    }
220
221
    /**
222
     * @param       $userId
223
     * @param array $requestOptions
224
     * @return ResponseInterface
225
     */
226
    public function updateUserMfa($userId, array $requestOptions)
227
    {
228
        return $this->client->put(self::$endpoint . '/' . $userId . '/mfa', $requestOptions);
229
    }
230
231
    /**
232
     * @param       $userId
233
     * @param array $requestOptions
234
     * @return ResponseInterface
235
     */
236
    public function generateMfaSecret($userId, array $requestOptions)
237
    {
238
        return $this->client->post(self::$endpoint . '/' . $userId . '/mfa/generate', $requestOptions);
239
    }
240
241
    /**
242
     * @param array $requestOptions
243
     * @return ResponseInterface
244
     */
245
    public function checkMfa(array $requestOptions)
246
    {
247
        return $this->client->post(self::$endpoint . '/mfa', $requestOptions);
248
    }
249
250
    /**
251
     * @param       $userId
252
     * @param array $requestOptions
253
     * @return ResponseInterface
254
     */
255
    public function updateUserPassword($userId, array $requestOptions)
256
    {
257
        return $this->client->put(self::$endpoint . '/' . $userId . '/password', $requestOptions);
258
    }
259
260
    /**
261
     * @param array $requestOptions
262
     * @return ResponseInterface
263
     */
264
    public function sendPasswordResetEmail(array $requestOptions)
265
    {
266
        return $this->client->post(self::$endpoint . '/password/reset/send', $requestOptions);
267
    }
268
269
    /**
270
     * @param $email
271
     * @return ResponseInterface
272
     */
273
    public function getUserByEmail($email)
274
    {
275
        return $this->client->get(self::$endpoint . '/email/' . $email);
276
    }
277
278
    /**
279
     * @param $userId
280
     * @return ResponseInterface
281
     */
282
    public function getUserSessions($userId)
283
    {
284
        return $this->client->get(self::$endpoint . '/' . $userId . '/sessions');
285
    }
286
287
    /**
288
     * @param $userId
289
     * @param array $requestOptions
290
     * @return ResponseInterface
291
     */
292
    public function revokeUserSession($userId, array $requestOptions)
293
    {
294
        return $this->client->post(self::$endpoint . '/' . $userId . '/sessions/revoke', $requestOptions);
295
    }
296
297
    /**
298
     * @param $userId
299
     * @return ResponseInterface
300
     */
301
    public function revokeAllUserSessions($userId)
302
    {
303
        return $this->client->post(self::$endpoint . '/' . $userId . '/sessions/revoke/all');
304
    }
305
306
    /**
307
     * @param array $requestOptions
308
     * @return ResponseInterface
309
     */
310
    public function attachMobileDevice(array $requestOptions)
311
    {
312
        return $this->client->put(self::$endpoint . '/sessions/device', $requestOptions);
313
    }
314
315
    /**
316
     * @param $userId
317
     * @return ResponseInterface
318
     */
319
    public function getUserAudits($userId)
320
    {
321
        return $this->client->get(self::$endpoint . '/' . $userId . '/audits');
322
    }
323
324
    /**
325
     * @param array $requestOptions
326
     * @return ResponseInterface
327
     */
328
    public function verifyUserEmail(array $requestOptions)
329
    {
330
        return $this->client->post(self::$endpoint . '/email/verify', $requestOptions);
331
    }
332
333
    /**
334
     * @param array $requestOptions
335
     * @return ResponseInterface
336
     */
337
    public function sendVerificationEmail(array $requestOptions)
338
    {
339
        return $this->client->post(self::$endpoint . '/email/verify/send', $requestOptions);
340
    }
341
342
    /**
343
     * @param array $requestOptions
344
     * @return ResponseInterface
345
     */
346
    public function switchLoginMethod(array $requestOptions)
347
    {
348
        return $this->client->post(self::$endpoint . '/login/switch', $requestOptions);
349
    }
350
351
    /**
352
     * @param       $userId
353
     * @param array $requestOptions
354
     * @return ResponseInterface
355
     */
356
    public function createToken($userId, array $requestOptions)
357
    {
358
        return $this->client->post(self::$endpoint . '/' . $userId . '/tokens', $requestOptions);
359
    }
360
361
    /**
362
     * @param       $userId
363
     * @param array $requestOptions
364
     * @return ResponseInterface
365
     */
366
    public function getTokens($userId, array $requestOptions)
367
    {
368
        return $this->client->get(self::$endpoint . '/' . $userId . '/tokens', $requestOptions);
369
    }
370
371
    /**
372
     * @param $tokenId
373
     * @return ResponseInterface
374
     */
375
    public function getToken($tokenId)
376
    {
377
        return $this->client->get(self::$endpoint . '/tokens/' . $tokenId);
378
    }
379
380
    /**
381
     * @param array $requestOptions
382
     * @return ResponseInterface
383
     */
384
    public function revokeToken(array $requestOptions)
385
    {
386
        return $this->client->post(self::$endpoint . '/tokens/revoke', $requestOptions);
387
    }
388
389
    /**
390
     * @param array $requestOptions
391
     * @return ResponseInterface
392
     */
393
    public function disablePersonalAccessToken(array $requestOptions)
394
    {
395
        return $this->client->post(self::$endpoint . '/tokens/disable', $requestOptions);
396
    }
397
398
    /**
399
     * @param array $requestOptions
400
     * @return ResponseInterface
401
     */
402
    public function enablePersonalAccessToken(array $requestOptions)
403
    {
404
        return $this->client->post(self::$endpoint . '/tokens/enable', $requestOptions);
405
    }
406
407
    /**
408
     * @param array $requestOptions
409
     * @return ResponseInterface
410
     */
411
    public function searchTokens(array $requestOptions)
412
    {
413
        return $this->client->post(self::$endpoint . '/tokens/search', $requestOptions);
414
    }
415
    
416
    /**
417
     * @param $userId
418
     * @return ResponseInterface
419
     */
420
    public function getUserStatus($userId)
421
    {
422
        return $this->client->get(self::$endpoint . '/' . $userId . '/status');
423
    }
424
425
    /**
426
     * @param       $userId
427
     * @param array $requestOptions
428
     * @return ResponseInterface
429
     */
430
    public function updateUserStatus($userId, array $requestOptions)
431
    {
432
        return $this->client->put(self::$endpoint . '/' . $userId . '/status', $requestOptions);
433
    }
434
435
    /**
436
     * @param       $userId
437
     * @param array $requestOptions
438
     * @return ResponseInterface
439
     */
440
    public function updateUserAuthenticationMethod($userId, array $requestOptions)
441
    {
442
        return $this->client->put(self::$endpoint . '/' . $userId . '/auth', $requestOptions);
443
    }
444
445
    /**
446
     * @return ResponseInterface
447
     */
448
    public function getTotalCountOfUsersInTheSystem()
449
    {
450
        return $this->client->get(self::$endpoint . '/stats');
451
    }
452
}
453