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