1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the KongAdminApi package. |
5
|
|
|
* |
6
|
|
|
* (c) Unikorp <https://github.com/unikorp> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Unikorp\KongAdminApi\Node; |
13
|
|
|
|
14
|
|
|
use Psr\Http\Message\ResponseInterface; |
15
|
|
|
use Unikorp\KongAdminApi\AbstractNode; |
16
|
|
|
use Unikorp\KongAdminApi\Document\TargetDocument as Document; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* target node |
20
|
|
|
* |
21
|
|
|
* @author VEBER Arnaud <https://github.com/VEBERArnaud> |
22
|
|
|
*/ |
23
|
|
|
class TargetNode extends AbstractNode |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* add target |
27
|
|
|
* |
28
|
|
|
* @param string $nameOrId |
29
|
|
|
* @param \Unikorp\KongAdminApi\Document\TargetDocument $document |
30
|
|
|
* |
31
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
32
|
|
|
*/ |
33
|
2 |
|
public function addTarget(string $nameOrId, Document $document): ResponseInterface |
34
|
|
|
{ |
35
|
2 |
|
return $this->post(sprintf('/upstreams/%1$s/targets', $nameOrId), $document); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* list targets |
40
|
|
|
* |
41
|
|
|
* @param string $nameOrId |
42
|
|
|
* @param \Unikorp\KongAdminApi\Document\TargetDocument $document |
43
|
|
|
* |
44
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
45
|
|
|
*/ |
46
|
1 |
|
public function listTargets(string $nameOrId, Document $document = null): ResponseInterface |
47
|
|
|
{ |
48
|
1 |
|
return $this->get(sprintf('/upstreams/%1$s/targets', $nameOrId), $document); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* list active targets |
53
|
|
|
* |
54
|
|
|
* @param string $nameOrId |
55
|
|
|
* |
56
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
57
|
|
|
*/ |
58
|
2 |
|
public function listActiveTargets(string $nameOrId): ResponseInterface |
59
|
|
|
{ |
60
|
2 |
|
return $this->get(sprintf('/upstreams/%1$s/targets/active', $nameOrId)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* delete target |
65
|
|
|
* |
66
|
|
|
* @param string $nameOrId |
67
|
|
|
* @param string $target |
68
|
|
|
* |
69
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
70
|
|
|
*/ |
71
|
1 |
|
public function deleteTarget(string $nameOrId, string $target): ResponseInterface |
72
|
|
|
{ |
73
|
1 |
|
return $this->delete(sprintf('/upstreams/%1$s/targets/%2$s', $nameOrId, $target)); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|