1 | <?php |
||
22 | class Client implements ClientInterface |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * Request parameters |
||
27 | * |
||
28 | * @var \Symfony\Component\HttpFoundation\ParameterBag |
||
29 | */ |
||
30 | protected $parameters; |
||
31 | |||
32 | /** |
||
33 | * HTTP Client |
||
34 | * @var \GuzzleHttp\ClientInterface |
||
35 | */ |
||
36 | protected $httpClient; |
||
37 | |||
38 | /** |
||
39 | * Instantiate Visual Recognition client with API credentials |
||
40 | * |
||
41 | * @api |
||
42 | * @param HttpClientInterface|null $httpClient |
||
43 | * @throws \Exception |
||
44 | */ |
||
45 | 30 | public function __construct(HttpClientInterface $httpClient = null) |
|
49 | |||
50 | /** |
||
51 | * Get the global default HTTP client. |
||
52 | * |
||
53 | * @return HttpClient |
||
54 | */ |
||
55 | 18 | protected function getDefaultHttpClient() |
|
56 | { |
||
57 | 18 | return new HttpClient( |
|
58 | array( |
||
59 | 18 | 'curl.options' => array(CURLOPT_CONNECTTIMEOUT => 60), |
|
60 | ) |
||
61 | 18 | ); |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Initialize this client with default parameters |
||
66 | * |
||
67 | * @param array $parameters |
||
68 | * @return $this |
||
69 | */ |
||
70 | 29 | public function initialize(array $parameters = array()) |
|
71 | { |
||
72 | 29 | $this->parameters = new ParameterBag; |
|
73 | |||
74 | // set default parameters |
||
75 | 29 | foreach ($this->getDefaultParameters() as $key => $value) { |
|
76 | 29 | $this->parameters->set($key, $value); |
|
77 | 29 | } |
|
78 | |||
79 | 29 | Helper::initialize($this, $parameters); |
|
80 | |||
81 | 29 | return $this; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * Create new request object and initialize. |
||
86 | * |
||
87 | * @param $class |
||
88 | * @param array $parameters |
||
89 | * @return mixed |
||
90 | */ |
||
91 | 25 | protected function createRequest($class, array $parameters) |
|
98 | |||
99 | /** |
||
100 | * Default & required parameters for requests |
||
101 | * |
||
102 | */ |
||
103 | 29 | public function getDefaultParameters() |
|
104 | { |
||
105 | return array( |
||
106 | 29 | 'username' => '', |
|
107 | 29 | 'password' => '', |
|
108 | 'version' => '2015-12-02' |
||
109 | 29 | ); |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * Get Parameters |
||
114 | * |
||
115 | * @return array |
||
116 | */ |
||
117 | 25 | public function getParameters() |
|
121 | |||
122 | /** |
||
123 | * Get Username |
||
124 | * |
||
125 | * @return mixed |
||
126 | */ |
||
127 | 2 | public function getUsername() |
|
131 | |||
132 | /** |
||
133 | * Set Username |
||
134 | * |
||
135 | * @param $value |
||
136 | * @return $this |
||
137 | */ |
||
138 | 29 | public function setUsername($value) |
|
144 | |||
145 | /** |
||
146 | * Get password |
||
147 | * |
||
148 | * @return mixed |
||
149 | */ |
||
150 | 2 | public function getPassword() |
|
154 | |||
155 | /** |
||
156 | * Set Password |
||
157 | * |
||
158 | * @param $value |
||
159 | * @return $this |
||
160 | */ |
||
161 | 29 | public function setPassword($value) |
|
167 | |||
168 | /** |
||
169 | * Get Version |
||
170 | * |
||
171 | * @return mixed |
||
172 | */ |
||
173 | 1 | public function getVersion() |
|
177 | |||
178 | /** |
||
179 | * Set version |
||
180 | * |
||
181 | * @param $value |
||
182 | * @return $this |
||
183 | */ |
||
184 | 18 | public function setVersion($value) |
|
190 | |||
191 | /** |
||
192 | * Get list of available classifiers |
||
193 | * |
||
194 | * @api |
||
195 | * @param array $parameters |
||
196 | * @return GetClassifiersRequest |
||
197 | * @throws \Exception |
||
198 | */ |
||
199 | 9 | public function getClassifiers(array $parameters = []) |
|
203 | |||
204 | /** |
||
205 | * Get detail on individual classifier |
||
206 | * |
||
207 | * @param array $parameters |
||
208 | * @return mixed |
||
209 | */ |
||
210 | 4 | public function getClassifier(array $parameters = []) |
|
214 | |||
215 | /** |
||
216 | * Classify image |
||
217 | * |
||
218 | * @param array $parameters |
||
219 | * @return ClassifyRequest |
||
220 | */ |
||
221 | 4 | public function classify(array $parameters = []) |
|
225 | |||
226 | /** |
||
227 | * Train a new classifier |
||
228 | * |
||
229 | * @param array $parameters |
||
230 | * @return mixed |
||
231 | */ |
||
232 | 3 | public function createClassifier(array $parameters = []) |
|
236 | |||
237 | /** |
||
238 | * Delete a classifier |
||
239 | * |
||
240 | * @param array $parameters |
||
241 | * @return mixed |
||
242 | */ |
||
243 | 5 | public function deleteClassifier(array $parameters = []) |
|
247 | } |
||
248 |