Skip to content

Commit 56f1aea

Browse files
authored
Merge pull request #6 from gpl-ajackson/master
Implement Multi-Collo support
2 parents 3681703 + 97081da commit 56f1aea

12 files changed

Lines changed: 394 additions & 1 deletion

src/Endpoints/AbstractEndpoint.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,36 @@ protected function restCreate(array $body)
6666
return ResourceFactory::createFromApiResult($result, $this->getResourceObject(), $this->getSingleResourceKey());
6767
}
6868

69+
/**
70+
* @param array $body
71+
* @return AbstractCollection
72+
* @throws ApiException
73+
*/
74+
protected function restCreateCollection(array $body)
75+
{
76+
$result = $this->client->performHttpCall(
77+
self::REST_CREATE,
78+
$this->getResourcePath(),
79+
$this->parseRequestBody($body)
80+
);
81+
82+
/** @var AbstractCollection $collection */
83+
$collection = $this->getResourceCollectionObject(
84+
null,
85+
null
86+
);
87+
88+
if (is_object($result)) {
89+
$result = $result->{$collection->getCollectionResourceName()};
90+
}
91+
92+
foreach ($result as $dataResult) {
93+
$collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject());
94+
}
95+
96+
return $collection;
97+
}
98+
6999
/**
70100
* @param $id
71101
* @param array $filters
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Imbue\SendCloud\Endpoints;
4+
5+
use Imbue\SendCloud\Exceptions\ApiException;
6+
use Imbue\SendCloud\Resources\Collections\ParcelCollection;
7+
use Imbue\SendCloud\Resources\GenericStatus;
8+
use Imbue\SendCloud\Resources\Parcel;
9+
use Imbue\SendCloud\Resources\ParcelMulti;
10+
use Imbue\SendCloud\Resources\ResourceFactory;
11+
12+
class ParcelMultiEndpoint extends AbstractEndpoint
13+
{
14+
/** @var string */
15+
protected $resourcePath = 'parcels';
16+
17+
/**
18+
* @return Parcel
19+
*/
20+
protected function getResourceObject(): Parcel
21+
{
22+
return new Parcel($this->client);
23+
}
24+
25+
/**
26+
* @param $previous
27+
* @param $next
28+
* @return ParcelCollection
29+
*/
30+
protected function getResourceCollectionObject($previous, $next): ParcelCollection
31+
{
32+
return new ParcelCollection($this->client, $previous, $next);
33+
}
34+
35+
/**
36+
* @param array $data
37+
* @return ParcelCollection
38+
* @throws ApiException
39+
*/
40+
public function create(array $data = []): ParcelCollection
41+
{
42+
return $this->restCreateCollection($data);
43+
}
44+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Imbue\SendCloud\Endpoints;
4+
5+
use Imbue\SendCloud\Exceptions\ApiException;
6+
use Imbue\SendCloud\Resources\AbstractResource;
7+
use Imbue\SendCloud\Resources\Collections\AbstractCollection;
8+
use Imbue\SendCloud\Resources\Collections\ShippingProductCollection;
9+
use Imbue\SendCloud\Resources\ShippingProduct;
10+
11+
class ShippingProductsEndpoint extends AbstractEndpoint
12+
{
13+
/** @var string */
14+
protected $resourcePath = 'shipping-products';
15+
/** @var string */
16+
protected $singleResourceKey = 'shipping_product';
17+
18+
/**
19+
* @return mixed
20+
*/
21+
protected function getResourceObject(): ShippingProduct
22+
{
23+
return new ShippingProduct($this->client);
24+
}
25+
26+
/**
27+
* @return ShippingProductCollection
28+
*/
29+
protected function getResourceCollectionObject(): ShippingProductCollection
30+
{
31+
return new ShippingProductCollection(null, null);
32+
}
33+
34+
/**
35+
* @param $id
36+
* @param array $filters
37+
* @return AbstractResource
38+
* @throws ApiException
39+
*/
40+
public function get($id, array $filters = [])
41+
{
42+
return $this->list($filters)->getArrayCopy()->get($id);
43+
}
44+
45+
/**
46+
* @param $filters
47+
* @return array|AbstractCollection
48+
* @throws ApiException
49+
*/
50+
public function list(array $filters = [])
51+
{
52+
return $this->restList($filters);
53+
}}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
3+
namespace Imbue\SendCloud\Resources;
4+
5+
class AvailableShippingFunctionality
6+
{
7+
/** @var (null|int)[] */
8+
public $age_check;
9+
10+
/** @var bool[] */
11+
public $b2b;
12+
13+
/** @var bool[] */
14+
public $b2c;
15+
16+
/** @var bool[] */
17+
public $boxable;
18+
19+
/** @var bool[] */
20+
public $bulky_goods;
21+
22+
/** @var (null|string)[] */
23+
public $carrier_billing_type;
24+
25+
/** @var (null|bool)[] */
26+
public $cash_on_delivery;
27+
28+
/** @var bool[] */
29+
public $dangerous_goods;
30+
31+
/** @var (null|int)[] */
32+
public $delivery_attempts;
33+
34+
/** @var (null|string)[] */
35+
public $delivery_before;
36+
37+
/** @var (null|string)[] */
38+
public $delivery_deadline;
39+
40+
/** @var bool[] */
41+
public $direct_contract_only;
42+
43+
/** @var bool[] */
44+
public $eco_delivery;
45+
46+
/** @var bool[] */
47+
public $ers;
48+
49+
/** @var (null|string)[] */
50+
public $first_mile;
51+
52+
/** @var bool[] */
53+
public $flex_delivery;
54+
55+
/** @var (null|string)[] */
56+
public $form_factor;
57+
58+
/** @var bool[] */
59+
public $fragile_goods;
60+
61+
/** @var bool[] */
62+
public $fresh_goods;
63+
64+
/** @var bool[] */
65+
public $harmonized_label;
66+
67+
/** @var bool[] */
68+
public $id_check;
69+
70+
/** @var (null|string)[] */
71+
public $incoterm;
72+
73+
/** @var (null|int)[] */
74+
public $insurance;
75+
76+
/** @var bool[] */
77+
public $labelless;
78+
79+
/** @var (null|string)[] */
80+
public $last_mile;
81+
82+
/** @var bool[] */
83+
public $manually;
84+
85+
/** @var bool[] */
86+
public $multicollo;
87+
88+
/** @var bool[] */
89+
public $neighbor_delivery;
90+
91+
/** @var bool[] */
92+
public $non_conveyable;
93+
94+
/** @var bool[] */
95+
public $personalized_delivery;
96+
97+
/** @var bool[] */
98+
public $premium;
99+
100+
/** @var (null|string)[] */
101+
public $priority;
102+
103+
/** @var bool[] */
104+
public $registered_delivery;
105+
106+
/** @var bool[] */
107+
public $returns;
108+
109+
/** @var (null|string)[] **/
110+
public $segment;
111+
112+
/** @var (null|string)[] */
113+
public $service_area;
114+
115+
/** @var bool[] */
116+
public $signature;
117+
118+
/** @var (null|string)[] */
119+
public $size;
120+
121+
/** @var bool[] */
122+
public $sorted;
123+
124+
/** @var bool[] */
125+
public $surcharge;
126+
127+
/** @var bool[] */
128+
public $tracked;
129+
130+
/** @var bool[] */
131+
public $tyres;
132+
133+
/** @var (null|string)[] */
134+
public $weekend_delivery;
135+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Imbue\SendCloud\Resources\Collections;
4+
5+
use Imbue\SendCloud\Resources\ShippingProduct;
6+
7+
class ShippingProductCollection extends AbstractCollection
8+
{
9+
/**
10+
* @return string
11+
*/
12+
public function getCollectionResourceName()
13+
{
14+
return 'shipping_products';
15+
}
16+
17+
/**
18+
* @return ShippingProduct
19+
*/
20+
protected function createResourceObject(): ShippingProduct
21+
{
22+
return new ShippingProduct($this->client);
23+
}
24+
}

src/Resources/Parcel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,6 @@ class Parcel extends AbstractResource
7878
public $tracking_url;
7979
/** @var string */
8080
public $country_state;
81+
/** @var int */
82+
public $quantity;
8183
}

src/Resources/ShippingProduct.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Imbue\SendCloud\Resources;
4+
5+
class ShippingProduct extends AbstractResource
6+
{
7+
/** @var string */
8+
public $name;
9+
10+
/** @var string */
11+
public $code;
12+
13+
/** @var string */
14+
public $carrier;
15+
16+
/** @var string */
17+
public $service_points_carrier;
18+
19+
/** @var WeightRange */
20+
public $weight_range;
21+
22+
/** @var AvailableShippingFunctionality[] */
23+
public $available_functionalities;
24+
25+
/** @var ShippingProductMethod[] */
26+
public $methods;
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Imbue\SendCloud\Resources;
4+
5+
class ShippingProductMethod
6+
{
7+
/** @var int */
8+
public $id;
9+
10+
/** @var string */
11+
public $name;
12+
13+
/** @var AvailableShippingFunctionality */
14+
public $functionalities;
15+
16+
/** @var string */
17+
public $shippingProductCode;
18+
19+
/** @var ShippingProductMethodProperties */
20+
public $properties;
21+
22+
/** @var object */
23+
public $leadTimeHours;
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Imbue\SendCloud\Resources;
4+
5+
class ShippingProductMethodProperties
6+
{
7+
/** @var int */
8+
public $min_weight;
9+
10+
/** @var int */
11+
public $max_weight;
12+
13+
/** @var ShippingProductMethodPropertiesMaxDimensions */
14+
public $max_dimensions;
15+
}
16+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Imbue\SendCloud\Resources;
4+
5+
class ShippingProductMethodPropertiesMaxDimensions
6+
{
7+
/** @var int */
8+
public $length;
9+
10+
/** @var int */
11+
public $width;
12+
13+
/** @var int */
14+
public $height;
15+
16+
/** @var string */
17+
public $unit;
18+
}

0 commit comments

Comments
 (0)