Skip to content

Commit ac00014

Browse files
committed
first commit
0 parents  commit ac00014

21 files changed

+794
-0
lines changed

.gitattributes

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.sh linguist-vendored
2+
*.cache linguist-vendored
3+
*.xml linguist-vendored
4+
5+
*.blade linguist-language=php
6+
*.neon linguist-language=php
7+
*.php linguist-language=php
8+
*.php5 linguist-language=php
9+
*.phtml linguist-language=php
10+
*.inc linguist-language=php
11+
*.module linguist-language=php
12+
*.install linguist-language=php
13+
*.profile linguist-language=php
14+
*.test linguist-language=php
15+
*.info linguist-language=php

.github/workflows/php.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: PHP Composer
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Validate composer.json and composer.lock
21+
run: composer validate --strict
22+
23+
- name: Cache Composer packages
24+
id: composer-cache
25+
uses: actions/cache@v3
26+
with:
27+
path: vendor
28+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
29+
restore-keys: |
30+
${{ runner.os }}-php-
31+
32+
- name: Install dependencies
33+
run: composer install --prefer-dist --no-progress
34+
35+
- name: Run test suite
36+
run: composer run-script test

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.env
2+
.idea
3+
vendor
4+
composer.lock
5+
composer.phar
6+
7+
# phpunit
8+
*.cache
9+
10+
# composer
11+
composer.phar
12+
/vendor/
13+
.phpunit.cache
14+
example.php
15+
logs/
16+
**.log
17+
package.xml

CONTRIBUTING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
We accept contributions via Pull Requests on [GitHub](https://github.com/usevalid-email/php-sdk).
6+
7+
## Pull Requests
8+
9+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
10+
- **Document any change in behaviour** - Make sure the README and any other relevant documentation are kept up-to-date.
11+
- **Create topic branches** - Don't ask us to pull from your master branch.
12+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
13+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.
14+
15+
## Security
16+
17+
If you discover any security related issues, please email [hebert@hotbrains.com.br](mailto:hebert@hotbrains.com.br) instead of using the issue tracker.
18+
19+
## Credits
20+
21+
- [Hebert Barros](https://github.com/hebertcisco)
22+
- [All Contributors](https://github.com/usevalid-email/php-sdk/graphs/contributors)

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2025 usevalid.email
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# usevalid.email
2+
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/usevalid-email/sdk.svg?style=flat-square)](https://packagist.org/packages/usevalid-email/sdk)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/usevalid-email/sdk.svg?style=flat-square)](https://packagist.org/packages/usevalid-email/sdk)
5+
[![License](https://img.shields.io/packagist/l/usevalid-email/sdk.svg?style=flat-square)](https://packagist.org/packages/usevalid-email/sdk)
6+
7+
Validate Your Emails with Confidence
8+
9+
## Installation
10+
11+
You can install the package via composer:
12+
13+
```bash
14+
composer require usevalid-email/sdk
15+
```
16+
17+
## Usage
18+
19+
### Initialization
20+
21+
```php
22+
use UseValidEmail\Sdk;
23+
24+
$token = 'your-access-token';
25+
$sdk = new Sdk($token);
26+
```
27+
### Validate Email
28+
29+
```php
30+
use UseValidEmail\Sdk\Exceptions\AccessTokenException;
31+
use UseValidEmail\Sdk\Exceptions\ForbiddenException;
32+
use UseValidEmail\Sdk\Exceptions\UnauthorizedException;
33+
use GuzzleHttp\Exception\GuzzleException;
34+
35+
try {
36+
$email = 'example@example.com';
37+
$response = $sdk->emailValidator->validate($email);
38+
print_r($response->toArray());
39+
} catch (Exception $e) {
40+
// Handle exception
41+
}
42+
```
43+
44+
### Using Helper Function
45+
46+
```php
47+
use GuzzleHttp\Exception\GuzzleException;
48+
use UseValidEmail\Sdk\Exceptions\AccessTokenException;
49+
use UseValidEmail\Sdk\Exceptions\ForbiddenException;
50+
use UseValidEmail\Sdk\Exceptions\UnauthorizedException;
51+
use UseValidEmail\Sdk\Responses\Validation\ValidationResponse;
52+
53+
try {
54+
$email = 'example@example.com';
55+
$response = validateEmail($email);
56+
print_r($response->toArray());
57+
} catch (Exception $e) {
58+
// Handle exception
59+
}
60+
```
61+
## Testing
62+
63+
```bash
64+
composer test
65+
```
66+
67+
## Contributing
68+
69+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
70+
71+
## Credits
72+
73+
- [Hebert Barros](https://github.com/hebertcisco)
74+
- [All Contributors](https://github.com/usevalid-email/php-sdk/graphs/contributors)
75+
76+
## License
77+
78+
The MIT License (MIT). Please see [License File](LICENSE) for more information.

composer.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "usevalid-email/php-sdk",
3+
"type": "library",
4+
"description": "Validate Your Emails with Confidence",
5+
"keywords": [
6+
"email",
7+
"validation",
8+
"sdk",
9+
"api",
10+
"usevalid.email"
11+
],
12+
"homepage": "https://usevalid.email",
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "Contact",
17+
"email": "contact@usevalid.email",
18+
"homepage": "https://usevalid.email"
19+
}
20+
],
21+
"scripts": {
22+
"test": "vendor/bin/pest",
23+
"test:coverage": "vendor/bin/pest --coverage",
24+
"test:unit": "vendor/bin/pest --testsuite=unit"
25+
},
26+
"require": {
27+
"php": ">=7.4",
28+
"localtools/php-http-client": "^0.0.1",
29+
"ext-json": "*"
30+
},
31+
"require-dev": {
32+
"pestphp/pest": "^3.2 || ^v3.5.1",
33+
"laravel/pint": "^1.18",
34+
"phpunit/phpunit": "^8.5.40 || ^11.4.3",
35+
"mockery/mockery": "^1.6"
36+
},
37+
"autoload": {
38+
"psr-4": {
39+
"UseValidEmail\\Sdk\\": "src/"
40+
},
41+
"files": [
42+
"src/Utils/helpers.php"
43+
]
44+
},
45+
"autoload-dev": {
46+
"psr-4": {
47+
"UseValidEmail\\Sdk\\Tests\\": "tests/"
48+
}
49+
},
50+
"config": {
51+
"allow-plugins": {
52+
"pestphp/pest-plugin": true
53+
}
54+
}
55+
}

phpunit.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
3+
<testsuites>
4+
<testsuite name="Test Suite">
5+
<directory suffix="Test.php">./tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">./app</directory>
11+
<directory suffix=".php">./src</directory>
12+
</include>
13+
</source>
14+
</phpunit>

src/Dtos/ValidateEmailDto.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace UseValidEmail\Sdk\Dtos;
4+
5+
class ValidateEmailDto
6+
{
7+
public string $email;
8+
9+
public function __construct(
10+
string $email
11+
12+
) {
13+
$this->email = $email;
14+
}
15+
16+
public function toArray(): array
17+
{
18+
return [
19+
'email' => $this->email,
20+
];
21+
}
22+
}

src/EmailValidator.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace UseValidEmail\Sdk;
4+
5+
use GuzzleHttp\Exception\GuzzleException;
6+
use UseValidEmail\Sdk\Dtos\ValidateEmailDto;
7+
use UseValidEmail\Sdk\Exceptions\ForbiddenException;
8+
use UseValidEmail\Sdk\Exceptions\UnauthorizedException;
9+
use UseValidEmail\Sdk\Requests\HttpClient;
10+
use UseValidEmail\Sdk\Responses\Validation\ValidationResponse;
11+
12+
/**
13+
* Class EmailValidator
14+
*/
15+
class EmailValidator
16+
{
17+
protected bool $logs;
18+
19+
protected HttpClient $api;
20+
21+
public function __construct(HttpClient $api, bool $logs = false)
22+
{
23+
$this->api = $api;
24+
$this->logs = $logs;
25+
}
26+
27+
/**
28+
* Create a Charge
29+
*
30+
* @throws GuzzleException
31+
* @throws UnauthorizedException
32+
* @throws ForbiddenException
33+
*/
34+
public function validate(string $email): ValidationResponse
35+
{
36+
$data = new ValidateEmailDto($email);
37+
$response = $this->api->post('EmailValidator@validate', '/verify/v1', $data->toArray(), $this->logs);
38+
39+
if ($response->getStatusCode() === 401) {
40+
throw new UnauthorizedException;
41+
}
42+
43+
if ($response->getStatusCode() === 403) {
44+
throw new ForbiddenException;
45+
}
46+
47+
$data = json_decode($response->getBody()->getContents(), true);
48+
49+
return ValidationResponse::fromArray($data);
50+
}
51+
}

0 commit comments

Comments
 (0)