1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bobbyshaw\WatsonVisualRecognition\Message; |
4
|
|
|
|
5
|
|
|
use Bobbyshaw\WatsonVisualRecognition\Exceptions\AuthException; |
6
|
|
|
use GuzzleHttp\Exception\ClientException; |
7
|
|
|
use GuzzleHttp\Psr7\MultipartStream; |
8
|
|
|
use GuzzleHttp\Psr7\Request; |
9
|
|
|
use InvalidArgumentException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class DeleteClassifierRequest |
13
|
|
|
* @package Bobbyshaw\WatsonVisualRecognition\Message |
14
|
|
|
*/ |
15
|
|
|
class DeleteClassifierRequest extends AbstractRequest |
16
|
|
|
{ |
17
|
|
|
const CLASSIFIERS_PATH = 'classifiers/'; |
18
|
|
|
|
19
|
|
|
|
20
|
5 |
|
public function getData() |
21
|
|
|
{ |
22
|
5 |
|
$data = parent::getData(); |
23
|
|
|
|
24
|
5 |
|
$data['classifier_id'] = $this->getClassifierId(); |
25
|
|
|
|
26
|
5 |
|
return $data; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Send HTTP request to create a new classifier |
31
|
|
|
* |
32
|
|
|
* @param array $data |
33
|
|
|
* @return ClassifierResponse |
34
|
|
|
* @throws AuthException |
35
|
|
|
* @throws \Exception |
36
|
|
|
*/ |
37
|
4 |
|
public function sendData($data) |
38
|
|
|
{ |
39
|
4 |
|
$query = ['version' => $data['version']]; |
40
|
|
|
|
41
|
4 |
|
$request = new Request( |
42
|
4 |
|
'DELETE', |
43
|
4 |
|
$this->getApiUrl(static::CLASSIFIERS_PATH) . $data['classifier_id'] . '?' . http_build_query($query), |
44
|
4 |
|
['Authorization' => 'Basic ' . base64_encode($data['username'] . ':' . $data['password'])] |
45
|
4 |
|
); |
46
|
|
|
|
47
|
|
|
try { |
48
|
4 |
|
$response = $this->httpClient->send($request); |
49
|
|
|
|
50
|
3 |
|
if ($response->getStatusCode() != 200) { |
51
|
|
|
throw new \Exception($response->getBody()->getContents(), $response->getStatusCode()); |
52
|
|
|
} |
53
|
4 |
|
} catch (ClientException $e) { |
54
|
1 |
|
if ($e->getCode() == 401) { |
55
|
1 |
|
throw new AuthException('Invalid credentials provided'); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
3 |
|
return $this->response = new Response($this, $response->getBody()); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|