We have detected an error in your notification set-up
(Event-ID dab39dc24f564ec7bd4628d1305fd03c).
Currently, we cannot inform you about inspection progress.
Please check that the user
557058:bca11929-8c2d-43f2-8a82-c5416880d395
still has access to your repository or
update the API account.
1 | <?php |
||
22 | class Api |
||
23 | { |
||
24 | /** |
||
25 | * Api response codes. |
||
26 | */ |
||
27 | const HTTP_RESPONSE_OK = 200; |
||
28 | const HTTP_RESPONSE_CREATED = 201; |
||
29 | const HTTP_RESPONSE_NO_CONTENT = 204; |
||
30 | const HTTP_RESPONSE_BAD_REQUEST = 400; |
||
31 | const HTTP_RESPONSE_UNAUTHORIZED = 401; |
||
32 | const HTTP_RESPONSE_FORBIDDEN = 403; |
||
33 | const HTTP_RESPONSE_NOT_FOUND = 404; |
||
34 | |||
35 | /** |
||
36 | * @var ClientInterface |
||
37 | */ |
||
38 | protected $httpClient; |
||
39 | |||
40 | /** |
||
41 | * Authentication object |
||
42 | * @var Authentication\AuthenticationInterface |
||
43 | */ |
||
44 | protected $auth; |
||
45 | |||
46 | /** |
||
47 | * @param array $options |
||
48 | * @param ClientInterface $client |
||
49 | */ |
||
50 | 282 | public function __construct(array $options = array(), ClientInterface $client = null) |
|
51 | { |
||
52 | 282 | $this->httpClient = (null !== $client) ? $client : new Client($options, $client); |
|
53 | |||
54 | 282 | $this->httpClient->addListener(new NormalizeArrayListener()); |
|
55 | 282 | $this->httpClient->addListener(new ApiOneCollectionListener()); |
|
56 | 282 | } |
|
57 | |||
58 | /** |
||
59 | * @access public |
||
60 | * @return ClientInterface |
||
61 | */ |
||
62 | 106 | public function getClient() |
|
66 | |||
67 | /** |
||
68 | * @access public |
||
69 | * @param ClientInterface $client |
||
70 | * @return $this |
||
71 | */ |
||
72 | 110 | public function setClient(ClientInterface $client) |
|
78 | |||
79 | /** |
||
80 | * Set API login credentials |
||
81 | * |
||
82 | * @access public |
||
83 | * @param Authentication\AuthenticationInterface $auth |
||
84 | * @return void |
||
85 | */ |
||
86 | 11 | public function setCredentials(Authentication\AuthenticationInterface $auth) |
|
97 | |||
98 | /** |
||
99 | * Make an HTTP GET request to API |
||
100 | * |
||
101 | * @access public |
||
102 | * @param string $endpoint API endpoint |
||
103 | * @param string|array $params GET parameters |
||
104 | * @param array $headers HTTP headers |
||
105 | * @return MessageInterface |
||
106 | */ |
||
107 | 2 | public function requestGet($endpoint, $params = array(), $headers = array()) |
|
108 | { |
||
109 | 2 | return $this->getClient()->get($endpoint, $params, $headers); |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * Make an HTTP POST request to API |
||
114 | * |
||
115 | * @access public |
||
116 | * @param string $endpoint API endpoint |
||
117 | * @param string|array $params POST parameters |
||
118 | * @param array $headers HTTP headers |
||
119 | * @return MessageInterface |
||
120 | */ |
||
121 | 1 | public function requestPost($endpoint, $params = array(), $headers = array()) |
|
125 | |||
126 | /** |
||
127 | * Make an HTTP PUT request to API |
||
128 | * |
||
129 | * @access public |
||
130 | * @param string $endpoint API endpoint |
||
131 | * @param string|array $params POST parameters |
||
132 | * @param array $headers HTTP headers |
||
133 | * @return MessageInterface |
||
134 | */ |
||
135 | 1 | public function requestPut($endpoint, $params = array(), $headers = array()) |
|
139 | |||
140 | /** |
||
141 | * Make a HTTP DELETE request to API |
||
142 | * |
||
143 | * @access public |
||
144 | * @param string $endpoint API endpoint |
||
145 | * @param string|array $params DELETE parameters |
||
146 | * @param array $headers HTTP headers |
||
147 | * @return MessageInterface |
||
148 | */ |
||
149 | 1 | public function requestDelete($endpoint, $params = array(), $headers = array()) |
|
153 | |||
154 | /** |
||
155 | * Create HTTP request |
||
156 | * |
||
157 | * @access protected |
||
158 | * @param string $method HTTP method |
||
159 | * @param string $endpoint Api endpoint |
||
160 | * @param string|array $params Request parameter(s) |
||
161 | * @param array $headers HTTP headers |
||
162 | * @return MessageInterface |
||
163 | * |
||
164 | * @throws \RuntimeException |
||
165 | */ |
||
166 | protected function doRequest($method, $endpoint, $params, array $headers) |
||
170 | |||
171 | /** |
||
172 | * Set the preferred format for response |
||
173 | * |
||
174 | * @access public |
||
175 | * @param string $name Format name |
||
176 | * @return self |
||
177 | * |
||
178 | * @throws \InvalidArgumentException |
||
179 | */ |
||
180 | 2 | public function setFormat($name) |
|
186 | |||
187 | /** |
||
188 | * Get current format used for response |
||
189 | * |
||
190 | * @access public |
||
191 | * @return string |
||
192 | */ |
||
193 | 2 | public function getFormat() |
|
197 | |||
198 | /** |
||
199 | * @param string $name |
||
200 | * @return Api |
||
201 | * |
||
202 | * @throws \InvalidArgumentException |
||
203 | */ |
||
204 | 12 | public function api($name) |
|
226 | |||
227 | /** |
||
228 | * @access public |
||
229 | * @return void |
||
230 | */ |
||
231 | 1 | public function __clone() |
|
236 | |||
237 | /** |
||
238 | * Convert JSON to array with error check |
||
239 | * |
||
240 | * @access protected |
||
241 | * @param string $body JSON data |
||
242 | * @return array |
||
243 | * |
||
244 | * @throws \InvalidArgumentException |
||
245 | */ |
||
246 | 15 | protected function decodeJSON($body) |
|
256 | } |
||
257 |