Test Failed
Pull Request — master (#9)
by Laurens
01:59
created

ImageClient   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A postImage() 0 11 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
    public function __construct(IzettleClientInterface $client, UuidInterface $organizationUuid, ImageBuilderInterface $imageBuilder)
23
    {
24
        $this->client = $client;
25
        $this->organizationUuid = (string) $organizationUuid;
26
        $this->imageBuilder = $imageBuilder;
27
    }
28
29
    public function postImage(ImageUploadRequestInterface $imageUploadRequest): Image
30
    {
31
        $url = sprintf(self::POST_IMAGE, $this->organizationUuid);
32
        $data = json_encode($imageUploadRequest->getUploadRequest());
33
34
        $response = $this->client->post($url, $data);
35
36
        return $this->imageBuilder->buildFromJson($this->client->getJson($response));
37
38
39
    }
40
}
41