diff --git a/composer.json b/composer.json index 4c2871e..1a46dca 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "prefer-stable": true, "minimum-stability": "dev", "require": { - "php": ">=8.1", + "php": ">=8.2", "psr/http-message": "^2.0", "psr/http-factory": "^1.0", "psr/http-client": "^1.0", @@ -30,14 +30,15 @@ "guzzlehttp/guzzle": "^7.7" }, "require-dev": { - "phpunit/phpunit": "^9.5", + "friendsofphp/php-cs-fixer": "dev-master", "php-coveralls/php-coveralls": "dev-master", + "phpmd/phpmd": "dev-master", + "phpunit/phpunit": "^9.5", + "psalm/plugin-phpunit": "dev-master", "squizlabs/php_codesniffer": "4.0.x-dev", + "symfony/var-dumper": "^7.0", "theseer/phpdox": "dev-master", - "vimeo/psalm": "4.x-dev", - "psalm/plugin-phpunit": "dev-master", - "friendsofphp/php-cs-fixer": "dev-master", - "phpmd/phpmd": "dev-master" + "vimeo/psalm": "4.x-dev" }, "license": "MIT", "autoload": { diff --git a/composer.lock b/composer.lock index 9495c77..c75084f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7b4d769d4a5f2d82e7f4661336d60a51", + "content-hash": "46e18e53f9dec4a61f1c2a9ffd2cb025", "packages": [ { "name": "clue/stream-filter", @@ -5774,6 +5774,89 @@ ], "time": "2023-11-28T20:41:49+00:00" }, + { + "name": "symfony/var-dumper", + "version": "v7.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-dumper.git", + "reference": "cf0220fc7607476fd0d001ab3ed9e830d1fdda56" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/cf0220fc7607476fd0d001ab3ed9e830d1fdda56", + "reference": "cf0220fc7607476fd0d001ab3ed9e830d1fdda56", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/console": "<6.4" + }, + "require-dev": { + "ext-iconv": "*", + "symfony/console": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/process": "^6.4|^7.0", + "symfony/uid": "^6.4|^7.0", + "twig/twig": "^3.0.4" + }, + "bin": [ + "Resources/bin/var-dump-server" + ], + "type": "library", + "autoload": { + "files": [ + "Resources/functions/dump.php" + ], + "psr-4": { + "Symfony\\Component\\VarDumper\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides mechanisms for walking through any arbitrary PHP variable", + "homepage": "https://symfony.com", + "keywords": [ + "debug", + "dump" + ], + "support": { + "source": "https://github.com/symfony/var-dumper/tree/v7.0.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-11-27T12:39:18+00:00" + }, { "name": "symfony/var-exporter", "version": "v6.4.1", @@ -6342,18 +6425,18 @@ "aliases": [], "minimum-stability": "dev", "stability-flags": { + "friendsofphp/php-cs-fixer": 20, "php-coveralls/php-coveralls": 20, + "phpmd/phpmd": 20, + "psalm/plugin-phpunit": 20, "squizlabs/php_codesniffer": 20, "theseer/phpdox": 20, - "vimeo/psalm": 20, - "psalm/plugin-phpunit": 20, - "friendsofphp/php-cs-fixer": 20, - "phpmd/phpmd": 20 + "vimeo/psalm": 20 }, "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": ">=8.1" + "php": ">=8.2" }, "platform-dev": [], "platform-overrides": { diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..fe2867d --- /dev/null +++ b/public/index.php @@ -0,0 +1,35 @@ +getClientProfiles())); \ No newline at end of file diff --git a/src/Configuration.php b/src/Configuration.php new file mode 100644 index 0000000..d522323 --- /dev/null +++ b/src/Configuration.php @@ -0,0 +1,12 @@ + */ -final class Econt +final class Econt implements EcontInterface { - public function __construct() + public const API_URL = 'https://demo.econt.com'; + + public function __construct( + private readonly Configuration $configuration, + private readonly ClientInterface $client, + private readonly RequestFactoryInterface $factory + ) { + } + + /** + * @throws ClientExceptionInterface + */ + public function getClientProfiles(): string + { + $request = $this->createRequest( + RequestMethodInterface::METHOD_POST, + self::API_URL . '/ee/services/Profile/ProfileService.getClientProfiles.json', + [] + ); + + $response = $this->client->sendRequest($request); + + return $response->getBody()->getContents(); + } + + /** + * @throws ClientExceptionInterface + */ + public function getCountries(): string + { + $request = $this->createRequest( + RequestMethodInterface::METHOD_POST, + self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getCountries.json', + [] + ); + + $response = $this->client->sendRequest($request); + + return $response->getBody()->getContents(); + } + + /** + * @throws ClientExceptionInterface + */ + public function getCities(array $data): string + { + $request = $this->createRequest( + RequestMethodInterface::METHOD_POST, + self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getCities.json', + [ + Constants::COUNTRY_CODE => $data['countryCode'] + ] + ); + + $response = $this->client->sendRequest($request); + + return $response->getBody()->getContents(); + } + + public function getOffices(array $data): string + { + $request = $this->createRequest( + RequestMethodInterface::METHOD_POST, + self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getOffices.json', + [ + Constants::COUNTRY_CODE => $data['countryCode'], + Constants::CITY_ID => $data['cityId'], + ] + ); + + $response = $this->client->sendRequest($request); + + return $response->getBody()->getContents(); + } + + + public function getShipmentStatuses(array $data): string + { + $request = $this->createRequest( + RequestMethodInterface::METHOD_POST, + self::API_URL . '/ee/services/Shipments/ShipmentService.getShipmentStatuses.json', + $data + ); + + $response = $this->client->sendRequest($request); + + return $response->getBody()->getContents(); + } + + + /** + * @param string $method + * @param string $uri + * @param array $data + * @return RequestInterface + */ + private function createRequest(string $method, string $uri, array $data): RequestInterface + { + $request = $this->factory->createRequest($method, $uri); + + $request = $request->withAddedHeader('Content-Type', 'application/json'); + $request = $request->withAddedHeader( + 'Authorization', + 'Basic ' . base64_encode( + $this->configuration->username . ":" . $this->configuration->password + ) + ); + + $request->getBody()->write(json_encode($data)); + + return $request; + } + + public function getStreets(array $data): string + { + return ''; + } + + public function getQuarters(array $data): string + { + return ''; + } + + public function createLabel(array $data): string + { + return ''; + } + + public function createLabels(array $data): string + { + return ''; + } + + public function deleteLabels(array $data): string { + return ''; } } diff --git a/src/EcontInterface.php b/src/EcontInterface.php new file mode 100644 index 0000000..b88cee6 --- /dev/null +++ b/src/EcontInterface.php @@ -0,0 +1,27 @@ + $default) { + if (!array_key_exists($property, $data)) continue; + $obj->{$property} = $data[$property]; // assign value to object + } + return $obj; + } } diff --git a/src/Model/Office.php b/src/Model/Office.php new file mode 100644 index 0000000..d090ab3 --- /dev/null +++ b/src/Model/Office.php @@ -0,0 +1,8 @@ +getData()); + + self::assertInstanceOf(City::class, $city); + } + + /** + * @test + */ + public function itCanBeCreatedFromEmptyArray(): void + { + $city = City::fromArray([]); + + self::assertInstanceOf(City::class, $city); + } + + + /** + * @test + */ + public function itCanBeConvertedToArray(): void + { + $city = City::fromArray([]); + $array = $city->toArray(); + + self::assertIsArray($array); + self::assertArrayHasKey('id', $array); + self::assertArrayHasKey('name', $array); + self::assertArrayHasKey('postCode', $array); + } + + + private function getData(): array + { + return [ + "id" => 204964, + "name" => "Sofia", + "postCode" => "1000", + ]; + } +} \ No newline at end of file diff --git a/test/Model/CountryTest.php b/test/Model/CountryTest.php index 1c7740d..4a7b971 100644 --- a/test/Model/CountryTest.php +++ b/test/Model/CountryTest.php @@ -1,11 +1,13 @@