1 | <?php |
||
2 | |||
3 | namespace NStack\Clients; |
||
4 | |||
5 | use NStack\Exceptions\FailedToParseException; |
||
6 | use NStack\Models\EmailValidation; |
||
7 | use NStack\Models\PhoneValidation; |
||
8 | |||
9 | /** |
||
10 | * Class ValidatorsClient |
||
11 | * |
||
12 | * @package NStack\Clients |
||
13 | * @author Tiago Araujo <[email protected]> |
||
14 | */ |
||
15 | class ValidatorsClient extends NStackClient |
||
16 | { |
||
17 | /** @var string */ |
||
18 | protected $path = 'validator'; |
||
19 | |||
20 | /** |
||
21 | |||
22 | * |
||
23 | * @param String $email |
||
24 | * @return EmailValidation |
||
25 | * @throws FailedToParseException |
||
26 | * @author Tiago Araujo <[email protected]> |
||
27 | */ |
||
28 | 1 | public function email(String $email): EmailValidation |
|
29 | { |
||
30 | 1 | $response = $this->client->get($this->buildPath($this->path . '/email?email=' . $email)); |
|
31 | 1 | $contents = $response->getBody()->getContents(); |
|
32 | 1 | $data = json_decode($contents, true); |
|
33 | |||
34 | 1 | return new EmailValidation($data); |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * phone |
||
39 | * |
||
40 | * @param String $phone |
||
41 | * @param String|null $fallbackCountryCode |
||
42 | * @param Boolean|null $validateWithTwilio |
||
43 | * @param String|null $twilioType |
||
44 | * @return PhoneValidation |
||
45 | * @throws FailedToParseException |
||
46 | * @author Tiago Araujo <[email protected]> |
||
47 | */ |
||
48 | 1 | public function phone( |
|
49 | String $phone, |
||
50 | String $fallbackCountryCode = null, |
||
51 | bool $validateWithTwilio = null, |
||
52 | String $twilioType = null |
||
53 | ): PhoneValidation { |
||
54 | 1 | $path = $this->buildPath($this->path . '/phone?phone=' . $phone); |
|
55 | |||
56 | 1 | if ($fallbackCountryCode) { |
|
57 | 1 | $path = $path . '&fallback_country_code=' . $fallbackCountryCode; |
|
58 | } |
||
59 | 1 | if ($validateWithTwilio) { |
|
60 | 1 | $path = $path . '&twilio=' . $validateWithTwilio; |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
61 | } |
||
62 | 1 | if ($twilioType) { |
|
63 | 1 | $path = $path . '&twilio_type=' . $twilioType; |
|
64 | } |
||
65 | |||
66 | 1 | $response = $this->client->get($path); |
|
67 | 1 | $contents = $response->getBody()->getContents(); |
|
68 | 1 | $data = json_decode($contents, true); |
|
69 | |||
70 | 1 | return new PhoneValidation($data); |
|
71 | } |
||
72 | } |