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 Gnello\Mattermost\Client; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class JobModel |
18
|
|
|
* |
19
|
|
|
* @package Gnello\Mattermost\Models |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
class JobModel extends AbstractModel |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private static $endpoint = '/jobs'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param array $requestOptions |
30
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
31
|
|
|
*/ |
32
|
|
|
public function getJobs(array $requestOptions = []) |
33
|
|
|
{ |
34
|
|
|
return $this->client->get(self::$endpoint, $requestOptions, Client::TYPE_QUERY); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param array $requestOptions |
39
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
40
|
|
|
*/ |
41
|
|
|
public function createJob(array $requestOptions) |
42
|
|
|
{ |
43
|
|
|
return $this->client->post(self::$endpoint, $requestOptions); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param $jobId |
48
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
49
|
|
|
*/ |
50
|
|
|
public function getJob($jobId) |
51
|
|
|
{ |
52
|
|
|
return $this->client->get(self::$endpoint . '/' . $jobId); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param $jobId |
57
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
58
|
|
|
*/ |
59
|
|
|
public function deleteJob($jobId) |
60
|
|
|
{ |
61
|
|
|
return $this->client->post(self::$endpoint . '/' . $jobId . '/cancel'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param $type |
66
|
|
|
* @param array $requestOptions |
67
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
68
|
|
|
*/ |
69
|
|
|
public function getJobsOfType($type, array $requestOptions = []) |
70
|
|
|
{ |
71
|
|
|
return $this->client->get(self::$endpoint . '/type/' . $type, $requestOptions); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
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.