StatClient::downloadBulkJobStream()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace SchulzeFelix\Stat;
4
5
use GuzzleHttp\Client;
6
7
class StatClient
8
{
9
    /**
10
     * @var Client
11
     */
12
    private $client;
13
14
    /**
15
     * Sistrix constructor.
16
     * @param Client $client
17
     */
18
    public function __construct(Client $client)
19
    {
20
        $this->client = $client;
21
    }
22
23
    public function performQuery(string $method, array $parameters)
24
    {
25
        $request = $this->buildRequest($method, $parameters);
26
        $response = $this->client->get($request);
27
28
        return json_decode($response->getBody()->getContents(), true);
29
    }
30
31
    public function downloadBulkJobStream($streamUrl)
32
    {
33
        $response = $this->client->get($streamUrl);
34
35
        return json_decode($response->getBody()->getContents(), true);
36
    }
37
38
    protected function buildRequest($method, $parameters = [])
39
    {
40
        $parameterString = '?format=json';
41
42
        foreach ($parameters as $parameter => $value) {
43
            $parameterString .= '&'.$parameter.'='.$value;
44
        }
45
46
        $request = $method.$parameterString;
47
48
        return $request;
49
    }
50
}
51