Completed
Push — develop ( 4ff741...64bd10 )
by Tom
14:53
created

GetClassifiersRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 7
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A sendData() 0 21 3
1
<?php
2
3
namespace Bobbyshaw\WatsonVisualRecognition\Message;
4
5
use Bobbyshaw\WatsonVisualRecognition\Exceptions\AuthException;
6
use GuzzleHttp\Exception\ClientException;
7
use GuzzleHttp\Psr7\Request;
8
9
/**
10
 * Class GetClassifiersRequest
11
 * @package Bobbyshaw\WatsonVisualRecognition\Message
12
 */
13
class GetClassifiersRequest extends AbstractRequest
14
{
15
    const CLASSIFIERS_PATH = 'classifiers/';
16
17
    /**
18
     * Send HTTP request to get list of classifiers
19
     *
20
     * @param array $data
21
     * @return ClassifiersResponse
22
     * @throws AuthException
23
     */
24
    public function sendData($data)
25
    {
26
        $request = new Request(
27
            'GET',
28
            $this->getApiUrl(static::CLASSIFIERS_PATH) . '?' . http_build_query(['version' => $data['version']]),
29
            ['Authorization' => 'Basic ' . base64_encode($data['username'] . ':' . $data['password'])]
30
        );
31
32
        $this->response = null;
33
34
        try {
35
            $response = $this->httpClient->send($request);
36
            $this->response = new ClassifiersResponse($this, $response->getBody());
37
        } catch (ClientException $e) {
38
            if ($e->getCode() == 401) {
39
                throw new AuthException('Invalid credentials provided');
40
            }
41
        }
42
43
        return $this->response;
44
    }
45
}
46