Completed
Push — master ( 190bc1...59dcab )
by Luca
01:23
created

TeamModel::updateSchemeDerivedRolesOfMember()   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 3
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
 * For the full copyright and license information, please read the LICENSE.txt
7
 * file that was distributed with this source code. For the full list of
8
 * contributors, visit https://github.com/gnello/php-mattermost-driver/contributors
9
 *
10
 * God bless this mess.
11
 *
12
 * @author Luca Agnello <[email protected]>
13
 * @link https://api.mattermost.com/
14
 */
15
16
namespace Gnello\Mattermost\Models;
17
18
use GuzzleHttp\RequestOptions;
19
use Psr\Http\Message\ResponseInterface;
20
21
/**
22
 * Class TeamModel
23
 *
24
 * @package Gnello\Mattermost
25
 */
26
class TeamModel extends AbstractModel
27
{
28
    /**
29
     * @var string
30
     */
31
    public static $endpoint = '/teams';
32
33
    /**
34
     * @param array $requestOptions
35
     * @return ResponseInterface
36
     */
37
    public function createTeam(array $requestOptions)
38
    {
39
        return $this->client->post(self::$endpoint, $requestOptions);
40
    }
41
42
    /**
43
     * @param array $requestOptions
44
     * @return ResponseInterface
45
     */
46
    public function getTeams(array $requestOptions)
47
    {
48
        return $this->client->get(self::$endpoint, $requestOptions);
49
    }
50
51
    /**
52
     * @param $teamId
53
     * @return ResponseInterface
54
     */
55
    public function getTeam($teamId)
56
    {
57
        return $this->client->get(self::$endpoint . '/' . $teamId);
58
    }
59
60
    /**
61
     * @param $teamId
62
     * @param array $requestOptions
63
     * @return ResponseInterface
64
     */
65
    public function updateTeam($teamId, array $requestOptions)
66
    {
67
        return $this->client->put(self::$endpoint . '/' . $teamId, $requestOptions);
68
    }
69
70
    /**
71
     * @param $teamId
72
     * @return ResponseInterface
73
     */
74
    public function deleteTeam($teamId)
75
    {
76
        return $this->client->delete(self::$endpoint . '/' . $teamId);
77
    }
78
79
    /**
80
     * @param $teamId
81
     * @param array $requestOptions
82
     * @return ResponseInterface
83
     */
84
    public function patchTeam($teamId, array $requestOptions)
85
    {
86
        return $this->client->put(self::$endpoint . '/' . $teamId . '/patch', $requestOptions);
87
    }
88
89
    /**
90
     * @param $teamName
91
     * @return ResponseInterface
92
     */
93
    public function getTeamByName($teamName)
94
    {
95
        return $this->client->get(self::$endpoint . '/name/' . $teamName);
96
    }
97
98
    /**
99
     * @param array $requestOptions
100
     * @return ResponseInterface
101
     */
102
    public function searchTeams(array $requestOptions)
103
    {
104
        return $this->client->post(self::$endpoint . '/search', $requestOptions);
105
    }
106
107
    /**
108
     * @param $teamName
109
     * @return ResponseInterface
110
     */
111
    public function checkTeamExists($teamName)
112
    {
113
        return $this->client->get(self::$endpoint . '/name/' . $teamName . '/exists');
114
    }
115
116
    /**
117
     * @param $userId
118
     * @return ResponseInterface
119
     */
120
    public function getUserTeams($userId)
121
    {
122
        return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams');
123
    }
124
125
    /**
126
     * @param $teamId
127
     * @param array $requestOptions
128
     * @return ResponseInterface
129
     */
130
    public function getTeamMembers($teamId, array $requestOptions)
131
    {
132
        return $this->client->get(self::$endpoint . '/' . $teamId . '/members', $requestOptions);
133
    }
134
135
    /**
136
     * @param $teamId
137
     * @param array $requestOptions
138
     * @return ResponseInterface
139
     */
140
    public function addUser($teamId, array $requestOptions)
141
    {
142
        return $this->client->post(self::$endpoint . '/' . $teamId . '/members', $requestOptions);
143
    }
144
145
    /**
146
     * @param array $requestOptions
147
     * @return ResponseInterface
148
     */
149
    public function addUserFromInvite(array $requestOptions)
150
    {
151
        return $this->client->get(self::$endpoint . '/members/invite', $requestOptions);
152
    }
153
154
    /**
155
     * @param $teamId
156
     * @param array $requestOptions
157
     * @return ResponseInterface
158
     */
159
    public function addMultipleUsers($teamId, array $requestOptions)
160
    {
161
        return $this->client->post(self::$endpoint . '/' . $teamId . '/members/batch', $requestOptions);
162
    }
163
164
    /**
165
     * @param $userId
166
     * @param array $requestOptions
167
     * @return ResponseInterface
168
     */
169
    public function getTeamMembersForUser($userId, array $requestOptions)
170
    {
171
        return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams/members', $requestOptions);
172
    }
173
174
    /**
175
     * @param $teamId
176
     * @param $userId
177
     * @return ResponseInterface
178
     */
179
    public function getTeamMember($teamId, $userId)
180
    {
181
        return $this->client->get(self::$endpoint . '/' . $teamId . '/members/' . $userId);
182
    }
183
184
    /**
185
     * @param       $teamId
186
     * @param       $userId
187
     * @param array $requestOptions
188
     * @return ResponseInterface
189
     */
190
    public function removeUser($teamId, $userId, array $requestOptions)
191
    {
192
        return $this->client->delete(self::$endpoint . '/' . $teamId . '/members/' . $userId, $requestOptions);
193
    }
194
195
    /**
196
     * @param       $teamId
197
     * @param array $requestOptions
198
     * @return ResponseInterface
199
     */
200
    public function getTeamMembersByIds($teamId, array $requestOptions)
201
    {
202
        return $this->client->post(self::$endpoint . '/' . $teamId . '/members/ids', $requestOptions);
203
    }
204
205
    /**
206
     * @param $teamId
207
     * @return ResponseInterface
208
     */
209
    public function getTeamStats($teamId)
210
    {
211
        return $this->client->get(self::$endpoint . '/' . $teamId . '/stats');
212
    }
213
214
    /**
215
     * @param       $teamId
216
     * @return ResponseInterface
217
     */
218
    public function regenerateInviteID($teamId)
219
    {
220
        return $this->client->post(self::$endpoint . '/' . $teamId . '/regenerate_invite_id');
221
    }
222
223
    /**
224
     * @param $teamId
225
     * @return ResponseInterface
226
     */
227
    public function getTeamIcon($teamId)
228
    {
229
        return $this->client->get(self::$endpoint . '/' . $teamId . '/image');
230
    }
231
232
    /**
233
     * @param       $teamId
234
     * @param array $requestOptions
235
     * @return ResponseInterface
236
     */
237
    public function setTeamIcon($teamId, array $requestOptions)
238
    {
239
        $internalRequestOptions = self::buildMultipartDataOptions($requestOptions, ['image']);
240
241
        return $this->client->post(self::$endpoint . '/' . $teamId . '/image', $internalRequestOptions, RequestOptions::MULTIPART);
242
    }
243
244
    /**
245
     * @param $teamId
246
     * @return ResponseInterface
247
     */
248
    public function removeTeamIcon($teamId)
249
    {
250
        return $this->client->delete(self::$endpoint . '/' . $teamId . '/image');
251
    }
252
253
    /**
254
     * @param $teamId
255
     * @param $userId
256
     * @param array $requestOptions
257
     * @return ResponseInterface
258
     */
259
    public function updateTeamMemberRoles($teamId, $userId, array $requestOptions)
260
    {
261
        return $this->client->put(self::$endpoint . '/' . $teamId . '/members/' . $userId . '/roles', $requestOptions);
262
    }
263
264
    /**
265
     * @param $teamId
266
     * @param $userId
267
     * @param array $requestOptions
268
     * @return ResponseInterface
269
     */
270
    public function updateSchemeDerivedRolesOfMember($teamId, $userId, array $requestOptions)
271
    {
272
        return $this->client->put(self::$endpoint . '/' . $teamId . '/members/' . $userId . '/schemeRoles', $requestOptions);
273
    }
274
275
    /**
276
     * @param $userId
277
     * @return ResponseInterface
278
     */
279
    public function getUserTotalUnreadMessagesFromTeams($userId)
280
    {
281
        return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams/unread');
282
    }
283
284
    /**
285
     * @param $userId
286
     * @param $teamId
287
     * @return ResponseInterface
288
     */
289
    public function getUserTotalUnreadMessagesFromTeam($userId, $teamId)
290
    {
291
        return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams/' . $teamId . '/unread');
292
    }
293
294
    /**
295
     * @param       $teamId
296
     * @param array $requestOptions
297
     * @return ResponseInterface
298
     */
299
    public function inviteUsersByEmail($teamId, array $requestOptions)
300
    {
301
        return $this->client->post(self::$endpoint . '/' . $teamId . '/invite/email', $requestOptions);
302
    }
303
304
    /**
305
     * @param       $teamId
306
     * @param array $requestOptions
307
     * @return ResponseInterface
308
     */
309
    public function inviteGuestsByEmail($teamId, array $requestOptions)
310
    {
311
        return $this->client->post(self::$endpoint . '/' . $teamId . '/invite-guests/email', $requestOptions);
312
    }
313
314
    /**
315
     * @return ResponseInterface
316
     */
317
    public function invalidateActiveEmailInvitations()
318
    {
319
        return $this->client->delete(self::$endpoint . '/invites/email');
320
    }
321
322
    /**
323
     * @param       $teamId
324
     * @param array $requestOptions
325
     * @return ResponseInterface
326
     */
327
    public function importTeamFromOtherApplication($teamId, array $requestOptions)
328
    {
329
        $internalRequestOptions = self::buildMultipartDataOptions($requestOptions, ['file', 'filesize', 'importFrom']);
330
331
        return $this->client->post(self::$endpoint . '/' . $teamId . '/import', $internalRequestOptions, RequestOptions::MULTIPART);
332
    }
333
334
    /**
335
     * @param $teamId
336
     * @return ResponseInterface
337
     */
338
    public function getInviteInfoForTeam($teamId)
339
    {
340
        return $this->client->get(self::$endpoint . '/invite/' . $teamId);
341
    }
342
343
    /**
344
     * @param       $teamId
345
     * @param array $requestOptions
346
     * @return ResponseInterface
347
     */
348
    public function setTeamScheme($teamId, array $requestOptions)
349
    {
350
        return $this->client->put(self::$endpoint . '/' . $teamId . '/scheme', $requestOptions);
351
    }
352
353
    /**
354
     * @param       $teamId
355
     * @param array $requestOptions
356
     * @return ResponseInterface
357
     */
358
    public function getTeamMembersMinusGroupMembers($teamId, array $requestOptions)
359
    {
360
        return $this->client->get(self::$endpoint . '/' . $teamId . '/members_minus_group_members', $requestOptions);
361
    }
362
363
    /**
364
     * @param $teamId
365
     * @param array $requestOptions
366
     * @return ResponseInterface
367
     */
368
    public function getPublicChannels($teamId, array $requestOptions)
369
    {
370
        return $this->client->get(self::$endpoint . '/' . $teamId . '/channels', $requestOptions);
371
    }
372
373
    /**
374
     * @param $teamId
375
     * @param array $requestOptions
376
     * @return ResponseInterface
377
     */
378
    public function getDeletedChannels($teamId, array $requestOptions)
379
    {
380
        return $this->client->get(self::$endpoint . '/' . $teamId . '/channels/deleted', $requestOptions);
381
    }
382
383
    /**
384
     * @param       $teamId
385
     * @param array $requestOptions
386
     * @return ResponseInterface
387
     */
388
    public function searchChannels($teamId, array $requestOptions)
389
    {
390
        return $this->client->post(self::$endpoint . '/' . $teamId . '/channels/search', $requestOptions);
391
    }
392
}
393