Live::assets()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Distilleries\Contentful\Api\Delivery;
4
5
use GuzzleHttp\RequestOptions;
6
use Psr\Http\Message\ResponseInterface;
7
use Distilleries\Contentful\Api\BaseApi;
8
use Distilleries\Contentful\Api\DeliveryApi;
9
10
class Live extends BaseApi implements DeliveryApi
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected $baseUrl = 'https://cdn.contentful.com';
16
17
    /**
18
     * Preview base URL API.
19
     *
20
     * @var string
21
     */
22
    protected $previewBaseUrl = 'https://preview.contentful.com';
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function entries(array $parameters = []): array
28
    {
29
        $response = $this->query('entries', $parameters);
30
31
        return $this->decodeResponse($response);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function assets(array $parameters = []): array
38
    {
39
        $response = $this->query('assets', $parameters);
40
41
        return $this->decodeResponse($response);
42
    }
43
44
    /**
45
     * Return a raw items response matching given endpoint and parameters.
46
     *
47
     * @param  string  $endpoint
48
     * @param  array  $parameters
49
     * @return \Psr\Http\Message\ResponseInterface
50
     * @throws \GuzzleHttp\Exception\GuzzleException
51
     */
52
    protected function query(string $endpoint, array $parameters): ResponseInterface
53
    {
54
        $token = ! empty($this->config['use_preview']) ? 'preview' : 'live';
55
56
        $url = isset($parameters['id']) ? $this->url($endpoint) . '/' . $parameters['id'] : $this->url($endpoint);
57
        unset($parameters['id']);
58
59
        return $this->client->request('GET', $url, [
60
            RequestOptions::QUERY => array_merge($parameters, [
61
                'access_token' => $this->config['tokens']['delivery'][$token],
62
            ]),
63
        ]);
64
    }
65
}
66