Passed
Push — master ( 4438f7...71dff0 )
by Radu
01:11
created

ShipmentsCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 32 1
A __construct() 0 7 1
1
<?php
2
namespace ParcelValue\ApiClient\Domain\Shipments;
3
4
use WebServCo\Api\JsonApi\Document;
5
use WebServCo\Framework\Cli\Ansi;
6
use WebServCo\Framework\Cli\Sgr;
7
use WebServCo\Framework\CliResponse;
8
9
final class ShipmentsCommand extends \ParcelValue\ApiClient\AbstractController
10
{
11
    use \ParcelValue\ApiClient\Traits\ControllerApiTrait;
12
13
    public function __construct()
14
    {
15
        parent::__construct();
16
17
        $this->repository = new ShipmentsRepository($this->outputLoader);
18
19
        $this->validateApiConfig();
20
    }
21
22
    public function create()
23
    {
24
        $this->outputCli(Ansi::clear(), true);
25
        $this->outputCli(Ansi::sgr(__METHOD__, [Sgr::BOLD]), true);
26
27
        $this->initApiCall();
28
29
        $url = sprintf(
30
            '%s%s/shipments',
31
            $this->apiUrl,
32
            $this->apiVersion
33
        );
34
35
        $jwt = \ParcelValue\Api\AuthenticationToken::generate($this->clientId, $this->clientKey, $this->serverKey);
36
        $headers = [
37
            'Authorization' => sprintf('Bearer %s', $jwt),
38
            'Content-Type' => Document::CONTENT_TYPE,
39
        ];
40
41
        $shipment = $this->repository->getTestShipment();
42
43
        $document = new Document();
44
        $document->setData($shipment);
45
46
        $this->handleApiCall(
47
            $url,
48
            \WebServCo\Framework\Http::METHOD_POST,
49
            $headers,
50
            $document->toJson()
51
        );
52
53
        return new CliResponse('', true);
54
    }
55
}
56