Completed
Push — master ( dbb949...f619f7 )
by Luca
02:03
created

ChannelModel::getChannelsList()   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
 * 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 Psr\Http\Message\ResponseInterface;
19
20
/**
21
 * Class ChannelModel
22
 *
23
 * @package Gnello\Mattermost\Models
24
 */
25
class ChannelModel extends AbstractModel
26
{
27
    /**
28
     * @var string
29
     */
30
    public static $endpoint = '/channels';
31
32
    /**
33
     * @param array $requestOptions
34
     * @return ResponseInterface
35
     */
36
    public function createChannel(array $requestOptions)
37
    {
38
        return $this->client->post(self::$endpoint, $requestOptions);
39
    }
40
41
    /**
42
     * @param array $requestOptions
43
     * @return ResponseInterface
44
     */
45
    public function createDirectMessageChannel(array $requestOptions)
46
    {
47
        return $this->client->post(self::$endpoint . '/direct', $requestOptions);
48
    }
49
50
    /**
51
     * @param array $requestOptions
52
     * @return ResponseInterface
53
     */
54
    public function createGroupMessageChannel(array $requestOptions)
55
    {
56
        return $this->client->post(self::$endpoint . '/group', $requestOptions);
57
    }
58
59
    /**
60
     * @param       $teamId
61
     * @param array $requestOptions
62
     * @return ResponseInterface
63
     */
64
    public function getChannelsListByIds($teamId, array $requestOptions)
65
    {
66
        return $this->client->post(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/ids', $requestOptions);
67
    }
68
69
    /**
70
     * @param array $requestOptions
71
     * @return ResponseInterface
72
     */
73
    public function getChannelsList(array $requestOptions = [])
74
    {
75
        return $this->client->get(self::$endpoint, $requestOptions);
76
    }
77
78
    /**
79
     * @param $channelId
80
     * @return ResponseInterface
81
     */
82
    public function getChannel($channelId)
83
    {
84
        return $this->client->get(self::$endpoint . '/' . $channelId);
85
    }
86
87
    /**
88
     * @param $channelId
89
     * @return ResponseInterface
90
     */
91
    public function getTimezone($channelId)
92
    {
93
        return $this->client->get(self::$endpoint . '/' . $channelId . '/timezones');
94
    }
95
96
    /**
97
     * @param       $channelId
98
     * @param array $requestOptions
99
     * @return ResponseInterface
100
     */
101
    public function updateChannel($channelId, array $requestOptions)
102
    {
103
        return $this->client->put(self::$endpoint . '/' . $channelId, $requestOptions);
104
    }
105
106
    /**
107
     * @param $channelId
108
     * @return ResponseInterface
109
     */
110
    public function deleteChannel($channelId)
111
    {
112
        return $this->client->delete(self::$endpoint . '/' . $channelId);
113
    }
114
115
    /**
116
     * @param       $channelId
117
     * @param array $requestOptions
118
     * @return ResponseInterface
119
     */
120
    public function patchChannel($channelId, array $requestOptions)
121
    {
122
        return $this->client->put(self::$endpoint . '/' . $channelId . '/patch', $requestOptions);
123
    }
124
125
    /**
126
     * @param       $channelId
127
     * @return ResponseInterface
128
     */
129
    public function restoreChannel($channelId)
130
    {
131
        return $this->client->post(self::$endpoint . '/' . $channelId . '/restore');
132
    }
133
134
    /**
135
     * @param $channelId
136
     * @return ResponseInterface
137
     */
138
    public function getChannelStatistics($channelId)
139
    {
140
        return $this->client->get(self::$endpoint . '/' . $channelId . '/stats');
141
    }
142
143
    /**
144
     * @param $channelId
145
     * @return ResponseInterface
146
     */
147
    public function getChannelsPinnedPosts($channelId)
148
    {
149
        return $this->client->get(self::$endpoint . '/' . $channelId . '/pinned');
150
    }
151
152
    /**
153
     * @param $teamId
154
     * @param $channelName
155
     * @return ResponseInterface
156
     */
157
    public function getChannelByName($teamId, $channelName)
158
    {
159
        return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/name/' . $channelName);
160
    }
161
162
    /**
163
     * @param $teamName
164
     * @param $channelName
165
     * @return ResponseInterface
166
     */
167
    public function getChannelByNameAndTeamName($teamName, $channelName)
168
    {
169
        return $this->client->get(TeamModel::$endpoint . '/name/' . $teamName . self::$endpoint . '/name/' . $channelName);
170
    }
171
172
    /**
173
     * @param $channelId
174
     * @param array $requestOptions
175
     * @return ResponseInterface
176
     */
177
    public function getChannelMembers($channelId, array $requestOptions)
178
    {
179
        return $this->client->get(self::$endpoint . '/' . $channelId . '/members', $requestOptions);
180
    }
181
182
    /**
183
     * @param       $channelId
184
     * @param array $requestOptions
185
     * @return ResponseInterface
186
     */
187
    public function addUser($channelId, array $requestOptions)
188
    {
189
        return $this->client->post(self::$endpoint . '/' . $channelId . '/members', $requestOptions);
190
    }
191
192
    /**
193
     * @param       $channelId
194
     * @param array $requestOptions
195
     * @return ResponseInterface
196
     */
197
    public function getChannelMembersByIds($channelId, array $requestOptions)
198
    {
199
        return $this->client->post(self::$endpoint . '/' . $channelId . '/members/ids', $requestOptions);
200
    }
201
202
    /**
203
     * @param $channelId
204
     * @param $userId
205
     * @return ResponseInterface
206
     */
207
    public function getChannelMember($channelId, $userId)
208
    {
209
        return $this->client->get(self::$endpoint . '/' . $channelId . '/members/' . $userId);
210
    }
211
212
    /**
213
     * @param $channelId
214
     * @param $userId
215
     * @return ResponseInterface
216
     */
217
    public function removeUserFromChannel($channelId, $userId)
218
    {
219
        return $this->client->delete(self::$endpoint . '/' . $channelId . '/members/' . $userId);
220
    }
221
222
    /**
223
     * @param       $channelId
224
     * @param       $userId
225
     * @param array $requestOptions
226
     * @return ResponseInterface
227
     */
228
    public function updateChannelRoles($channelId, $userId, array $requestOptions)
229
    {
230
        return $this->client->put(self::$endpoint . '/' . $channelId . '/members/' . $userId . '/roles', $requestOptions);
231
    }
232
233
    /**
234
     * @param       $channelId
235
     * @param       $userId
236
     * @param array $requestOptions
237
     * @return ResponseInterface
238
     */
239
    public function updateChannelNotifications($channelId, $userId, array $requestOptions)
240
    {
241
        return $this->client->put(self::$endpoint . '/' . $channelId . '/members/' . $userId . '/notify_props', $requestOptions);
242
    }
243
244
    /**
245
     * @param       $userId
246
     * @param array $requestOptions
247
     * @return ResponseInterface
248
     */
249
    public function viewChannel($userId, array $requestOptions)
250
    {
251
        return $this->client->post(self::$endpoint . '/members/' . $userId . '/view', $requestOptions);
252
    }
253
254
    /**
255
     * @param $userId
256
     * @param $teamId
257
     * @return ResponseInterface
258
     */
259
    public function getChannelMembersForTheUser($userId, $teamId)
260
    {
261
        return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/members');
262
    }
263
264
    /**
265
     * @param $userId
266
     * @param $teamId
267
     * @return ResponseInterface
268
     */
269
    public function getChannelsForUser($userId, $teamId)
270
    {
271
        return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId . self::$endpoint);
272
    }
273
274
    /**
275
     * @param $userId
276
     * @param $channelId
277
     * @return ResponseInterface
278
     */
279
    public function getUnreadMessages($userId, $channelId)
280
    {
281
        return $this->client->get(UserModel::$endpoint . '/' . $userId . self::$endpoint . '/' . $channelId . '/unread');
282
    }
283
284
    /**
285
     * @param $channelId
286
     * @return ResponseInterface
287
     */
288
    public function convertChannelFromPublicToPrivate($channelId)
289
    {
290
        return $this->client->post(self::$endpoint . '/' . $channelId . '/convert');
291
    }
292
293
    /**
294
     * @param       $teamId
295
     * @param array $requestOptions
296
     * @return ResponseInterface
297
     */
298
    public function getPublicChannels($teamId, array $requestOptions)
299
    {
300
        return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint, $requestOptions);
301
    }
302
303
    /**
304
     * @param       $teamId
305
     * @param array $requestOptions
306
     * @return ResponseInterface
307
     */
308
    public function getDeletedChannels($teamId, array $requestOptions)
309
    {
310
        return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/deleted', $requestOptions);
311
    }
312
313
    /**
314
     * @param       $teamId
315
     * @param array $requestOptions
316
     * @return ResponseInterface
317
     */
318
    public function autocompleteChannels($teamId, array $requestOptions)
319
    {
320
        return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/autocomplete', $requestOptions);
321
    }
322
323
    /**
324
     * @param       $teamId
325
     * @param array $requestOptions
326
     * @return ResponseInterface
327
     */
328
    public function autocompleteChannelsForSearch($teamId, array $requestOptions)
329
    {
330
        return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/search_autocomplete', $requestOptions);
331
    }
332
333
    /**
334
     * @param       $teamId
335
     * @param array $requestOptions
336
     * @return ResponseInterface
337
     */
338
    public function searchChannels($teamId, array $requestOptions)
339
    {
340
        return $this->client->post(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/search', $requestOptions);
341
    }
342
343
    /**
344
     * @param       $teamId
345
     * @param array $requestOptions
346
     * @return ResponseInterface
347
     */
348
    public function searchArchivedChannels($teamId, array $requestOptions)
349
    {
350
        return $this->client->post(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/search_archived', $requestOptions);
351
    }
352
353
    /**
354
     * @param array $requestOptions
355
     * @return ResponseInterface
356
     */
357
    public function searchAllPrivateAndOpenTypeChannels(array $requestOptions)
358
    {
359
        return $this->client->post(self::$endpoint . '/search', $requestOptions);
360
    }
361
362
    /**
363
     * @param array $requestOptions
364
     * @return ResponseInterface
365
     */
366
    public function searchGroupChannels(array $requestOptions)
367
    {
368
        return $this->client->post('/group/search', $requestOptions);
369
    }
370
371
    /**
372
     * @param       $channelId
373
     * @param array $requestOptions
374
     * @return ResponseInterface
375
     */
376
    public function getMembersMinusGroupMembers($channelId, array $requestOptions)
377
    {
378
        return $this->client->get(self::$endpoint . $channelId . '/members_minus_group_members', $requestOptions);
379
    }
380
381
    /**
382
     * @param       $channelId
383
     * @param array $requestOptions
384
     * @return ResponseInterface
385
     */
386
    public function updateChannelPrivacy($channelId, array $requestOptions)
387
    {
388
        return $this->client->put(self::$endpoint . '/' . $channelId . '/privacy', $requestOptions);
389
    }
390
}
391