-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathCapabilities.php
More file actions
executable file
·75 lines (63 loc) · 3.1 KB
/
Capabilities.php
File metadata and controls
executable file
·75 lines (63 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Mvdnbrk\DhlParcel\Endpoints;
use Mvdnbrk\DhlParcel\Resources\Capability as CapabilityResource;
use Mvdnbrk\DhlParcel\Resources\Dimensions;
use Mvdnbrk\DhlParcel\Resources\Option;
use Mvdnbrk\DhlParcel\Resources\ParcelType;
use Mvdnbrk\DhlParcel\Resources\Product;
use Tightenco\Collect\Support\Collection;
class Capabilities extends BaseEndpoint
{
public function get(string $senderType, array $filters = []): Collection
{
$queryString = $this->buildQueryString($filters);
$response = $this->performApiCall(
'GET',
'capabilities/'.$senderType.$queryString
);
$capabilities = new Collection();
collect($response)->each(function ($capability) use ($capabilities) {
$capabilityResource = new CapabilityResource([
'rank' => $capability->rank,
'fromCountryCode' => $capability->fromCountryCode,
'toCountryCode' => $capability->toCountryCode,
]);
$capabilityResource->product = new Product([
'key' => $capability->product->key,
'label' => $capability->product->label,
'code' => $capability->product->code,
'menuCode' => $capability->product->menuCode,
'businessProduct' => $capability->product->businessProduct,
'monoColloProduct' => $capability->product->monoColloProduct,
'softwareCharacteristic' => $capability->product->softwareCharacteristic,
'returnProduct' => $capability->product->returnProduct,
]);
$capabilityResource->parcelType = new ParcelType([
'key' => $capability->parcelType->key,
'category' => $capability->parcelType->category,
'minWeightKg' => $capability->parcelType->minWeightKg,
'maxWeightKg' => $capability->parcelType->maxWeightKg,
'defaultWeightKg' => $capability->parcelType->defaultWeightKg,
'minWeightGrams' => $capability->parcelType->minWeightGrams,
'maxWeightGrams' => $capability->parcelType->maxWeightGrams,
'defaultWeightGrams' => $capability->parcelType->defaultWeightGrams,
]);
$capabilityResource->parcelType->dimensions = new Dimensions([
'maxLengthCm' => $capability->parcelType->dimensions->maxLengthCm,
'maxWidthCm' => $capability->parcelType->dimensions->maxWidthCm,
'maxHeightCm' => $capability->parcelType->dimensions->maxHeightCm,
]);
collect($capability->options)->each(function ($option) use ($capabilityResource) {
$capabilityResource->options->add(new Option([
'key' => $option->key,
'description' => $option->description,
'rank' => $option->rank,
'code' => $option->code,
'optionType' => $option->optionType,
]));
});
$capabilities->add($capabilityResource);
});
return $capabilities;
}
}