Completed
Push — master ( 510f92...73b08b )
by Laurens
01:58
created

ImageClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Client;
6
7
use LauLamanApps\IzettleApi\API\Image;
8
use LauLamanApps\IzettleApi\Client\Image\ImageUploadRequestInterface;
9
use LauLamanApps\IzettleApi\Client\Universal\ImageBuilderInterface;
10
use LauLamanApps\IzettleApi\IzettleClientInterface;
11
use Ramsey\Uuid\UuidInterface;
12
13
final class ImageClient
14
{
15
    const BASE_URL = 'https://image.izettle.com/organizations/%s';
16
    const POST_IMAGE = self::BASE_URL . '/products';
17
18
    private $client;
19
    private $organizationUuid = 'self';
20
    private $imageBuilder;
21
22 3
    public function __construct(
23
        IzettleClientInterface $client,
24
        ?UuidInterface $organizationUuid = null,
25
        ImageBuilderInterface $imageBuilder
26
    ) {
27 3
        $this->client = $client;
28 3
        $this->organizationUuid = (string) $organizationUuid;
29 3
        $this->imageBuilder = $imageBuilder;
30 3
    }
31
32 3
    public function postImage(ImageUploadRequestInterface $imageUploadRequest): Image
33
    {
34 3
        $url = sprintf(self::POST_IMAGE, $this->organizationUuid);
35 3
        $data = json_encode($imageUploadRequest->getUploadRequest());
36
37 3
        $response = $this->client->post($url, $data);
38
39 3
        return $this->imageBuilder->buildFromJson($this->client->getJson($response));
40
    }
41
}
42