Completed
Push — master ( d25167...dbe861 )
by Lukáš
09:30 queued 06:24
created

Job::schedule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
	/**
72
	 * @return Execution
73
	 */
74
	public function execution(): Execution
75
	{
76
		return new Execution($this->client);
77
	}
78
79
	/**
80
	 * @return Schedule
81
	 */
82
	public function schedule(): Schedule
83
	{
84
		return new Schedule($this->client);
85
	}
86
}
87