1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Lookyman\Rundeck\Api\Endpoints\Job; |
5
|
|
|
|
6
|
|
|
use GuzzleHttp\Promise\PromiseInterface; |
7
|
|
|
use GuzzleHttp\Psr7\Request; |
8
|
|
|
use Lookyman\Rundeck\Api\Client; |
9
|
|
|
|
10
|
|
|
class Job |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Client |
14
|
|
|
*/ |
15
|
|
|
private $client; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param Client $client |
19
|
|
|
*/ |
20
|
|
|
public function __construct(Client $client) |
21
|
|
|
{ |
22
|
|
|
$this->client = $client; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $id |
27
|
|
|
* @param array $params |
28
|
|
|
* @return PromiseInterface |
29
|
|
|
*/ |
30
|
|
|
public function run(string $id, array $params = []): PromiseInterface |
31
|
|
|
{ |
32
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
33
|
|
|
new Request('POST', $this->client->getConfiguration()->getBaseUri() . sprintf('/job/%s/run', urlencode($id)), [], $this->client->getConfiguration()->getFormat()->formatParams($params)) |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $id |
39
|
|
|
* @param array $params |
40
|
|
|
* @return PromiseInterface |
41
|
|
|
*/ |
42
|
|
|
public function get(string $id, array $params = []): PromiseInterface |
43
|
|
|
{ |
44
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
45
|
|
|
new Request('GET', $this->client->getConfiguration()->getBaseUri() . sprintf('/job/%s', urlencode($id)), [], $this->client->getConfiguration()->getFormat()->formatParams($params)) |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $id |
51
|
|
|
* @return PromiseInterface |
52
|
|
|
*/ |
53
|
|
|
public function delete(string $id): PromiseInterface |
54
|
|
|
{ |
55
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
56
|
|
|
new Request('DELETE', $this->client->getConfiguration()->getBaseUri() . sprintf('/job/%s', urlencode($id))) |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string[] $ids |
62
|
|
|
* @return PromiseInterface |
63
|
|
|
*/ |
64
|
|
|
public function bulkDelete(array $ids): PromiseInterface |
65
|
|
|
{ |
66
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
67
|
|
|
new Request('DELETE', $this->client->getConfiguration()->getBaseUri() . '/jobs/delete', [], $this->client->getConfiguration()->getFormat()->formatParams(['ids' => $ids])) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|