Skip to content

Commit

Permalink
Setting service
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-novotny committed Jul 21, 2022
1 parent 811f731 commit d4730a5
Show file tree
Hide file tree
Showing 62 changed files with 1,258 additions and 316 deletions.
6 changes: 3 additions & 3 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Inspirum\Balikobot\Client;

use Inspirum\Balikobot\Client\Request\CarrierType;
use Inspirum\Balikobot\Client\Request\Carrier;
use Inspirum\Balikobot\Client\Request\Method;
use Inspirum\Balikobot\Client\Request\Version;

Expand All @@ -21,10 +21,10 @@ interface Client
*/
public function call(
Version $version,
?CarrierType $carrier,
?Carrier $carrier,
Method $request,
array $data = [],
string $path = '',
?string $path = null,
bool $shouldHaveStatus = true,
bool $gzip = false,
): array;
Expand Down
10 changes: 5 additions & 5 deletions src/Client/DefaultClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Inspirum\Balikobot\Client;

use GuzzleHttp\Psr7\InflateStream;
use Inspirum\Balikobot\Client\Request\CarrierType;
use Inspirum\Balikobot\Client\Request\Carrier;
use Inspirum\Balikobot\Client\Request\Method;
use Inspirum\Balikobot\Client\Request\Version;
use Inspirum\Balikobot\Client\Response\Validator;
Expand All @@ -30,10 +30,10 @@ public function __construct(
/** @inheritDoc */
public function call(
Version $version,
?CarrierType $carrier,
?Carrier $carrier,
Method $request,
array $data = [],
string $path = '',
?string $path = null,
bool $shouldHaveStatus = true,
bool $gzip = false,
): array {
Expand All @@ -50,9 +50,9 @@ public function call(
return $parsedContent;
}

private function resolveUrl(string $version, ?string $carrier, string $request, string $path, bool $gzip): string
private function resolveUrl(string $version, ?string $carrier, string $request, ?string $path, bool $gzip): string
{
$url = sprintf('%s/%s/%s', $carrier, $request, $path);
$url = sprintf('%s/%s/%s', $carrier, $request, $path ?? '');
$url = trim(str_replace('//', '/', $url), '/');

if ($gzip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Inspirum\Balikobot\Client\Request;

interface CarrierType
interface Carrier
{
public function getValue(): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Stringable;

interface ServiceType extends Stringable
interface Service extends Stringable
{
public function getValue(): string;
}
10 changes: 5 additions & 5 deletions src/Definitions/Carrier.php → src/Definitions/CarrierType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Inspirum\Balikobot\Definitions;

use Inspirum\Balikobot\Client\Request\CarrierType;
use Inspirum\Balikobot\Client\Request\ServiceType;
use Inspirum\Balikobot\Client\Request\Carrier;
use Inspirum\Balikobot\Client\Request\Service;

enum Carrier: string implements CarrierType
enum CarrierType: string implements Carrier
{
case CP = 'cp';
case DPD = 'dpd';
Expand Down Expand Up @@ -48,13 +48,13 @@ public function getValue(): string
return $this->value;
}

public static function hasBranchCountryFilterSupport(CarrierType $carrier, ?ServiceType $service): bool
public static function hasBranchCountryFilterSupport(Carrier $carrier, ?Service $service): bool
{
// TODO:
return false;
}

public static function hasFullBranchesSupport(CarrierType $carrier, ?ServiceType $service): bool
public static function hasFullBranchesSupport(Carrier $carrier, ?Service $service): bool
{
// TODO:
return false;
Expand Down
64 changes: 32 additions & 32 deletions src/Definitions/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@

enum Request: string implements Method
{
case TRACK = 'track';
case TRACK_STATUS = 'trackstatus';
case BRANCHES = 'branches';
case FULL_BRANCHES = 'fullbranches';
case BRANCH_LOCATOR = 'branchlocator';
case ADD = 'add';
case DROP = 'drop';
case OVERVIEW = 'overview';
case LABELS = 'labels';
case PACKAGE = 'package';
case ORDER = 'order';
case ORDER_VIEW = 'orderview';
case ORDER_PICKUP = 'orderpickup';
case CHECK = 'check';
case PROOF_OF_DELIVERY = 'pod';
case TRANSPORT_COSTS = 'transportcosts';
case ADD_SERVICE_OPTIONS = 'addserviceoptions';
case ADD_ATTRIBUTES = 'addattributes';
case B2A = 'b2a';
case B2A_SERVICES = 'b2a/services';
case INFO_WHO_AM_I = 'info/whoami';
case INFO_CARRIERS = 'info/carriers';
case CHANGELOG = 'changelog';
case SERVICES = 'services';
case ACTIVATED_SERVICES = 'activatedservices';
case GET_COUNTRIES_DATA = 'getCountriesData';
case MANIPULATION_UNITS = 'manipulationunits';
case TRACK = 'track';
case TRACK_STATUS = 'trackstatus';
case BRANCHES = 'branches';
case FULL_BRANCHES = 'fullbranches';
case BRANCH_LOCATOR = 'branchlocator';
case ADD = 'add';
case DROP = 'drop';
case OVERVIEW = 'overview';
case LABELS = 'labels';
case PACKAGE = 'package';
case ORDER = 'order';
case ORDER_VIEW = 'orderview';
case ORDER_PICKUP = 'orderpickup';
case CHECK = 'check';
case PROOF_OF_DELIVERY = 'pod';
case TRANSPORT_COSTS = 'transportcosts';
case ADD_SERVICE_OPTIONS = 'addserviceoptions';
case ADD_ATTRIBUTES = 'addattributes';
case B2A = 'b2a';
case B2A_SERVICES = 'b2a/services';
case INFO_WHO_AM_I = 'info/whoami';
case INFO_CARRIERS = 'info/carriers';
case CHANGELOG = 'changelog';
case SERVICES = 'services';
case ACTIVATED_SERVICES = 'activatedservices';
case GET_COUNTRIES_DATA = 'getCountriesData';
case MANIPULATION_UNITS = 'manipulationunits';
case ACTIVATED_MANIPULATION_UNITS = 'activatedmanipulationunits';
case CASH_ON_DELIVERY_COUNTRIES = 'cod4services';
case COUNTRIES = 'countries4service';
case ZIP_CODES = 'zipcodes';
case ADR_UNITS = 'adrunits';
case FULL_ADR_UNITS = 'fulladrunits';
case CASH_ON_DELIVERY_COUNTRIES = 'cod4services';
case COUNTRIES = 'countries4service';
case ZIP_CODES = 'zipcodes';
case ADR_UNITS = 'adrunits';
case FULL_ADR_UNITS = 'fulladrunits';

public function getValue(): string
{
Expand Down
66 changes: 33 additions & 33 deletions src/Definitions/ServiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3146,39 +3146,39 @@ public static function magyarposta(): array
public static function all(): array
{
return [
Carrier::CP->value => self::cp(),
Carrier::DPD->value => self::dpd(),
Carrier::DHL->value => self::dhl(),
Carrier::GEIS->value => self::geis(),
Carrier::GLS->value => self::gls(),
Carrier::INTIME->value => self::intime(),
Carrier::PBH->value => self::pbh(),
Carrier::PPL->value => self::ppl(),
Carrier::SP->value => self::sp(),
Carrier::SPS->value => self::sps(),
Carrier::TOPTRANS->value => self::topTrans(),
Carrier::ULOZENKA->value => self::ulozenka(),
Carrier::UPS->value => self::ups(),
Carrier::ZASILKOVNA->value => self::zasilkovna(),
Carrier::TNT->value => self::tnt(),
Carrier::GW->value => self::gw(),
Carrier::GWCZ->value => self::gwcz(),
Carrier::MESSENGER->value => self::messenger(),
Carrier::DHLDE->value => self::dhlde(),
Carrier::FEDEX->value => self::fedex(),
Carrier::FOFR->value => self::fofr(),
Carrier::DACHSER->value => self::dachser(),
Carrier::DHLPARCEL->value => self::dhlparcel(),
Carrier::RABEN->value => self::raben(),
Carrier::SPRING->value => self::spring(),
Carrier::DSV->value => self::dsv(),
Carrier::DHLFREIGHTEC->value => self::dhlfreightec(),
Carrier::KURIER->value => self::kurier(),
Carrier::DBSCHENKER->value => self::dbschenker(),
Carrier::AIRWAY->value => self::airway(),
Carrier::JAPO->value => self::japo(),
Carrier::LIFTAGO->value => self::liftago(),
Carrier::MAGYARPOSTA->value => self::magyarposta(),
CarrierType::CP->value => self::cp(),
CarrierType::DPD->value => self::dpd(),
CarrierType::DHL->value => self::dhl(),
CarrierType::GEIS->value => self::geis(),
CarrierType::GLS->value => self::gls(),
CarrierType::INTIME->value => self::intime(),
CarrierType::PBH->value => self::pbh(),
CarrierType::PPL->value => self::ppl(),
CarrierType::SP->value => self::sp(),
CarrierType::SPS->value => self::sps(),
CarrierType::TOPTRANS->value => self::topTrans(),
CarrierType::ULOZENKA->value => self::ulozenka(),
CarrierType::UPS->value => self::ups(),
CarrierType::ZASILKOVNA->value => self::zasilkovna(),
CarrierType::TNT->value => self::tnt(),
CarrierType::GW->value => self::gw(),
CarrierType::GWCZ->value => self::gwcz(),
CarrierType::MESSENGER->value => self::messenger(),
CarrierType::DHLDE->value => self::dhlde(),
CarrierType::FEDEX->value => self::fedex(),
CarrierType::FOFR->value => self::fofr(),
CarrierType::DACHSER->value => self::dachser(),
CarrierType::DHLPARCEL->value => self::dhlparcel(),
CarrierType::RABEN->value => self::raben(),
CarrierType::SPRING->value => self::spring(),
CarrierType::DSV->value => self::dsv(),
CarrierType::DHLFREIGHTEC->value => self::dhlfreightec(),
CarrierType::KURIER->value => self::kurier(),
CarrierType::DBSCHENKER->value => self::dbschenker(),
CarrierType::AIRWAY->value => self::airway(),
CarrierType::JAPO->value => self::japo(),
CarrierType::LIFTAGO->value => self::liftago(),
CarrierType::MAGYARPOSTA->value => self::magyarposta(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Inspirum\Balikobot\Definitions;

enum Version: string implements \Inspirum\Balikobot\Client\Request\Version
use Inspirum\Balikobot\Client\Request\Version;

enum VersionType: string implements Version
{
case V1V1 = 'https://api.balikobot.cz';
case V1V2 = 'https://api.balikobot.cz/v2';
Expand Down
4 changes: 2 additions & 2 deletions src/Model/AdrUnit/AdrUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace Inspirum\Balikobot\Model\AdrUnit;

use Inspirum\Arrayable\BaseModel;
use Inspirum\Balikobot\Client\Request\CarrierType;
use Inspirum\Balikobot\Client\Request\Carrier;

/**
* @extends \Inspirum\Arrayable\BaseModel<string,mixed>
*/
class AdrUnit extends BaseModel
{
public function __construct(
public readonly CarrierType $carrier,
public readonly Carrier $carrier,
public readonly string $id,
public readonly string $code,
public readonly string $name,
Expand Down
15 changes: 15 additions & 0 deletions src/Model/AdrUnit/AdrUnitCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@
namespace Inspirum\Balikobot\Model\AdrUnit;

use Inspirum\Arrayable\BaseCollection;
use Inspirum\Balikobot\Client\Request\Carrier;

/**
* @extends \Inspirum\Arrayable\BaseCollection<string,mixed,int,\Inspirum\Balikobot\Model\AdrUnit\AdrUnit>
*/
final class AdrUnitCollection extends BaseCollection
{
/**
* @param array<int,\Inspirum\Balikobot\Model\AdrUnit\AdrUnit> $items
*/
public function __construct(
private Carrier $carrier,
array $items = [],
) {
parent::__construct($items);
}

public function getCarrier(): Carrier
{
return $this->carrier;
}
}
6 changes: 3 additions & 3 deletions src/Model/AdrUnit/AdrUnitFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace Inspirum\Balikobot\Model\AdrUnit;

use Inspirum\Balikobot\Client\Request\CarrierType;
use Inspirum\Balikobot\Client\Request\Carrier;

interface AdrUnitFactory
{
/**
* @param array<string,mixed> $data
*/
public function create(CarrierType $carrier, array $data): AdrUnit;
public function create(Carrier $carrier, array $data): AdrUnit;

/**
* @param array<string,mixed> $data
*/
public function createCollection(CarrierType $carrier, array $data): AdrUnitCollection;
public function createCollection(Carrier $carrier, array $data): AdrUnitCollection;
}
7 changes: 4 additions & 3 deletions src/Model/AdrUnit/DefaultAdrUnitFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Inspirum\Balikobot\Model\AdrUnit;

use Inspirum\Balikobot\Client\Request\CarrierType;
use Inspirum\Balikobot\Client\Request\Carrier;
use function array_map;

final class DefaultAdrUnitFactory implements AdrUnitFactory
{
/** @inheritDoc */
public function create(CarrierType $carrier, array $data): AdrUnit
public function create(Carrier $carrier, array $data): AdrUnit
{
return new AdrUnit(
$carrier,
Expand All @@ -25,9 +25,10 @@ public function create(CarrierType $carrier, array $data): AdrUnit
}

/** @inheritDoc */
public function createCollection(CarrierType $carrier, array $data): AdrUnitCollection
public function createCollection(Carrier $carrier, array $data): AdrUnitCollection
{
return new AdrUnitCollection(
$carrier,
array_map(fn(array $unit): AdrUnit => $this->create($carrier, $unit), $data['units'] ?? []),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Attribute/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class Attribute extends BaseModel
public function __construct(
public readonly string $name,
public readonly string $dataType,
public readonly string $maxLength,
public readonly ?string $maxLength,
) {
}

Expand Down
15 changes: 15 additions & 0 deletions src/Model/Attribute/AttributeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@
namespace Inspirum\Balikobot\Model\Attribute;

use Inspirum\Arrayable\BaseCollection;
use Inspirum\Balikobot\Client\Request\Carrier;

/**
* @extends \Inspirum\Arrayable\BaseCollection<string,mixed,int,\Inspirum\Balikobot\Model\Attribute\Attribute>
*/
final class AttributeCollection extends BaseCollection
{
/**
* @param array<int,\Inspirum\Balikobot\Model\Attribute\Attribute> $items
*/
public function __construct(
private Carrier $carrier,
array $items = [],
) {
parent::__construct($items);
}

public function getCarrier(): Carrier
{
return $this->carrier;
}
}
Loading

0 comments on commit d4730a5

Please sign in to comment.