Downloadable::download()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 9
c 3
b 0
f 0
dl 0
loc 16
rs 9.9666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Picqer\Financials\Exact\Persistance;
4
5
use GuzzleHttp\Client;
6
use Picqer\Financials\Exact\Connection;
7
8
trait Downloadable
9
{
10
    /**
11
     * @return Connection
12
     */
13
    abstract public function connection();
14
15
    /**
16
     * @return string
17
     */
18
    abstract public function getDownloadUrl();
19
20
    /**
21
     * @return mixed Binary representation of file
22
     */
23
    public function download()
24
    {
25
        $client = new Client();
26
27
        $headers = [
28
            'Accept'        => 'application/json',
29
            'Content-Type'  => 'application/json',
30
            'Prefer'        => 'return=representation',
31
            'Authorization' => 'Bearer ' . $this->connection()->getAccessToken(),
32
        ];
33
34
        $res = $client->get($this->getDownloadUrl(), [
35
            'headers' => $headers,
36
        ]);
37
38
        return $res->getBody();
39
    }
40
}
41