Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Multi-Collo support #6

Merged
merged 5 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/Endpoints/AbstractEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,36 @@ protected function restCreate(array $body)
return ResourceFactory::createFromApiResult($result, $this->getResourceObject(), $this->getSingleResourceKey());
}

/**
* @param array $body
* @return AbstractCollection
* @throws ApiException
*/
protected function restCreateCollection(array $body)
{
$result = $this->client->performHttpCall(
self::REST_CREATE,
$this->getResourcePath(),
$this->parseRequestBody($body)
);

/** @var AbstractCollection $collection */
$collection = $this->getResourceCollectionObject(
null,
null
);

if (is_object($result)) {
$result = $result->{$collection->getCollectionResourceName()};
}

foreach ($result as $dataResult) {
$collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject());
}

return $collection;
}

/**
* @param $id
* @param array $filters
Expand Down
44 changes: 44 additions & 0 deletions src/Endpoints/ParcelMultiEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Imbue\SendCloud\Endpoints;

use Imbue\SendCloud\Exceptions\ApiException;
use Imbue\SendCloud\Resources\Collections\ParcelCollection;
use Imbue\SendCloud\Resources\GenericStatus;
use Imbue\SendCloud\Resources\Parcel;
use Imbue\SendCloud\Resources\ParcelMulti;
use Imbue\SendCloud\Resources\ResourceFactory;

class ParcelMultiEndpoint extends AbstractEndpoint
{
/** @var string */
protected $resourcePath = 'parcels';

/**
* @return Parcel
*/
protected function getResourceObject(): Parcel
{
return new Parcel($this->client);
}

/**
* @param $previous
* @param $next
* @return ParcelCollection
*/
protected function getResourceCollectionObject($previous, $next): ParcelCollection
{
return new ParcelCollection($this->client, $previous, $next);
}

/**
* @param array $data
* @return ParcelCollection
* @throws ApiException
*/
public function create(array $data = []): ParcelCollection
{
return $this->restCreateCollection($data);
}
}
53 changes: 53 additions & 0 deletions src/Endpoints/ShippingProductsEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Imbue\SendCloud\Endpoints;

use Imbue\SendCloud\Exceptions\ApiException;
use Imbue\SendCloud\Resources\AbstractResource;
use Imbue\SendCloud\Resources\Collections\AbstractCollection;
use Imbue\SendCloud\Resources\Collections\ShippingProductCollection;
use Imbue\SendCloud\Resources\ShippingProduct;

class ShippingProductsEndpoint extends AbstractEndpoint
{
/** @var string */
protected $resourcePath = 'shipping-products';
/** @var string */
protected $singleResourceKey = 'shipping_product';

/**
* @return mixed
*/
protected function getResourceObject(): ShippingProduct
{
return new ShippingProduct($this->client);
}

/**
* @return ShippingProductCollection
*/
protected function getResourceCollectionObject(): ShippingProductCollection
{
return new ShippingProductCollection(null, null);
}

/**
* @param $id
* @param array $filters
* @return AbstractResource
* @throws ApiException
*/
public function get($id, array $filters = [])
{
return $this->list($filters)->getArrayCopy()->get($id);
}

/**
* @param $filters
* @return array|AbstractCollection
* @throws ApiException
*/
public function list(array $filters = [])
{
return $this->restList($filters);
}}
135 changes: 135 additions & 0 deletions src/Resources/AvailableShippingFunctionality.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

namespace Imbue\SendCloud\Resources;

class AvailableShippingFunctionality
{
/** @var (null|int)[] */
public $age_check;

/** @var bool[] */
public $b2b;

/** @var bool[] */
public $b2c;

/** @var bool[] */
public $boxable;

/** @var bool[] */
public $bulky_goods;

/** @var (null|string)[] */
public $carrier_billing_type;

/** @var (null|bool)[] */
public $cash_on_delivery;

/** @var bool[] */
public $dangerous_goods;

/** @var (null|int)[] */
public $delivery_attempts;

/** @var (null|string)[] */
public $delivery_before;

/** @var (null|string)[] */
public $delivery_deadline;

/** @var bool[] */
public $direct_contract_only;

/** @var bool[] */
public $eco_delivery;

/** @var bool[] */
public $ers;

/** @var (null|string)[] */
public $first_mile;

/** @var bool[] */
public $flex_delivery;

/** @var (null|string)[] */
public $form_factor;

/** @var bool[] */
public $fragile_goods;

/** @var bool[] */
public $fresh_goods;

/** @var bool[] */
public $harmonized_label;

/** @var bool[] */
public $id_check;

/** @var (null|string)[] */
public $incoterm;

/** @var (null|int)[] */
public $insurance;

/** @var bool[] */
public $labelless;

/** @var (null|string)[] */
public $last_mile;

/** @var bool[] */
public $manually;

/** @var bool[] */
public $multicollo;

/** @var bool[] */
public $neighbor_delivery;

/** @var bool[] */
public $non_conveyable;

/** @var bool[] */
public $personalized_delivery;

/** @var bool[] */
public $premium;

/** @var (null|string)[] */
public $priority;

/** @var bool[] */
public $registered_delivery;

/** @var bool[] */
public $returns;

/** @var (null|string)[] **/
public $segment;

/** @var (null|string)[] */
public $service_area;

/** @var bool[] */
public $signature;

/** @var (null|string)[] */
public $size;

/** @var bool[] */
public $sorted;

/** @var bool[] */
public $surcharge;

/** @var bool[] */
public $tracked;

/** @var bool[] */
public $tyres;

/** @var (null|string)[] */
public $weekend_delivery;
}
24 changes: 24 additions & 0 deletions src/Resources/Collections/ShippingProductCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Imbue\SendCloud\Resources\Collections;

use Imbue\SendCloud\Resources\ShippingProduct;

class ShippingProductCollection extends AbstractCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return 'shipping_products';
}

/**
* @return ShippingProduct
*/
protected function createResourceObject(): ShippingProduct
{
return new ShippingProduct($this->client);
}
}
2 changes: 2 additions & 0 deletions src/Resources/Parcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ class Parcel extends AbstractResource
public $tracking_url;
/** @var string */
public $country_state;
/** @var int */
public $quantity;
}
27 changes: 27 additions & 0 deletions src/Resources/ShippingProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Imbue\SendCloud\Resources;

class ShippingProduct extends AbstractResource
{
/** @var string */
public $name;

/** @var string */
public $code;

/** @var string */
public $carrier;

/** @var string */
public $service_points_carrier;

/** @var WeightRange */
public $weight_range;

/** @var AvailableShippingFunctionality[] */
public $available_functionalities;

/** @var ShippingProductMethod[] */
public $methods;
}
24 changes: 24 additions & 0 deletions src/Resources/ShippingProductMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Imbue\SendCloud\Resources;

class ShippingProductMethod
{
/** @var int */
public $id;

/** @var string */
public $name;

/** @var AvailableShippingFunctionality */
public $functionalities;

/** @var string */
public $shippingProductCode;

/** @var ShippingProductMethodProperties */
public $properties;

/** @var object */
public $leadTimeHours;
}
16 changes: 16 additions & 0 deletions src/Resources/ShippingProductMethodProperties.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Imbue\SendCloud\Resources;

class ShippingProductMethodProperties
{
/** @var int */
public $min_weight;

/** @var int */
public $max_weight;

/** @var ShippingProductMethodPropertiesMaxDimensions */
public $max_dimensions;
}

18 changes: 18 additions & 0 deletions src/Resources/ShippingProductMethodPropertiesMaxDimensions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Imbue\SendCloud\Resources;

class ShippingProductMethodPropertiesMaxDimensions
{
/** @var int */
public $length;

/** @var int */
public $width;

/** @var int */
public $height;

/** @var string */
public $unit;
}
Loading
Loading