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\UpstreamDocument as Document; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* upstream node |
20
|
|
|
* |
21
|
|
|
* @author VEBER Arnaud <https://github.com/VEBERArnaud> |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
class UpstreamNode extends AbstractNode |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* add upstream |
27
|
|
|
* |
28
|
|
|
* @param \Unikorp\KongAdminApi\Document\UpstreamDocument $document |
29
|
|
|
* |
30
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
31
|
|
|
*/ |
32
|
2 |
|
public function addUpstream(Document $document): ResponseInterface |
33
|
|
|
{ |
34
|
2 |
|
return $this->post('/upstreams/', $document); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* retrieve upstream |
39
|
|
|
* |
40
|
|
|
* @param string $nameOrId |
41
|
|
|
* |
42
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
43
|
|
|
*/ |
44
|
2 |
|
public function retrieveUpstream(string $nameOrId): ResponseInterface |
45
|
|
|
{ |
46
|
2 |
|
return $this->get(sprintf('/upstreams/%1$s', $nameOrId)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* list upstreams |
51
|
|
|
* |
52
|
|
|
* @param \Unikorp\KongAdminApi\Document\UpstreamDocument $document |
53
|
|
|
* |
54
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
55
|
|
|
*/ |
56
|
2 |
|
public function listUpstreams(Document $document = null): ResponseInterface |
57
|
|
|
{ |
58
|
2 |
|
return $this->get('/upstreams/', $document); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* update upstream |
63
|
|
|
* |
64
|
|
|
* @param string $nameOrId |
65
|
|
|
* @param \Unikorp\KongAdminApi\Document\UpstreamDocument $document |
66
|
|
|
* |
67
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
68
|
|
|
*/ |
69
|
2 |
|
public function updateUpstream(string $nameOrId, Document $document): ResponseInterface |
70
|
|
|
{ |
71
|
2 |
|
return $this->patch(sprintf('/upstreams/%1$s', $nameOrId), $document); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* update or create upstream |
76
|
|
|
* |
77
|
|
|
* @param \Unikorp\KongAdminApi\Document\UpstreamDocument $document |
78
|
|
|
* |
79
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
80
|
|
|
*/ |
81
|
2 |
|
public function updateOrCreateUpstream(Document $document): ResponseInterface |
82
|
|
|
{ |
83
|
2 |
|
return $this->put('/upstreams/', $document); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* delete upstream |
88
|
|
|
* |
89
|
|
|
* @param string $nameOrId |
90
|
|
|
* |
91
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
92
|
|
|
*/ |
93
|
2 |
|
public function deleteUpstream(string $nameOrId): ResponseInterface |
94
|
|
|
{ |
95
|
2 |
|
return $this->delete(sprintf('/upstreams/%1$s', $nameOrId)); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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.