|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NStack\Clients; |
|
4
|
|
|
|
|
5
|
|
|
use NStack\Exceptions\FailedToParseException; |
|
6
|
|
|
use NStack\Models\EmailValidation; |
|
7
|
|
|
use NStack\Models\IpAddress; |
|
8
|
|
|
use NStack\Models\PhoneValidation; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class ValidatorsClient |
|
12
|
|
|
* |
|
13
|
|
|
* @package NStack\Clients |
|
14
|
|
|
* @author Tiago Araujo <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class ValidatorsClient extends NStackClient |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var string */ |
|
19
|
|
|
protected $path = 'validator'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* email |
|
23
|
|
|
* |
|
24
|
|
|
* @param String $email |
|
25
|
|
|
* @return EmailValidation |
|
26
|
|
|
* @throws FailedToParseException |
|
27
|
|
|
* @author Tiago Araujo <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
1 |
|
public function email(String $email): EmailValidation |
|
30
|
|
|
{ |
|
31
|
1 |
|
$response = $this->client->get($this->buildPath($this->path . '/email?email=' . $email)); |
|
32
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
33
|
1 |
|
$data = json_decode($contents, true); |
|
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
|
|
|
{ |
|
55
|
1 |
|
$path = $this->buildPath($this->path . '/phone?phone=' . $phone); |
|
56
|
|
|
|
|
57
|
1 |
|
if ($fallbackCountryCode) { |
|
58
|
1 |
|
$path = $path . '&fallback_country_code=' . $fallbackCountryCode; |
|
59
|
|
|
} |
|
60
|
1 |
|
if ($validateWithTwilio) { |
|
61
|
1 |
|
$path = $path . '&twilio=' . $validateWithTwilio; |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
1 |
|
if ($twilioType) { |
|
64
|
1 |
|
$path = $path . '&twilio_type=' . $twilioType; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
$response = $this->client->get($path); |
|
68
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
69
|
1 |
|
$data = json_decode($contents, true); |
|
70
|
1 |
|
return new PhoneValidation($data); |
|
71
|
|
|
} |
|
72
|
|
|
} |