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
|
|
|
/**
|
19
|
|
|
* Class TeamModel
|
20
|
|
|
*
|
21
|
|
|
* @package Gnello\Mattermost
|
22
|
|
|
*/
|
23
|
|
|
class TeamModel extends AbstractModel
|
24
|
|
|
{
|
25
|
|
|
/**
|
26
|
|
|
* @var string
|
27
|
|
|
*/
|
28
|
|
|
public static $endpoint = '/teams';
|
29
|
|
|
|
30
|
|
|
/**
|
31
|
|
|
* @param array $requestOptions
|
32
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
33
|
|
|
*/
|
34
|
|
|
public function createTeam(array $requestOptions)
|
35
|
|
|
{
|
36
|
|
|
return $this->client->post(self::$endpoint, $requestOptions);
|
37
|
|
|
}
|
38
|
|
|
|
39
|
|
|
/**
|
40
|
|
|
* @param array $requestOptions
|
41
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
42
|
|
|
*/
|
43
|
|
|
public function getTeams(array $requestOptions)
|
44
|
|
|
{
|
45
|
|
|
return $this->client->get(self::$endpoint, $requestOptions);
|
46
|
|
|
}
|
47
|
|
|
|
48
|
|
|
/**
|
49
|
|
|
* @param $teamId
|
50
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
51
|
|
|
*/
|
52
|
|
|
public function getTeam($teamId)
|
53
|
|
|
{
|
54
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId);
|
55
|
|
|
}
|
56
|
|
|
|
57
|
|
|
/**
|
58
|
|
|
* @param $teamId
|
59
|
|
|
* @param array $requestOptions
|
60
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
61
|
|
|
*/
|
62
|
|
|
public function updateTeam($teamId, array $requestOptions)
|
63
|
|
|
{
|
64
|
|
|
return $this->client->put(self::$endpoint . '/' . $teamId, $requestOptions);
|
65
|
|
|
}
|
66
|
|
|
|
67
|
|
|
/**
|
68
|
|
|
* @param $teamId
|
69
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
70
|
|
|
*/
|
71
|
|
|
public function deleteTeam($teamId)
|
72
|
|
|
{
|
73
|
|
|
return $this->client->delete(self::$endpoint . '/' . $teamId);
|
74
|
|
|
}
|
75
|
|
|
|
76
|
|
|
/**
|
77
|
|
|
* @param $teamId
|
78
|
|
|
* @param array $requestOptions
|
79
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
80
|
|
|
*/
|
81
|
|
|
public function patchTeam($teamId, array $requestOptions)
|
82
|
|
|
{
|
83
|
|
|
return $this->client->put(self::$endpoint . '/' . $teamId . '/patch', $requestOptions);
|
84
|
|
|
}
|
85
|
|
|
|
86
|
|
|
/**
|
87
|
|
|
* @param $teamName
|
88
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
89
|
|
|
*/
|
90
|
|
|
public function getTeamByName($teamName)
|
91
|
|
|
{
|
92
|
|
|
return $this->client->get(self::$endpoint . '/name/' . $teamName);
|
93
|
|
|
}
|
94
|
|
|
|
95
|
|
|
/**
|
96
|
|
|
* @param array $requestOptions
|
97
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
98
|
|
|
*/
|
99
|
|
|
public function searchTeams(array $requestOptions)
|
100
|
|
|
{
|
101
|
|
|
return $this->client->post(self::$endpoint . '/search', $requestOptions);
|
102
|
|
|
}
|
103
|
|
|
|
104
|
|
|
/**
|
105
|
|
|
* @param $teamName
|
106
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
107
|
|
|
*/
|
108
|
|
|
public function checkTeamExists($teamName)
|
109
|
|
|
{
|
110
|
|
|
return $this->client->get(self::$endpoint . '/name/' . $teamName . '/exists');
|
111
|
|
|
}
|
112
|
|
|
|
113
|
|
|
/**
|
114
|
|
|
* @param $userId
|
115
|
|
|
* @return null|\Psr\Http\Message\ResponseInterface
|
116
|
|
|
*/
|
117
|
|
|
public function getUserTeams($userId)
|
118
|
|
|
{
|
119
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams');
|
120
|
|
|
}
|
121
|
|
|
|
122
|
|
|
/**
|
123
|
|
|
* @param $teamId
|
124
|
|
|
* @param array $requestOptions
|
125
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
126
|
|
|
*/
|
127
|
|
|
public function getTeamMembers($teamId, array $requestOptions)
|
128
|
|
|
{
|
129
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/members', $requestOptions);
|
130
|
|
|
}
|
131
|
|
|
|
132
|
|
|
/**
|
133
|
|
|
* @param $teamId
|
134
|
|
|
* @param array $requestOptions
|
135
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
136
|
|
|
*/
|
137
|
|
|
public function addUser($teamId, array $requestOptions)
|
138
|
|
|
{
|
139
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/members', $requestOptions);
|
140
|
|
|
}
|
141
|
|
|
|
142
|
|
|
/**
|
143
|
|
|
* @param array $requestOptions
|
144
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
145
|
|
|
*/
|
146
|
|
|
public function addUserFromInvite(array $requestOptions)
|
147
|
|
|
{
|
148
|
|
|
return $this->client->post(self::$endpoint . '/members/invite', $requestOptions);
|
149
|
|
|
}
|
150
|
|
|
|
151
|
|
|
/**
|
152
|
|
|
* @param $teamId
|
153
|
|
|
* @param array $requestOptions
|
154
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
155
|
|
|
*/
|
156
|
|
|
public function addMultipleUsers($teamId, array $requestOptions)
|
157
|
|
|
{
|
158
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/members/batch', $requestOptions);
|
159
|
|
|
}
|
160
|
|
|
|
161
|
|
|
/**
|
162
|
|
|
* @param $userId
|
163
|
|
|
* @param array $requestOptions
|
164
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
165
|
|
|
*/
|
166
|
|
|
public function getTeamMembersForUser($userId, array $requestOptions)
|
167
|
|
|
{
|
168
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams/members', $requestOptions);
|
169
|
|
|
}
|
170
|
|
|
|
171
|
|
|
/**
|
172
|
|
|
* @param $teamId
|
173
|
|
|
* @param $userId
|
174
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
175
|
|
|
*/
|
176
|
|
|
public function getTeamMember($teamId, $userId)
|
177
|
|
|
{
|
178
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/members/' . $userId);
|
179
|
|
|
}
|
180
|
|
|
|
181
|
|
|
/**
|
182
|
|
|
* @param $teamId
|
183
|
|
|
* @param $userId
|
184
|
|
|
* @param array $requestOptions
|
185
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
186
|
|
|
*/
|
187
|
|
|
public function removeUser($teamId, $userId, array $requestOptions)
|
188
|
|
|
{
|
189
|
|
|
return $this->client->delete(self::$endpoint . '/' . $teamId . '/members/' . $userId, $requestOptions);
|
190
|
|
|
}
|
191
|
|
|
|
192
|
|
|
/**
|
193
|
|
|
* @param $teamId
|
194
|
|
|
* @param array $requestOptions
|
195
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
196
|
|
|
*/
|
197
|
|
|
public function getTeamMembersByIds($teamId, array $requestOptions)
|
198
|
|
|
{
|
199
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/members/ids', $requestOptions);
|
200
|
|
|
}
|
201
|
|
|
|
202
|
|
|
/**
|
203
|
|
|
* @param $teamId
|
204
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
205
|
|
|
*/
|
206
|
|
|
public function getTeamStats($teamId)
|
207
|
|
|
{
|
208
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/stats');
|
209
|
|
|
}
|
210
|
|
|
|
211
|
|
|
/**
|
212
|
|
|
* @param $teamId
|
213
|
|
|
* @param $userId
|
214
|
|
|
* @param array $requestOptions
|
215
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
216
|
|
|
*/
|
217
|
|
|
public function updateTeamMemberRoles($teamId, $userId, array $requestOptions)
|
218
|
|
|
{
|
219
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/members/' . $userId . '/roles', $requestOptions);
|
220
|
|
|
}
|
221
|
|
|
|
222
|
|
|
/**
|
223
|
|
|
* @param $userId
|
224
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
225
|
|
|
*/
|
226
|
|
|
public function getUserTotalUnreadMessagesFromTeams($userId)
|
227
|
|
|
{
|
228
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams/unread');
|
229
|
|
|
}
|
230
|
|
|
|
231
|
|
|
/**
|
232
|
|
|
* @param $userId
|
233
|
|
|
* @param $teamId
|
234
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
235
|
|
|
*/
|
236
|
|
|
public function getUserTotalUnreadMessagesFromTeam($userId, $teamId)
|
237
|
|
|
{
|
238
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/teams/' . $teamId . '/unread');
|
239
|
|
|
}
|
240
|
|
|
|
241
|
|
|
/**
|
242
|
|
|
* @param $teamId
|
243
|
|
|
* @param array $requestOptions
|
244
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
245
|
|
|
*/
|
246
|
|
|
public function inviteUsersByEmail($teamId, array $requestOptions)
|
247
|
|
|
{
|
248
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/invite/email', $requestOptions);
|
249
|
|
|
}
|
250
|
|
|
|
251
|
|
|
/**
|
252
|
|
|
* @param $teamId
|
253
|
|
|
* @param array $requestOptions
|
254
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
255
|
|
|
*/
|
256
|
|
|
public function importTeamFromOtherApplication($teamId, array $requestOptions)
|
257
|
|
|
{
|
258
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/import', $requestOptions, 'multipart');
|
259
|
|
|
}
|
260
|
|
|
|
261
|
|
|
/**
|
262
|
|
|
* @param $teamId
|
263
|
|
|
* @return null|\Psr\Http\Message\ResponseInterface
|
264
|
|
|
*/
|
265
|
|
|
public function getInviteInfoForTeam($teamId)
|
266
|
|
|
{
|
267
|
|
|
return $this->client->get(self::$endpoint . '/invite/' . $teamId);
|
268
|
|
|
}
|
269
|
|
|
|
270
|
|
|
/**
|
271
|
|
|
* @param $teamId
|
272
|
|
|
* @param array $requestOptions
|
273
|
|
|
* @return null|\Psr\Http\Message\ResponseInterface
|
274
|
|
|
*/
|
275
|
|
|
public function getPublicChannels($teamId, array $requestOptions)
|
276
|
|
|
{
|
277
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/channels', $requestOptions);
|
278
|
|
|
}
|
279
|
|
|
|
280
|
|
|
/**
|
281
|
|
|
* @param $teamId
|
282
|
|
|
* @param array $requestOptions
|
283
|
|
|
* @return null|\Psr\Http\Message\ResponseInterface
|
284
|
|
|
*/
|
285
|
|
|
public function getDeletedChannels($teamId, array $requestOptions)
|
286
|
|
|
{
|
287
|
|
|
return $this->client->get(self::$endpoint . '/' . $teamId . '/channels/deleted', $requestOptions);
|
288
|
|
|
}
|
289
|
|
|
|
290
|
|
|
/**
|
291
|
|
|
* @param $teamId
|
292
|
|
|
* @param array $requestOptions
|
293
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
294
|
|
|
*/
|
295
|
|
|
public function searchChannels($teamId, array $requestOptions)
|
296
|
|
|
{
|
297
|
|
|
return $this->client->post(self::$endpoint . '/' . $teamId . '/channels/search', $requestOptions);
|
298
|
|
|
}
|
299
|
|
|
}
|
300
|
|
|
|