1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Promopult\Dadata\Services; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Suggestions |
9
|
|
|
*/ |
10
|
|
|
final class Suggestions extends \Promopult\Dadata\Service |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Организация по ИНН или ОГРН |
14
|
|
|
* |
15
|
|
|
* @param string $query |
16
|
|
|
* @return array |
17
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
18
|
|
|
* |
19
|
|
|
* @see https://dadata.ru/api/find-party/ |
20
|
|
|
*/ |
21
|
|
|
public function partyFindById(string $query): array |
22
|
|
|
{ |
23
|
|
|
$request = $this->requestFactory->createRequest( |
24
|
|
|
'POST', |
25
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/party', |
26
|
|
|
['query' => $query] |
27
|
|
|
); |
28
|
|
|
|
29
|
|
|
$response = $this->httpClient->sendRequest($request); |
30
|
|
|
|
31
|
|
|
return \json_decode($response->getBody()->getContents(), true); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Поиск аффилированных компаний |
36
|
|
|
* |
37
|
|
|
* @param string $query |
38
|
|
|
* @return array |
39
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
40
|
|
|
* |
41
|
|
|
* @see https://dadata.ru/api/find-affiliated/ |
42
|
|
|
*/ |
43
|
|
|
public function partyFindAffiliated(string $query): array |
44
|
|
|
{ |
45
|
|
|
$request = $this->requestFactory->createRequest( |
46
|
|
|
'POST', |
47
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findAffiliated/party', |
48
|
|
|
['query' => $query] |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$response = $this->httpClient->sendRequest($request); |
52
|
|
|
|
53
|
|
|
return \json_decode($response->getBody()->getContents(), true); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* API подсказок по организациям |
58
|
|
|
* |
59
|
|
|
* @param string $query ИНН или ОГРН |
60
|
|
|
* @return array |
61
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
62
|
|
|
* |
63
|
|
|
* @see https://dadata.ru/api/suggest/party/ |
64
|
|
|
*/ |
65
|
|
|
public function partySuggest(string $query): array |
66
|
|
|
{ |
67
|
|
|
return $this->suggest( |
68
|
|
|
['query' => $query], |
69
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/party' |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* API подсказок по банкам |
75
|
|
|
* |
76
|
|
|
* @param string $query |
77
|
|
|
* @param int|null $count Количество результатов (максимум — 20) |
78
|
|
|
* @param array|null $locationsBoost Приоритет города при ранжировании ([..["kladr_id":"6100000100000"], ...]) |
79
|
|
|
* @param array|null $locations Ограничение по региону или городу ([..["kladr_id":"6100000100000"], ...]) |
80
|
|
|
* @param string|null $status Ограничение по статусу банка (ACTIVE | LIQUIDATING | LIQUIDATED) |
81
|
|
|
* @param string|null $type Ограничение по типу банка (BANK | NKO | BANK_BRANCH | NKO_BRANCH | RKC | OTHER) |
82
|
|
|
* @return array |
83
|
|
|
* |
84
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
85
|
|
|
* |
86
|
|
|
* @see https://dadata.ru/api/suggest/bank/ |
87
|
|
|
*/ |
88
|
|
|
public function bankSuggest( |
89
|
|
|
string $query, |
90
|
|
|
?int $count = null, |
91
|
|
|
?array $locationsBoost = null, |
92
|
|
|
?array $locations = null, |
93
|
|
|
?string $status = null, |
94
|
|
|
?string $type = null |
95
|
|
|
): array { |
96
|
|
|
return $this->suggest( |
97
|
|
|
array_filter([ |
98
|
|
|
'query' => $query, |
99
|
|
|
'count' => $count, |
100
|
|
|
'status' => $status, |
101
|
|
|
'type' => $type, |
102
|
|
|
'locations' => $locations, |
103
|
|
|
'locations_boost' => $locationsBoost, |
104
|
|
|
]), |
105
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/bank' |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Банк по БИК, SWIFT, ИНН или регистрационному номеру |
111
|
|
|
* |
112
|
|
|
* @param string $query |
113
|
|
|
* @param string|null $kpp |
114
|
|
|
* @return array |
115
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
116
|
|
|
* |
117
|
|
|
* @see https://dadata.ru/api/find-bank/ |
118
|
|
|
*/ |
119
|
|
|
public function bankFindById(string $query, string $kpp = null): array |
120
|
|
|
{ |
121
|
|
|
return $this->suggest(array_filter([ |
122
|
|
|
'query' => $query, |
123
|
|
|
'kpp' => $kpp |
124
|
|
|
]), 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/bank'); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Обратное геокодирование (адрес по координатам) |
129
|
|
|
* |
130
|
|
|
* @param string $lat |
131
|
|
|
* @param string $lon |
132
|
|
|
* @param int|null $count |
133
|
|
|
* @param int|null $radiusMeters |
134
|
|
|
* @param string|null $language |
135
|
|
|
* @return array |
136
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
137
|
|
|
* |
138
|
|
|
* @see https://dadata.ru/api/geolocate/ |
139
|
|
|
*/ |
140
|
|
|
public function addressGeolocate( |
141
|
|
|
string $lat, |
142
|
|
|
string $lon, |
143
|
|
|
?int $count = null, |
144
|
|
|
?int $radiusMeters = null, |
145
|
|
|
?string $language = null |
146
|
|
|
): array { |
147
|
|
|
return $this->suggest( |
148
|
|
|
array_filter([ |
149
|
|
|
'lat' => $lat, |
150
|
|
|
'lon' => $lon, |
151
|
|
|
'count' => $count, |
152
|
|
|
'radius_meters' => $radiusMeters, |
153
|
|
|
'language' => $language |
154
|
|
|
]), |
155
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/geolocate/address' |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Адрес по коду КЛАДР или ФИАС |
161
|
|
|
* |
162
|
|
|
* @param string $query |
163
|
|
|
* @param int|null $count |
164
|
|
|
* @param string|null $language |
165
|
|
|
* @param array|null $filters |
166
|
|
|
* @return array |
167
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
168
|
|
|
* |
169
|
|
|
* @see https://dadata.ru/api/find-address/ |
170
|
|
|
*/ |
171
|
|
|
public function addressFindById( |
172
|
|
|
string $query, |
173
|
|
|
?int $count = null, |
174
|
|
|
?string $language = null, |
175
|
|
|
?array $filters = null |
176
|
|
|
): array { |
177
|
|
|
return $this->suggest( |
178
|
|
|
array_filter([ |
179
|
|
|
'query' => $query, |
180
|
|
|
'count' => $count, |
181
|
|
|
'language' => $language, |
182
|
|
|
'filters' => $filters, |
183
|
|
|
]), |
184
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/address' |
185
|
|
|
); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* API подсказок по адресам |
190
|
|
|
* |
191
|
|
|
* @param string $query |
192
|
|
|
* @param int|null $count |
193
|
|
|
* @param string|null $language |
194
|
|
|
* @param array|null $locations |
195
|
|
|
* @param array|null $locationsBoost |
196
|
|
|
* @param string|null $fromBound |
197
|
|
|
* @param string|null $toBound |
198
|
|
|
* @return array |
199
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
200
|
|
|
* |
201
|
|
|
* @see https://dadata.ru/api/suggest/address/ |
202
|
|
|
*/ |
203
|
|
|
public function addressSuggest( |
204
|
|
|
string $query, |
205
|
|
|
?int $count = null, |
206
|
|
|
?string $language = null, |
207
|
|
|
?array $locations = null, |
208
|
|
|
?array $locationsBoost = null, |
209
|
|
|
?string $fromBound = null, |
210
|
|
|
?string $toBound = null |
211
|
|
|
): array { |
212
|
|
|
|
213
|
|
|
$fromBound = $fromBound ?: ['value' => $fromBound]; |
214
|
|
|
$toBound = $toBound ?: ['value' => $toBound]; |
215
|
|
|
|
216
|
|
|
return $this->suggest( |
217
|
|
|
array_filter([ |
218
|
|
|
'query' => $query, |
219
|
|
|
'count' => $count, |
220
|
|
|
'language' => $language, |
221
|
|
|
'locations' => $locations, |
222
|
|
|
'locations_boost' => $locationsBoost, |
223
|
|
|
'from_bound' => $fromBound, |
224
|
|
|
'to_bound' => $toBound |
225
|
|
|
]), |
226
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/address' |
227
|
|
|
); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Отделения Почты России по геолокации |
232
|
|
|
* |
233
|
|
|
* @param string $lat |
234
|
|
|
* @param string $lon |
235
|
|
|
* @param int|null $count |
236
|
|
|
* @param int|null $radiusMeters |
237
|
|
|
* @param array|null $filters |
238
|
|
|
* @return array |
239
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
240
|
|
|
* |
241
|
|
|
* @see https://dadata.ru/api/suggest/postal_unit/ |
242
|
|
|
*/ |
243
|
|
|
public function postalUnitGeolocate( |
244
|
|
|
string $lat, |
245
|
|
|
string $lon, |
246
|
|
|
?int $count = null, |
247
|
|
|
?int $radiusMeters = null, |
248
|
|
|
?array $filters = null |
249
|
|
|
): array { |
250
|
|
|
return $this->suggest( |
251
|
|
|
array_filter([ |
252
|
|
|
'lat' => $lat, |
253
|
|
|
'lon' => $lon, |
254
|
|
|
'count' => $count, |
255
|
|
|
'radius_meters' => $radiusMeters, |
256
|
|
|
'filters' => $filters, |
257
|
|
|
]), |
258
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/geolocate/postal_unit' |
259
|
|
|
); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Отделения Почты России по адресу и индексу |
264
|
|
|
* |
265
|
|
|
* @param string $query |
266
|
|
|
* @param int|null $count |
267
|
|
|
* @param array|null $filters |
268
|
|
|
* @return array |
269
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
270
|
|
|
* |
271
|
|
|
* @see https://dadata.ru/api/suggest/postal_unit/ |
272
|
|
|
*/ |
273
|
|
|
public function postalUnitSuggest( |
274
|
|
|
string $query, |
275
|
|
|
?int $count = null, |
276
|
|
|
?array $filters = null |
277
|
|
|
): array { |
278
|
|
|
return $this->suggest( |
279
|
|
|
array_filter([ |
280
|
|
|
'query' => $query, |
281
|
|
|
'count' => $count, |
282
|
|
|
'filters' => $filters |
283
|
|
|
]), |
284
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/postal_unit' |
285
|
|
|
); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Город по IP-адресу |
290
|
|
|
* |
291
|
|
|
* @param string $query |
292
|
|
|
* @param int|null $count |
293
|
|
|
* @param string|null $language |
294
|
|
|
* @return array |
295
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
296
|
|
|
* |
297
|
|
|
* @see https://dadata.ru/api/iplocate/ |
298
|
|
|
*/ |
299
|
|
|
public function cityIplocate( |
300
|
|
|
string $query, |
301
|
|
|
?int $count = null, |
302
|
|
|
?string $language = null |
303
|
|
|
): array { |
304
|
|
|
return $this->suggest( |
305
|
|
|
array_filter([ |
306
|
|
|
'query' => $query, |
307
|
|
|
'count' => $count, |
308
|
|
|
'language' => $language |
309
|
|
|
]), |
310
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/iplocate/address' |
311
|
|
|
); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Идентификатор города в СДЭК, Boxberry и DPD |
316
|
|
|
* |
317
|
|
|
* @param string $query |
318
|
|
|
* @return array |
319
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
320
|
|
|
* |
321
|
|
|
* @see https://dadata.ru/api/delivery/ |
322
|
|
|
*/ |
323
|
|
|
public function deliveryFindById( |
324
|
|
|
string $query |
325
|
|
|
): array { |
326
|
|
|
return $this->suggest([ |
327
|
|
|
'query' => $query |
328
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/delivery'); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* API подсказок по ФИАС |
333
|
|
|
* |
334
|
|
|
* @param string $query |
335
|
|
|
* @param int|null $count |
336
|
|
|
* @param array|null $locations |
337
|
|
|
* @param array|null $locationsBoost |
338
|
|
|
* @param string|null $fromBound |
339
|
|
|
* @param string|null $toBound |
340
|
|
|
* @return array |
341
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
342
|
|
|
* |
343
|
|
|
* @see https://dadata.ru/api/suggest/fias/ |
344
|
|
|
*/ |
345
|
|
|
public function fiasSuggest( |
346
|
|
|
string $query, |
347
|
|
|
?int $count = null, |
348
|
|
|
?array $locations = null, |
349
|
|
|
?array $locationsBoost = null, |
350
|
|
|
?string $fromBound = null, |
351
|
|
|
?string $toBound = null |
352
|
|
|
): array { |
353
|
|
|
$fromBound = $fromBound ?: ['value' => $fromBound]; |
354
|
|
|
$toBound = $toBound ?: ['value' => $toBound]; |
355
|
|
|
|
356
|
|
|
return $this->suggest( |
357
|
|
|
array_filter([ |
358
|
|
|
'query' => $query, |
359
|
|
|
'count' => $count, |
360
|
|
|
'locations' => $locations, |
361
|
|
|
'locations_boost' => $locationsBoost, |
362
|
|
|
'from_bound' => $fromBound, |
363
|
|
|
'to_bound' => $toBound |
364
|
|
|
]), |
365
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/fias' |
366
|
|
|
); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* API справочников: кем выдан паспорт |
371
|
|
|
* |
372
|
|
|
* @param string $query |
373
|
|
|
* @param array|null $filters |
374
|
|
|
* @return array |
375
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
376
|
|
|
* |
377
|
|
|
* @see https://dadata.ru/api/suggest/fms_unit/ |
378
|
|
|
*/ |
379
|
|
|
public function fmsUnitSuggest( |
380
|
|
|
string $query, |
381
|
|
|
?array $filters = [] |
382
|
|
|
): array { |
383
|
|
|
return $this->suggest( |
384
|
|
|
array_filter([ |
385
|
|
|
'query' => $query, |
386
|
|
|
'filters' => $filters |
387
|
|
|
]), |
388
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/fms_unit' |
389
|
|
|
); |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* API справочников: марки автомобилей |
394
|
|
|
* |
395
|
|
|
* @param string $query |
396
|
|
|
* @return array |
397
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
398
|
|
|
* |
399
|
|
|
* @see https://dadata.ru/api/suggest/car_brand/ |
400
|
|
|
*/ |
401
|
|
|
public function carBrandSuggest( |
402
|
|
|
string $query |
403
|
|
|
): array { |
404
|
|
|
return $this->suggest( |
405
|
|
|
[ |
406
|
|
|
'query' => $query |
407
|
|
|
], |
408
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/car_brand' |
409
|
|
|
); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* API справочников: марки автомобилей |
414
|
|
|
* |
415
|
|
|
* @param string $query |
416
|
|
|
* @return array |
417
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
418
|
|
|
* |
419
|
|
|
* @see https://dadata.ru/api/suggest/car_brand/ |
420
|
|
|
*/ |
421
|
|
|
public function carBrandFindById(string $query): array |
422
|
|
|
{ |
423
|
|
|
return $this->suggest([ |
424
|
|
|
'query' => $query |
425
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/car_brand'); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* API справочников: страны |
430
|
|
|
* |
431
|
|
|
* @param string $query |
432
|
|
|
* @return array |
433
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
434
|
|
|
* |
435
|
|
|
* @see https://dadata.ru/api/suggest/country/ |
436
|
|
|
*/ |
437
|
|
|
public function countrySuggest(string $query): array |
438
|
|
|
{ |
439
|
|
|
return $this->suggest([ |
440
|
|
|
'query' => $query |
441
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/country'); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* API справочников: страны |
446
|
|
|
* |
447
|
|
|
* @param string $query |
448
|
|
|
* @return array |
449
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
450
|
|
|
* |
451
|
|
|
* @see https://dadata.ru/api/suggest/country/ |
452
|
|
|
*/ |
453
|
|
|
public function countryFindById(string $query): array |
454
|
|
|
{ |
455
|
|
|
return $this->suggest([ |
456
|
|
|
'query' => $query |
457
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/country'); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
/** |
461
|
|
|
* API справочников: валюты |
462
|
|
|
* |
463
|
|
|
* @param string $query |
464
|
|
|
* @return array |
465
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
466
|
|
|
* |
467
|
|
|
* @see https://dadata.ru/api/suggest/currency/ |
468
|
|
|
*/ |
469
|
|
|
public function currencySuggest(string $query): array |
470
|
|
|
{ |
471
|
|
|
return $this->suggest([ |
472
|
|
|
'query' => $query |
473
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/currency'); |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* API справочников: валюты |
478
|
|
|
* |
479
|
|
|
* @param string $query |
480
|
|
|
* @return array |
481
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
482
|
|
|
* |
483
|
|
|
* @see https://dadata.ru/api/suggest/currency/ |
484
|
|
|
*/ |
485
|
|
|
public function currencyFindById(string $query): array |
486
|
|
|
{ |
487
|
|
|
return $this->suggest([ |
488
|
|
|
'query' => $query |
489
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/currency'); |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* API справочников: виды деятельности (ОКВЭД 2) |
494
|
|
|
* |
495
|
|
|
* @param string $query |
496
|
|
|
* @param array|null $filters [["razdel" => "C" ], ...] |
497
|
|
|
* @return array |
498
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
499
|
|
|
* |
500
|
|
|
* @see https://dadata.ru/api/suggest/okved2/ |
501
|
|
|
*/ |
502
|
|
|
public function okved2Suggest(string $query, ?array $filters = null): array |
503
|
|
|
{ |
504
|
|
|
return $this->suggest([ |
505
|
|
|
'query' => $query, |
506
|
|
|
'filters' => $filters |
507
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/okved2'); |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* API справочников: виды деятельности (ОКВЭД 2) |
512
|
|
|
* |
513
|
|
|
* @param string $query |
514
|
|
|
* @return array |
515
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
516
|
|
|
* |
517
|
|
|
* @see https://dadata.ru/api/suggest/okved2/ |
518
|
|
|
*/ |
519
|
|
|
public function okved2FindById(string $query): array |
520
|
|
|
{ |
521
|
|
|
return $this->suggest([ |
522
|
|
|
'query' => $query |
523
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/okved2'); |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* API справочников: виды продукции (ОКПД 2) |
528
|
|
|
* |
529
|
|
|
* @param string $query |
530
|
|
|
* @return array |
531
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
532
|
|
|
* |
533
|
|
|
* @see https://dadata.ru/api/suggest/okpd2/ |
534
|
|
|
*/ |
535
|
|
|
public function okpd2Suggest(string $query): array |
536
|
|
|
{ |
537
|
|
|
return $this->suggest([ |
538
|
|
|
'query' => $query |
539
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/okpd2'); |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
/** |
543
|
|
|
* API справочников: виды продукции (ОКПД 2) |
544
|
|
|
* |
545
|
|
|
* @param string $query |
546
|
|
|
* @return array |
547
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
548
|
|
|
* |
549
|
|
|
* @see https://dadata.ru/api/suggest/okpd2/ |
550
|
|
|
*/ |
551
|
|
|
public function okpd2FindById(string $query): array |
552
|
|
|
{ |
553
|
|
|
return $this->suggest([ |
554
|
|
|
'query' => $query |
555
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/okpd2'); |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
/** |
559
|
|
|
* API справочников: налоговые инспекции |
560
|
|
|
* |
561
|
|
|
* @param string $query |
562
|
|
|
* @param array|null $filter |
563
|
|
|
* @return array |
564
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
565
|
|
|
* |
566
|
|
|
* @see https://dadata.ru/api/suggest/fns_unit/ |
567
|
|
|
*/ |
568
|
|
|
public function fnsUnitSuggest(string $query, ?array $filter = null): array |
569
|
|
|
{ |
570
|
|
|
return $this->suggest([ |
571
|
|
|
'query' => $query, |
572
|
|
|
'filter' => $filter |
573
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/fns_unit'); |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
/** |
577
|
|
|
* API справочников: налоговые инспекции |
578
|
|
|
* |
579
|
|
|
* @param string $query |
580
|
|
|
* @return array |
581
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
582
|
|
|
* |
583
|
|
|
* @see https://dadata.ru/api/suggest/fns_unit/ |
584
|
|
|
*/ |
585
|
|
|
public function fnsUnitFindById(string $query): array |
586
|
|
|
{ |
587
|
|
|
return $this->suggest([ |
588
|
|
|
'query' => $query |
589
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/fns_unit'); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* API справочников: мировые суды |
594
|
|
|
* |
595
|
|
|
* @param string $query |
596
|
|
|
* @param array|null $filters |
597
|
|
|
* @return array |
598
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
599
|
|
|
* |
600
|
|
|
* @see https://dadata.ru/api/suggest/region_court/ |
601
|
|
|
*/ |
602
|
|
|
public function regionCourtSuggest(string $query, ?array $filters = null): array |
603
|
|
|
{ |
604
|
|
|
return $this->suggest([ |
605
|
|
|
'query' => $query, |
606
|
|
|
'filters' => $filters |
607
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/region_court'); |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
/** |
611
|
|
|
* API справочников: мировые суды |
612
|
|
|
* |
613
|
|
|
* @param string $query |
614
|
|
|
* @return array |
615
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
616
|
|
|
* |
617
|
|
|
* @see https://dadata.ru/api/suggest/region_court/ |
618
|
|
|
*/ |
619
|
|
|
public function regionCourtFindById(string $query): array |
620
|
|
|
{ |
621
|
|
|
return $this->suggest([ |
622
|
|
|
'query' => $query, |
623
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/region_court'); |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* API справочников: станции метро |
629
|
|
|
* |
630
|
|
|
* @param string $query |
631
|
|
|
* @param array|null $filters [['city_kladr_id' => '7800000000000'], ...] |
632
|
|
|
* @return array |
633
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
634
|
|
|
* |
635
|
|
|
* @see https://dadata.ru/api/suggest/metro/ |
636
|
|
|
*/ |
637
|
|
|
public function metroSuggest(string $query, ?array $filters = null): array |
638
|
|
|
{ |
639
|
|
|
return $this->suggest([ |
640
|
|
|
'query' => $query, |
641
|
|
|
'filters' => $filters |
642
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/metro'); |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
/* Private */ |
646
|
|
|
|
647
|
|
|
/** |
648
|
|
|
* @param array $args |
649
|
|
|
* @param string $uri |
650
|
|
|
* @return mixed |
651
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
652
|
|
|
*/ |
653
|
|
|
private function suggest(array $args, string $uri) |
654
|
|
|
{ |
655
|
|
|
$request = $this->requestFactory->createRequest('POST', $uri, $args); |
656
|
|
|
|
657
|
|
|
$response = $this->httpClient->sendRequest($request); |
658
|
|
|
|
659
|
|
|
return \json_decode($response->getBody()->getContents(), true); |
660
|
|
|
} |
661
|
|
|
} |
662
|
|
|
|