-
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.
Merge pull request #6 from ensi-platform/psbmarket-1904
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 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
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; | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
src/Dto/Suggestions/Requests/SearchGeolocationsRequest.php
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,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
19
src/Dto/Suggestions/Responses/SearchGeolocationsResponse.php
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 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); | ||
} | ||
} |