diff --git a/src/SuggestOrganizationClient.php b/src/SuggestOrganizationClient.php index ebff54e..91a651e 100644 --- a/src/SuggestOrganizationClient.php +++ b/src/SuggestOrganizationClient.php @@ -24,4 +24,14 @@ interface SuggestOrganizationClient * @throws ClientException */ public function findByInn(string $inn, int $count = 1): array; + + /** + * @param non-empty-string $name + * @param int<1, 20> $count + * + * @return array + * + * @throws ClientException + */ + public function findByName(string $name, int $count = 1): array; } diff --git a/src/Transport/RestSuggestOrganizationClient.php b/src/Transport/RestSuggestOrganizationClient.php index 3232c50..251859e 100644 --- a/src/Transport/RestSuggestOrganizationClient.php +++ b/src/Transport/RestSuggestOrganizationClient.php @@ -49,4 +49,23 @@ public function findByInn(string $inn, int $count = 1): array return $value; } + + public function findByName(string $name, int $count = 1): array + { + $request = new Request( + Method::POST, + '/suggestions/api/4_1/rs/suggest/party', + [], + $this->serializer->serialize(['query' => $name, 'count' => $count], 'json') + ); + + $content = $this->client->sendRequest($request)->getBody()->__toString(); + + /** @var list $value */ + $value = $this->serializer->deserialize($content, SuggestOrganization::class . '[]', 'json', [ + UnwrappingDenormalizer::UNWRAP_PATH => '[suggestions]', + ]); + + return $value; + } }