1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Promopult\Dadata\Services; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Clean |
9
|
|
|
* |
10
|
|
|
* API стандартизации |
11
|
|
|
* |
12
|
|
|
* @see https://dadata.ru/api/clean/ |
13
|
|
|
*/ |
14
|
|
|
final class Clean extends \Promopult\Dadata\Service |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param string $address |
18
|
|
|
* @return array |
19
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
20
|
|
|
* |
21
|
|
|
* @see https://dadata.ru/api/clean/address/ |
22
|
|
|
*/ |
23
|
|
|
public function address(string $address): array |
24
|
|
|
{ |
25
|
|
|
return $this->clean([$address], 'https://cleaner.dadata.ru/api/v1/clean/address'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* API стандартизации email |
30
|
|
|
* |
31
|
|
|
* @param string $email |
32
|
|
|
* @return array |
33
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
34
|
|
|
* |
35
|
|
|
* @see https://dadata.ru/api/clean/email/ |
36
|
|
|
*/ |
37
|
|
|
public function email(string $email): array |
38
|
|
|
{ |
39
|
|
|
return $this->clean([$email], 'https://cleaner.dadata.ru/api/v1/clean/email'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* API стандартизации телефонов |
44
|
|
|
* |
45
|
|
|
* @param string $phone |
46
|
|
|
* @return array |
47
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
48
|
|
|
* |
49
|
|
|
* @see https://dadata.ru/api/clean/phone/ |
50
|
|
|
*/ |
51
|
|
|
public function phone(string $phone): array |
52
|
|
|
{ |
53
|
|
|
return $this->clean([$phone], 'https://cleaner.dadata.ru/api/v1/clean/phone'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* API стандартизации ФИО |
58
|
|
|
* |
59
|
|
|
* @param string $name |
60
|
|
|
* @return array |
61
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
62
|
|
|
* |
63
|
|
|
* @see https://dadata.ru/api/clean/name/ |
64
|
|
|
*/ |
65
|
|
|
public function name(string $name): array |
66
|
|
|
{ |
67
|
|
|
return $this->clean([$name], 'https://cleaner.dadata.ru/api/v1/clean/name'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* API стандартизации паспортов |
72
|
|
|
* |
73
|
|
|
* @param string $passport |
74
|
|
|
* @return array |
75
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
76
|
|
|
* |
77
|
|
|
* @see https://dadata.ru/api/clean/passport/ |
78
|
|
|
*/ |
79
|
|
|
public function passport(string $passport): array |
80
|
|
|
{ |
81
|
|
|
return $this->clean([$passport], 'https://cleaner.dadata.ru/api/v1/clean/passport'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function vehicle(string $vehicle): array |
85
|
|
|
{ |
86
|
|
|
return $this->clean([$vehicle], 'https://cleaner.dadata.ru/api/v1/clean/vehicle'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function custom(array $structure, array $data): array |
90
|
|
|
{ |
91
|
|
|
return $this->clean([ |
92
|
|
|
'structure' => $structure, |
93
|
|
|
'data' => $data |
94
|
|
|
], 'https://cleaner.dadata.ru/api/v1/clean'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* API стандартизации дат рождения |
99
|
|
|
* |
100
|
|
|
* @param string $birthdate |
101
|
|
|
* @return array |
102
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
103
|
|
|
* |
104
|
|
|
* @see https://dadata.ru/api/clean/birthdate/ |
105
|
|
|
*/ |
106
|
|
|
public function birthdate(string $birthdate): array |
107
|
|
|
{ |
108
|
|
|
return $this->clean([$birthdate], 'https://cleaner.dadata.ru/api/v1/clean/birthdate'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param array $args |
113
|
|
|
* @param string $uri |
114
|
|
|
* @return array |
115
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
116
|
|
|
*/ |
117
|
|
|
private function clean(array $args, string $uri): array |
118
|
|
|
{ |
119
|
|
|
$request = $this->requestFactory->createRequest('POST', $uri, $args); |
120
|
|
|
$response = $this->httpClient->sendRequest($request); |
121
|
|
|
return \json_decode($response->getBody()->getContents(), true); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|