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 Psr\Http\Message\ResponseInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class CommandModel |
18
|
|
|
* |
19
|
|
|
* @package Gnello\MattermostRestApi\Models |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
class CommandModel extends AbstractModel |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private static $endpoint = '/commands'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param array $requestOptions |
30
|
|
|
* @return ResponseInterface |
31
|
|
|
*/ |
32
|
|
|
public function createCommand(array $requestOptions) |
33
|
|
|
{ |
34
|
|
|
return $this->client->post(self::$endpoint, $requestOptions); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param array $requestOptions |
39
|
|
|
* @return ResponseInterface |
40
|
|
|
*/ |
41
|
|
|
public function listCommandsForTeam(array $requestOptions) |
42
|
|
|
{ |
43
|
|
|
return $this->client->get(self::$endpoint, $requestOptions); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param $teamId |
48
|
|
|
* @return ResponseInterface |
49
|
|
|
*/ |
50
|
|
|
public function listAutocompleteCommands($teamId) |
51
|
|
|
{ |
52
|
|
|
return $this->client->get(TeamModel::$endpoint . '/' . $teamId . '/commands/autocomplete'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param $commandId |
57
|
|
|
* @param array $requestOptions |
58
|
|
|
* @return ResponseInterface |
59
|
|
|
*/ |
60
|
|
|
public function updateCommand($commandId, array $requestOptions) |
61
|
|
|
{ |
62
|
|
|
return $this->client->put(self::$endpoint . '/' . $commandId, $requestOptions); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param $commandId |
67
|
|
|
* @return ResponseInterface |
68
|
|
|
*/ |
69
|
|
|
public function deleteCommand($commandId) |
70
|
|
|
{ |
71
|
|
|
return $this->client->delete(self::$endpoint . '/' . $commandId); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param $commandId |
76
|
|
|
* @return ResponseInterface |
77
|
|
|
*/ |
78
|
|
|
public function generateNewToken($commandId) |
79
|
|
|
{ |
80
|
|
|
return $this->client->put(self::$endpoint . '/' . $commandId . '/regen_token'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param array $requestOptions |
85
|
|
|
* @return ResponseInterface |
86
|
|
|
*/ |
87
|
|
|
public function executeCommand(array $requestOptions) |
88
|
|
|
{ |
89
|
|
|
return $this->client->post(self::$endpoint . '/execute', $requestOptions); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param $commandId |
94
|
|
|
* @param array $requestOptions |
95
|
|
|
* @return ResponseInterface |
96
|
|
|
*/ |
97
|
|
|
public function moveCommand($commandId, array $requestOptions) |
98
|
|
|
{ |
99
|
|
|
return $this->client->put(self::$endpoint . '/' . $commandId . '/move', $requestOptions); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param $commandId |
104
|
|
|
* @return ResponseInterface |
105
|
|
|
*/ |
106
|
|
|
public function getCommand($commandId) |
107
|
|
|
{ |
108
|
|
|
return $this->client->get(self::$endpoint . '/' . $commandId); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.