GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Client::predict()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Fab\Clarifai;
4
5
use GuzzleHttp\Client as HttpClient;
6
7
class Client
8
{
9
    /**
10
     * @var HttpClient
11
     */
12
    protected $client;
13
14
    /**
15
     * The Clarifai client id.
16
     * @var string
17
     */
18
    protected $clientId;
19
20
    /**
21
     * The Clarifai client secret.
22
     * @var string
23
     */
24
    protected $clientSecret;
25
26
    /**
27
     * The Clarifai access token.
28
     * @var string
29
     */
30
    protected $accessToken;
31
32
    /**
33
     * The Clarifai API base URL.
34
     * @var string
35
     */
36
    protected $baseUrl = 'https://api.clarifai.com/v2';
37
38
    /**
39
     * Instantiate a new clarifai client.
40
     *
41
     * @param HttpClient $client
42
     * @param string $clientId
43
     * @param string $clientSecret
44
     */
45 5
    public function __construct($client, $clientId, $clientSecret)
46
    {
47 5
        $this->client = $client;
48 5
        $this->clientId = $clientId;
49 5
        $this->clientSecret = $clientSecret;
50 5
    }
51
52 3
    public function withAccessToken($accessToken)
53
    {
54 3
        $this->accessToken = $accessToken;
55
56 3
        return $this;
57
    }
58
59
    /**
60
     * Predict the content of an image using the Clarifai API.
61
     *
62
     * @param  array  $urls
63
     * @param  string $modelId
64
     * @return array
65
     */
66 3
    public function predict(array $urls, $modelId = Models::GENERAL)
67
    {
68 3
        $body = [];
69
70 3
        foreach ($urls as $url) {
71 3
            $body['inputs'][] = Input::fromUrl($url)->format();
72
        }
73
74 3
        $response = $this->client->request('POST', $this->baseUrl.'/models/'.$modelId.'/outputs', [
75
            'headers' => [
76 3
                'Accept' => 'application/json',
77 3
                'Content-Type' => 'application/json',
78 3
                'Authorization' => 'Bearer ' . $this->accessToken,
79
            ],
80 3
            'json' => $body,
81
        ]);
82
83 3
        return json_decode($response->getBody(), true);
84
    }
85
86
    /**
87
     * Retrieve a new access token.
88
     *
89
     * @return array
90
     */
91 1
    public function accessToken()
92
    {
93 1
        $response = $this->client->request('POST', $this->baseUrl . '/token', [
94
            'headers' => [
95
                'Accept' => 'application/json',
96
                'Content-Type' => 'application/json',
97 1
            ],
98 1
            'auth' => [$this->clientId, $this->clientSecret],
99
        ]);
100
101 1
        return json_decode($response->getBody(), true);
102
    }
103
}
104