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