1 | <?php |
||
21 | abstract class AbstractRequest implements RequestInterface |
||
22 | { |
||
23 | const ENDPOINT = 'https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/'; |
||
24 | |||
25 | /** |
||
26 | * The request parameters |
||
27 | * |
||
28 | * @var \Symfony\Component\HttpFoundation\ParameterBag |
||
29 | */ |
||
30 | protected $parameters; |
||
31 | |||
32 | /** |
||
33 | * The request client. |
||
34 | * |
||
35 | * @var \GuzzleHttp\ClientInterface |
||
36 | */ |
||
37 | protected $httpClient; |
||
38 | |||
39 | |||
40 | /** |
||
41 | * An associated ResponseInterface. |
||
42 | * |
||
43 | * @var ResponseInterface |
||
44 | */ |
||
45 | protected $response; |
||
46 | |||
47 | /** |
||
48 | * Create a new Request |
||
49 | * |
||
50 | * @param ClientInterface $httpClient A Guzzle client to make API calls with |
||
51 | */ |
||
52 | 38 | public function __construct(ClientInterface $httpClient) |
|
53 | 1 | { |
|
54 | 38 | $this->httpClient = $httpClient; |
|
55 | 38 | $this->initialize(); |
|
56 | 38 | } |
|
57 | |||
58 | /** |
||
59 | * Get the watson API endpoint |
||
60 | * |
||
61 | * @api |
||
62 | * @return string |
||
63 | */ |
||
64 | 21 | public function getEndpoint() |
|
68 | |||
69 | /** |
||
70 | * Get full API URL |
||
71 | * |
||
72 | * @param String $path of API needed |
||
73 | * @returns String of full URL |
||
74 | */ |
||
75 | 21 | public function getApiUrl($path) |
|
79 | |||
80 | /** |
||
81 | * Initialize the object with parameters. |
||
82 | * |
||
83 | * @param array $parameters An associative array of parameters |
||
84 | * |
||
85 | * @return $this |
||
86 | * @throws \RuntimeException |
||
87 | */ |
||
88 | 38 | public function initialize(array $parameters = array()) |
|
100 | |||
101 | /** |
||
102 | * Get all parameters as an associative array. |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | 1 | public function getParameters() |
|
110 | |||
111 | /** |
||
112 | * Get a single parameter. |
||
113 | * |
||
114 | * @param string $key The parameter key |
||
115 | * @return mixed |
||
116 | */ |
||
117 | 28 | protected function getParameter($key) |
|
121 | |||
122 | /** |
||
123 | * Set a single parameter |
||
124 | * |
||
125 | * @param string $key The parameter key |
||
126 | * @param mixed $value The value to set |
||
127 | * @return AbstractRequest Provides a fluent interface |
||
128 | * @throws \RuntimeException if a request parameter is modified after the request has been sent. |
||
129 | */ |
||
130 | 32 | protected function setParameter($key, $value) |
|
140 | |||
141 | /** |
||
142 | * Get Username |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | 28 | public function getUsername() |
|
150 | |||
151 | /** |
||
152 | * Set Username |
||
153 | * |
||
154 | * @param string $value |
||
155 | * @return $this |
||
156 | */ |
||
157 | 27 | public function setUsername($value) |
|
163 | |||
164 | /** |
||
165 | * Get password |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | 28 | public function getPassword() |
|
173 | |||
174 | /** |
||
175 | * Set Password |
||
176 | * |
||
177 | * @param string $value |
||
178 | * @return $this |
||
179 | */ |
||
180 | 25 | public function setPassword($value) |
|
186 | |||
187 | /** |
||
188 | * Get Version |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | 28 | public function getVersion() |
|
196 | |||
197 | /** |
||
198 | * Set version |
||
199 | * |
||
200 | * @param $value |
||
201 | * @return $this |
||
202 | */ |
||
203 | 25 | public function setVersion($value) |
|
209 | |||
210 | /** |
||
211 | * Set verbose parameter |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | 8 | public function getVerbose() |
|
219 | |||
220 | /** |
||
221 | * @param string $value |
||
222 | * @return $this |
||
223 | */ |
||
224 | 2 | public function setVerbose($value) |
|
230 | |||
231 | /** |
||
232 | * Get image file. |
||
233 | * |
||
234 | * @return string |
||
235 | */ |
||
236 | 6 | public function getImagesFile() |
|
240 | |||
241 | /** |
||
242 | * Set Image file |
||
243 | * |
||
244 | * @param string $value |
||
245 | * @return $this |
||
246 | */ |
||
247 | 6 | public function setImagesFile($value) |
|
253 | |||
254 | /** |
||
255 | * Get Classifier Ids |
||
256 | * |
||
257 | * @return string[] |
||
258 | */ |
||
259 | 6 | public function getClassifierIds() |
|
263 | |||
264 | /** |
||
265 | * Set Classifier Ids |
||
266 | * |
||
267 | * @param string[] $value |
||
268 | * @return $this |
||
269 | */ |
||
270 | 6 | public function setClassifierIds($value) |
|
276 | |||
277 | /** |
||
278 | * Get Classifier ID |
||
279 | * |
||
280 | * @return String |
||
281 | */ |
||
282 | 9 | public function getClassifierId() |
|
286 | |||
287 | /** |
||
288 | * Set Classifier ID |
||
289 | * |
||
290 | * @param String $value |
||
291 | * @return $this |
||
292 | */ |
||
293 | 9 | public function setClassifierId($value) |
|
299 | |||
300 | /** |
||
301 | * Get positive examples zip file path |
||
302 | * |
||
303 | * @return string |
||
304 | */ |
||
305 | 5 | public function getPositiveExamples() |
|
309 | |||
310 | /** |
||
311 | * Set file path of positive examples |
||
312 | * |
||
313 | * @param string $value |
||
314 | * @return $this |
||
315 | */ |
||
316 | 5 | public function setPositiveExamples($value) |
|
322 | |||
323 | /** |
||
324 | * Get negative examples zip file path |
||
325 | * |
||
326 | * @return string |
||
327 | */ |
||
328 | 5 | public function getNegativeExamples() |
|
332 | |||
333 | /** |
||
334 | * Set file path of negative examples |
||
335 | * |
||
336 | * @param string $value |
||
337 | * @return $this |
||
338 | */ |
||
339 | 5 | public function setNegativeExamples($value) |
|
345 | |||
346 | /** |
||
347 | * Get classifier name |
||
348 | * |
||
349 | * @return string |
||
350 | */ |
||
351 | 5 | public function getName() |
|
355 | |||
356 | /** |
||
357 | * Set classifier name |
||
358 | * |
||
359 | * @param string $value |
||
360 | * @return $this |
||
361 | */ |
||
362 | 5 | public function setName($value) |
|
368 | |||
369 | /** |
||
370 | * Get Default request data params |
||
371 | * |
||
372 | * @return array |
||
373 | */ |
||
374 | 28 | public function getData() |
|
375 | { |
||
376 | return [ |
||
377 | 28 | 'username' => $this->getUsername(), |
|
378 | 28 | 'password' => $this->getPassword(), |
|
379 | 28 | 'version' => $this->getVersion() |
|
380 | 28 | ]; |
|
381 | } |
||
382 | |||
383 | |||
384 | /** |
||
385 | * Send the request |
||
386 | * |
||
387 | * @return ResponseInterface |
||
388 | */ |
||
389 | 23 | public function send() |
|
395 | |||
396 | /** |
||
397 | * Get the associated Response. |
||
398 | * |
||
399 | * @return ResponseInterface |
||
400 | */ |
||
401 | 2 | public function getResponse() |
|
409 | } |
||
410 |