Completed
Push — master ( e64d63...07010a )
by Gabriel
10:26 queued 11s
created

DivideIQClient::download()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 13
ccs 0
cts 11
cp 0
crap 2
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
4
namespace Stockbase\Integration\StockbaseApi\Client\DivideIQ;
5
6
use DivideBV\PHPDivideIQ\DivideIQ;
7
8
/**
9
 * DivideIQ API client with extended functionality.
10
 */
11
class DivideIQClient extends DivideIQ
12
{
13
14
    const DEFAULT_REQUEST_TIMEOUT = 60.0;
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function __construct($username, $password, $environment = 'production')
20
    {
21
        parent::__construct($username, $password, $environment);
22
        
23
        $this->setRequestTimeout(self::DEFAULT_REQUEST_TIMEOUT);
24
    }
25
26
    /**
27
     * Sets the request timeout value.
28
     *
29
     * @param float $timeout Timeout in seconds.
30
     */
31
    public function setRequestTimeout($timeout)
32
    {
33
        $this->client->setDefaultOption('timeout', $timeout);
34
    }
35
36
    /**
37
     * Downloads a file using current client configuration and saves it at the specified destination.
38
     * 
39
     * @param string|\GuzzleHttp\Url $uri File URI.
40
     * @param string|resource|\GuzzleHttp\Stream\StreamInterface $destination Destination where the file should be saved to.
41
     */
42
    public function download($uri, $destination)
43
    {
44
        // Setup the connection.
45
        $this->setup();
46
47
        $this->client->get($uri, [
48
            'headers' => [
49
                'Content-Type' => null,
50
                'Authentication' => $this->accessToken->getToken(),
51
            ],
52
            'save_to' => $destination, //TODO: Change to `sink` for Guzzle 6
53
        ]);
54
    }
55
}
56