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