Skip to content

Commit

Permalink
updated client, model and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vasildakov committed Dec 27, 2023
1 parent a8b0f98 commit 5ab65be
Show file tree
Hide file tree
Showing 18 changed files with 413 additions and 51 deletions.
19 changes: 19 additions & 0 deletions data/City.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"id": 603409,
"country": {
"id": null,
"code2": "LU",
"code3": "LUX",
"name": "Люксембург",
"nameEn": "Luxembourg",
"isEU": true
},
"postCode": "0",
"name": "Alscheid",
"nameEn": "Alscheid",
"regionName": "",
"regionNameEn": "",
"phoneCode": "0",
"location": null,
"expressCityDeliveries": false
}
16 changes: 12 additions & 4 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use VasilDakov\Econt\Configuration;
use VasilDakov\Econt\Econt;
use VasilDakov\Econt\Request\GetCitiesRequest;
use VasilDakov\Econt\Request\GetOfficesRequest;
use VasilDakov\Econt\Response\GetCitiesResponseFactory;
use VasilDakov\Econt\Response\GetOfficesResponseFactory;

chdir(dirname(__DIR__));

Expand All @@ -36,9 +38,15 @@

$econt = new Econt($configuration, $client, $factory);


/*
$json = $econt->getCities(new GetCitiesRequest(countryCode: 'BGR'));
$object = (new GetCitiesResponseFactory())($json);

dump($object->findById(39));
dump($object->findByName('Бургас'));
dump($object->findById(41));
dump($object->findByName('София'));
*/

$json = $econt->getOffices(new GetOfficesRequest(countryCode: 'BGR', cityId: '41'));
$object = (new GetOfficesResponseFactory())($json);
foreach ($object->offices as $office) {
dump($office);
}
39 changes: 26 additions & 13 deletions src/Econt.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,29 @@ public function getCities(Request\GetCitiesRequest $object): string
return $response->getBody()->getContents();
}

public function getOffices(array $data): string
/**
* @throws ClientExceptionInterface
*/
public function getOffices(Request\GetOfficesRequest $object): 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'],
]
$object->toArray()
);

$response = $this->client->sendRequest($request);

return $response->getBody()->getContents();
}


public function getStreets(Request\GetStreetsRequest $object): string
{
$request = $this->createRequest(
RequestMethodInterface::METHOD_POST,
self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getStreets.json',
$object->toArray()
);

$response = $this->client->sendRequest($request);
Expand All @@ -92,6 +106,13 @@ public function getOffices(array $data): string
}


public function getQuarters(array $data): string
{
return '';
}



public function getShipmentStatuses(array $data): string
{
$request = $this->createRequest(
Expand Down Expand Up @@ -129,15 +150,7 @@ private function createRequest(string $method, string $uri, array $data): Reques
return $request;
}

public function getStreets(array $data): string
{
return '';
}

public function getQuarters(array $data): string
{
return '';
}

public function createLabel(array $data): string
{
Expand Down
11 changes: 9 additions & 2 deletions src/EcontInterface.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt;

use VasilDakov\Econt\Request;

/**
* EcontInterface
*
* @author Vasil Dakov <[email protected]>
*/
interface EcontInterface
{
public function getClientProfiles(): string;
Expand All @@ -12,9 +19,9 @@ public function getCountries(): string;

public function getCities(Request\GetCitiesRequest $object): string;

public function getOffices(array $data): string;
public function getOffices(Request\GetOfficesRequest $object): string;

public function getStreets(array $data): string;
public function getStreets(Request\GetStreetsRequest $object): string;

public function getQuarters(array $data): string;

Expand Down
46 changes: 46 additions & 0 deletions src/Model/Address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Model;

use JMS\Serializer\Annotation as Serializer;

final readonly class Address
{
public function __construct(
#[Serializer\Type('int')]
public ?int $id = null,

#[Serializer\Type(City::class)]
public ?City $city = null,

#[Serializer\Type('string')]
public ?string $fullAddress = null,

#[Serializer\Type('string')]
public ?string $fullAddressEn = null,

#[Serializer\Type('string')]
public ?string $quarter = null,

#[Serializer\Type('string')]
public ?string $street = null,

#[Serializer\Type('string')]
public ?string $num = null,

#[Serializer\Type('string')]
public ?string $other = null,

#[Serializer\Type(GeoLocation::class)]
public ?GeoLocation $location = null,

#[Serializer\Type('string')]
public ?string $zip = null,

#[Serializer\Type('string')]
public ?string $hezid = null,
) {
}
}
22 changes: 14 additions & 8 deletions src/Model/City.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,35 @@

use JMS\Serializer\Annotation as Serializer;

readonly class City
final readonly class City
{
public function __construct(
#[Serializer\Type('int')]
public ?int $id,
public ?int $id = null,

#[Serializer\Type('string')]
public ?string $name,
public ?string $name = null,

#[Serializer\Type('string')]
public ?string $nameEn,
public ?string $nameEn = null,

#[Serializer\Type('string')]
public ?string $regionName,
public ?string $regionName = null,

#[Serializer\Type('string')]
public ?string $regionNameEn,
public ?string $regionNameEn = null,

#[Serializer\Type('string')]
public ?string $phoneCode,
public ?string $phoneCode = null,

#[Serializer\Type(Country::class)]
public ?Country $country = null,

#[Serializer\Type(GeoLocation::class)]
public ?GeoLocation $location = null,

#[Serializer\Type('string',)]
public ?string $postCode
public ?string $postCode = null
) {
}
}
12 changes: 6 additions & 6 deletions src/Model/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
{
public function __construct(
#[Serializer\Type('int')]
public ?int $id,
public ?int $id = null,

#[Serializer\Type('string')]
public ?string $code2,
public ?string $code2 = null,

#[Serializer\Type('string')]
public ?string $code3,
public ?string $code3 = null,

#[Serializer\Type('string')]
public ?string $name,
public ?string $name = null,

#[Serializer\Type('string')]
public ?string $nameEn,
public ?string $nameEn = null,

#[Serializer\Type('bool')]
public ?bool $isEU
public ?bool $isEU = null
) {
}
}
20 changes: 20 additions & 0 deletions src/Model/GeoLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace VasilDakov\Econt\Model;

use JMS\Serializer\Annotation as Serializer;

readonly class GeoLocation
{
public function __construct(
#[Serializer\Type('float')]
public ?float $latitude = null,

#[Serializer\Type('float')]
public ?float $longitude = null,

#[Serializer\Type('int')]
public ?int $confidence = null,
) {
}
}
36 changes: 34 additions & 2 deletions src/Model/Office.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Model;

class Office
use JMS\Serializer\Annotation as Serializer;

readonly class Office
{
public function __construct(
#[Serializer\Type('int')]
public ?int $id = null,

#[Serializer\Type('string')]
public ?string $code = null,

#[Serializer\Type('string')]
public ?string $name = null,

#[Serializer\Type('string')]
public ?string $nameEn = null,

#[Serializer\Type('bool')]
public ?bool $isMPS = null,

#[Serializer\Type('bool')]
public ?bool $isAPS = null,

#[Serializer\Type('array')]
public ?array $phones = null,

#[Serializer\Type('array')]
public ?array $emails = null,

}
#[Serializer\Type(Address::class)]
public ?Address $address = null,
){
}
}
29 changes: 29 additions & 0 deletions src/Request/GetOfficesRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Request;

use VasilDakov\Econt\Constants;

/**
* EcontInterface
*
* @author Vasil Dakov <[email protected]>
*/
final readonly class GetOfficesRequest
{
public function __construct(
public string $countryCode,
public string $cityId
) {
}

public function toArray(): array
{
return [
Constants::COUNTRY_CODE => $this->countryCode,
Constants::CITY_ID => $this->cityId,
];
}
}
19 changes: 19 additions & 0 deletions src/Request/GetStreetsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace VasilDakov\Econt\Request;

use VasilDakov\Econt\Constants;

final readonly class GetStreetsRequest
{
public function __construct(public string $cityId)
{
}

public function toArray(): array
{
return [
Constants::CITY_ID => $this->cityId
];
}
}
18 changes: 18 additions & 0 deletions src/Response/GetOfficesResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace VasilDakov\Econt\Response;

use Doctrine\Common\Collections\ArrayCollection;
use JMS\Serializer\Annotation as Serializer;
use VasilDakov\Econt\Model;

final class GetOfficesResponse
{
#[Serializer\Type("ArrayCollection<VasilDakov\Econt\Model\Office>")]
public ArrayCollection $offices;

public function __construct()
{
$this->offices = new ArrayCollection();
}
}
Loading

0 comments on commit 5ab65be

Please sign in to comment.