-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab2c031
commit 5e665b6
Showing
16 changed files
with
468 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use GuzzleHttp\Client; | ||
use Laminas\Diactoros\RequestFactory; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use VasilDakov\Econt\Configuration; | ||
use VasilDakov\Econt\Econt; | ||
|
||
chdir(dirname(__DIR__)); | ||
|
||
// Decline static file requests back to the PHP built-in webserver | ||
if (php_sapi_name() === 'cli-server') { | ||
$path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); | ||
if (is_string($path) && __FILE__ !== $path && is_file($path)) { | ||
return false; | ||
} | ||
unset($path); | ||
} | ||
|
||
// Composer autoloading | ||
include __DIR__ . '/../vendor/autoload.php'; | ||
|
||
|
||
$configuration = new Configuration('iasp-dev','1Asp-dev'); | ||
|
||
/** @var ClientInterface $client */ | ||
$client = new Client(); | ||
|
||
/** @var RequestFactoryInterface $factory */ | ||
$factory = new RequestFactory(); | ||
|
||
$econt = new Econt($configuration, $client, $factory); | ||
|
||
dump(json_decode($econt->getClientProfiles())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace VasilDakov\Econt; | ||
|
||
final class Configuration | ||
{ | ||
public function __construct( | ||
public string $username, | ||
public string $password, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace VasilDakov\Econt; | ||
|
||
final class Constants | ||
{ | ||
public const CITY = 'city'; | ||
public const CITY_ID = 'cityID'; | ||
public const ADDRESS = 'address'; | ||
public const DATE = 'date'; | ||
public const COUNTRY_CODE = 'countryCode'; | ||
public const SHIPMENT_TYPE = 'shipmentType'; | ||
public const SERVICE_OFFICE = 'serviceOffice'; | ||
public const SERVICE_OFFICE_LATITUDE = 'serviceOfficeLatitude'; | ||
public const SERVICE_OFFICE_LONGITUDE = 'serviceOfficeLongitude'; | ||
public const SERVICE_OFFICE_CLIENTS_WORK_TIME = 'serviceOfficeClientsWorkTimes'; | ||
public const SERVICE_OFFICE_COURIER_WORK_TIME = 'serviceOfficeCourierWorkTimes'; | ||
public const SERVICE_OFFICE_TIME = 'serviceOfficeTime'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,154 @@ | |
|
||
namespace VasilDakov\Econt; | ||
|
||
use Fig\Http\Message\RequestMethodInterface; | ||
use Psr\Http\Client\ClientExceptionInterface; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
/** | ||
* Class Econt | ||
* | ||
* @author Vasil Dakov <[email protected]> | ||
*/ | ||
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 ''; | ||
} | ||
} |
Oops, something went wrong.