Skip to content

Commit

Permalink
Merge pull request #6 from ensi-platform/psbmarket-1904
Browse files Browse the repository at this point in the history
  • Loading branch information
MsNatali authored Dec 6, 2024
2 parents 7cf357e + e8f7e9a commit 9ac150e
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Api/GeolocationsApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Ensi\DaDataClient\Api;

use Ensi\DaDataClient\DaDataHostEnum;
use Ensi\DaDataClient\Dto\Suggestions\Requests\SearchGeolocationsRequest;
use Ensi\DaDataClient\Dto\Suggestions\Responses\SearchGeolocationsResponse;
use Ensi\DaDataClient\RequestBuilder;
use GuzzleHttp\Promise\PromiseInterface;

class GeolocationsApi extends BaseApi
{
public function searchAddress(SearchGeolocationsRequest $request): SearchGeolocationsResponse
{
return $this->send($this->searchAddressRequest($request), fn ($content) => new SearchGeolocationsResponse($content));
}

public function searchAddressAsync(SearchGeolocationsRequest $request): PromiseInterface
{
return $this->sendAsync($this->searchAddressRequest($request), fn ($content) => new SearchGeolocationsResponse($content));
}

protected function searchAddressRequest(SearchGeolocationsRequest $requestDto): RequestBuilder
{
return (new RequestBuilder('/suggestions/api/4_1/rs/geolocate/address', 'POST'))->json($requestDto);
}

protected function getHostTypeEnum(): string
{
return DaDataHostEnum::SUGGESTIONS;
}
}
1 change: 1 addition & 0 deletions src/DaDataClientProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class DaDataClientProvider
{
public static array $apis = [
'\Ensi\DaDataClient\Api\SuggestionsApi',
'\Ensi\DaDataClient\Api\GeolocationsApi',
];

public static string $configuration = Configuration::class;
Expand Down
30 changes: 30 additions & 0 deletions src/Dto/Suggestions/Requests/SearchGeolocationsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Ensi\DaDataClient\Dto\Suggestions\Requests;

use Ensi\DaDataClient\Dto\BaseBodyDto;
use Webmozart\Assert\Assert;

/**
* @property float $lat - latitude
* @property float $lon - longitude
*
* @property int|null $count - count of results
* @property int|null $radius_meters - search radius in meters
*
* @property string|null $language - response language (see: LanguageEnum)
* @property string|null $division - administrative or municipal division (see: DivisionEnum)
*/
class SearchGeolocationsRequest extends BaseBodyDto
{
public const MAX_COUNT = 20;
public const MAX_RADIUS_METER = 1000;

public function __construct(array $attributes = [])
{
Assert::nullOrRange($attributes['count'] ?? null, 1, self::MAX_COUNT);
Assert::nullOrRange($attributes['radius_meters'] ?? null, 1, self::MAX_RADIUS_METER);

parent::__construct($attributes);
}
}
19 changes: 19 additions & 0 deletions src/Dto/Suggestions/Responses/SearchGeolocationsResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Ensi\DaDataClient\Dto\Suggestions\Responses;

use Ensi\DaDataClient\Dto\BaseResponseDto;
use Ensi\DaDataClient\Dto\Suggestions\Data\SuggestionData;

/**
* @property SuggestionData[] $suggestions
*/
class SearchGeolocationsResponse extends BaseResponseDto
{
public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$this->mapAttributeToArray('suggestions', SuggestionData::class);
}
}

0 comments on commit 9ac150e

Please sign in to comment.