1 | <?php |
||
22 | abstract class AbstractRequest implements RequestInterface |
||
23 | { |
||
24 | const ENDPOINT = 'https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/'; |
||
25 | |||
26 | /** |
||
27 | * The request parameters |
||
28 | * |
||
29 | * @var \Symfony\Component\HttpFoundation\ParameterBag |
||
30 | */ |
||
31 | protected $parameters; |
||
32 | |||
33 | /** |
||
34 | * The request client. |
||
35 | * |
||
36 | * @var \GuzzleHttp\ClientInterface |
||
37 | */ |
||
38 | protected $httpClient; |
||
39 | |||
40 | |||
41 | /** |
||
42 | * An associated ResponseInterface. |
||
43 | * |
||
44 | * @var ResponseInterface |
||
45 | */ |
||
46 | protected $response; |
||
47 | |||
48 | /** |
||
49 | * Create a new Request |
||
50 | * |
||
51 | * @param ClientInterface $httpClient A Guzzle client to make API calls with |
||
52 | */ |
||
53 | public function __construct(ClientInterface $httpClient) |
||
58 | |||
59 | /** |
||
60 | * Get the watson API endpoint |
||
61 | * |
||
62 | * @api |
||
63 | * @return string |
||
64 | */ |
||
65 | public function getEndpoint() |
||
69 | |||
70 | /** |
||
71 | * Get full API URL |
||
72 | * |
||
73 | * @param String $path of API needed |
||
74 | * @returns String of full URL |
||
75 | */ |
||
76 | public function getApiUrl($path) |
||
80 | |||
81 | /** |
||
82 | * Initialize the object with parameters. |
||
83 | * |
||
84 | * @param array $parameters An associative array of parameters |
||
85 | * |
||
86 | * @return $this |
||
87 | * @throws \RuntimeException |
||
88 | */ |
||
89 | public function initialize(array $parameters = array()) |
||
101 | |||
102 | /** |
||
103 | * Get all parameters as an associative array. |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | public function getParameters() |
||
111 | |||
112 | /** |
||
113 | * Get a single parameter. |
||
114 | * |
||
115 | * @param string $key The parameter key |
||
116 | * @return mixed |
||
117 | */ |
||
118 | protected function getParameter($key) |
||
122 | |||
123 | /** |
||
124 | * Set a single parameter |
||
125 | * |
||
126 | * @param string $key The parameter key |
||
127 | * @param mixed $value The value to set |
||
128 | * @return AbstractRequest Provides a fluent interface |
||
129 | * @throws \RuntimeException if a request parameter is modified after the request has been sent. |
||
130 | */ |
||
131 | protected function setParameter($key, $value) |
||
141 | |||
142 | /** |
||
143 | * Get Username |
||
144 | * |
||
145 | * @return mixed |
||
146 | */ |
||
147 | public function getUsername() |
||
151 | |||
152 | /** |
||
153 | * Set Username |
||
154 | * |
||
155 | * @param $value |
||
156 | * @return $this |
||
157 | */ |
||
158 | public function setUsername($value) |
||
164 | |||
165 | /** |
||
166 | * Get password |
||
167 | * |
||
168 | * @return mixed |
||
169 | */ |
||
170 | public function getPassword() |
||
174 | |||
175 | /** |
||
176 | * Set Password |
||
177 | * |
||
178 | * @param $value |
||
179 | * @return $this |
||
180 | */ |
||
181 | public function setPassword($value) |
||
187 | |||
188 | /** |
||
189 | * Get Version |
||
190 | * |
||
191 | * @return mixed |
||
192 | */ |
||
193 | public function getVersion() |
||
197 | |||
198 | /** |
||
199 | * Get image file. |
||
200 | * |
||
201 | * @return mixed |
||
202 | */ |
||
203 | public function getImagesFile() |
||
207 | |||
208 | /** |
||
209 | * Set Image file |
||
210 | * |
||
211 | * @param $value |
||
212 | * @return AbstractRequest |
||
213 | */ |
||
214 | public function setImagesFile($value) |
||
220 | |||
221 | /** |
||
222 | * Get Classifier Ids |
||
223 | * |
||
224 | * @return mixed |
||
225 | */ |
||
226 | public function getClassifierIds() |
||
230 | |||
231 | /** |
||
232 | * Set Classifier Ids |
||
233 | * |
||
234 | * @param $value |
||
235 | * @return $this |
||
236 | */ |
||
237 | public function setClassifierIds($value) |
||
243 | |||
244 | /** |
||
245 | * Set version |
||
246 | * |
||
247 | * @param $value |
||
248 | * @return $this |
||
249 | */ |
||
250 | public function setVersion($value) |
||
256 | |||
257 | |||
258 | /** |
||
259 | * Configure command is run before every request is sent |
||
260 | */ |
||
261 | public function configure() |
||
264 | |||
265 | /** |
||
266 | * Get Default request data params |
||
267 | * |
||
268 | * @return array |
||
269 | */ |
||
270 | public function getData() |
||
278 | |||
279 | |||
280 | /** |
||
281 | * Send the request |
||
282 | * |
||
283 | * @return ResponseInterface |
||
284 | */ |
||
285 | public function send() |
||
293 | |||
294 | /** |
||
295 | * Get the associated Response. |
||
296 | * |
||
297 | * @return ResponseInterface |
||
298 | */ |
||
299 | public function getResponse() |
||
307 | } |
||
308 |