Completed
Pull Request — master (#1)
by Paulius
02:50
created

Client::getEndpointUrl()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
namespace DPD\Interconnector;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use Psr\Http\Message\ResponseInterface;
7
use DPD\Interconnector\Request\LabelsRequest;
8
use DPD\Interconnector\Request\ManifestRequest;
9
use DPD\Interconnector\Request\ShipmentRequest;
10
11
class Client extends GuzzleClient
12
{
13
    /**
14
     * test endpoint for Estonia
15
     */
16
    const EE_TEST_ENDPOINT_URL = 'https://ee.integration.dpd.eo.pl/ws-mapper-rest/';
17
18
    /**
19
     * production endpoint for Estonia
20
     */
21
    const EE_PRODUCTION_ENDPOINT_URL = 'https://integration.dpd.ee:8443/ws-mapper-rest/';
22
23
    /**
24
     * test endpoint for Latvia
25
     */
26
    const LV_TEST_ENDPOINT_URL = 'https://lv.integration.dpd.eo.pl/ws-mapper-rest/';
27
28
    /**
29
     * production endpoint for Latvia
30
     */
31
    const LV_PRODUCTION_ENDPOINT_URL = 'https://integration.dpd.lv:8443/ws-mapper-rest/';
32
33
    /**
34
     * test endpoint for Lithuania
35
     */
36
    const LT_TEST_ENDPOINT_URL = 'https://lt.integration.dpd.eo.pl/ws-mapper-rest/';
37
38
    /**
39
     * production endpoint for Lithuania
40
     */
41
    const LT_PRODUCTION_ENDPOINT_URL = 'https://integracijos.dpd.lt/ws-mapper-rest/';
42
43
    public function createShipment(ShipmentRequest $shipment): ResponseInterface
44
    {
45
        return $this->request(
46
            'POST',
47
            $this->getEndpointUrl($shipment->getCountry()) . '/createShipment_',
48
            [
49
                'form_params' => $shipment->toArray(),
50
                'verify' => false
51
            ]
52
        );
53
    }
54
55
    public function getLabels(LabelsRequest $request): ResponseInterface
56
    {
57
        return $this->request(
58
            'POST',
59
            $this->getEndpointUrl($request->getCountry()) . '/parcelPrint_',
60
            [
61
                'form_params' => $request->toArray(),
62
                'verify' => false
63
            ]
64
        );
65
    }
66
67
    public function getManifest(ManifestRequest $request): ResponseInterface
68
    {
69
        return $this->request(
70
            'POST',
71
            $this->getEndpointUrl($request->getCountry()) . '/parcelManifestPrint_',
72
            [
73
                'form_params' => $request->toArray(),
74
                'verify' => false
75
            ]
76
        );
77
    }
78
79
    private function getEndpointUrl(string $country)
80
    {
81
        switch ($country) {
82
            case 'LT':
83
                return self::LT_PRODUCTION_ENDPOINT_URL;
84
            case 'LV':
85
                return self::LV_PRODUCTION_ENDPOINT_URL;
86
            case 'EE':
87
            default:
88
                return self::EE_PRODUCTION_ENDPOINT_URL;
89
        }
90
    }
91
}