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