Skip to content

Commit e83412c

Browse files
committed
init
1 parent 8ecc189 commit e83412c

File tree

7 files changed

+245
-0
lines changed

7 files changed

+245
-0
lines changed

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/vendor/
2+
node_modules/
3+
npm-debug.log
4+
yarn-error.log
5+
6+
storage/*.key
7+
.env
8+
Homestead.yaml
9+
Homestead.json
10+
/.vagrant
11+
.phpunit.result.cache
12+
.idea
13+
14+
build
15+
composer.lock
16+
.phpunit.result.cache
17+
.php-cs-fixer.cache
18+
coverage
19+
phpstan.neon

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
All notable changes to `laravel-content-detect-emails` will be documented in this file.
4+
5+
## 1.0.0 - 2024-06-06
6+
7+
- Initial release
8+
- Support for detecting and extracting email addresses from text content
9+
- Comprehensive documentation and examples

LICENSE.md

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) SharpAPI <[email protected]>
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.

composer.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"name": "sharpapi/laravel-content-detect-emails",
3+
"description": "AI Email Detection for Laravel powered by SharpAPI.com",
4+
"keywords": [
5+
"sharpapi",
6+
"ai-powered",
7+
"ai capabilities",
8+
"api",
9+
"ai api",
10+
"api integration",
11+
"artificial intelligence",
12+
"natural language processing",
13+
"restful api",
14+
"php",
15+
"laravel",
16+
"software development",
17+
"content analysis",
18+
"email detection",
19+
"email extraction",
20+
"text processing"
21+
],
22+
"homepage": "https://github.com/sharpapi/laravel-content-detect-emails",
23+
"license": "MIT",
24+
"authors": [
25+
{
26+
"name": "Dawid Makowski",
27+
"email": "[email protected]",
28+
"role": "Developer"
29+
}
30+
],
31+
"require": {
32+
"php": "^8.1",
33+
"ext-json": "*",
34+
"guzzlehttp/guzzle": "^7.0",
35+
"laravel/framework": "^9.0|^10.0|^11.0|^12.0",
36+
"kongulov/interact-with-enum": "^1.0",
37+
"sharpapi/php-core": "^1.0",
38+
"spatie/url": "^2.4"
39+
},
40+
"require-dev": {
41+
"laravel/pint": "^1.0"
42+
},
43+
"autoload": {
44+
"psr-4": {
45+
"SharpAPI\\ContentDetectEmails\\": "src/"
46+
}
47+
},
48+
"autoload-dev": {
49+
"psr-4": {
50+
"SharpAPI\\ContentDetectEmails\\Tests\\": "tests/"
51+
}
52+
},
53+
"scripts": {
54+
"post-autoload-dump": "",
55+
"build": [
56+
],
57+
"start": [
58+
"Composer\\Config::disableProcessTimeout",
59+
"@composer run build"
60+
],
61+
"analyse": "vendor/bin/phpstan analyse",
62+
"test": "vendor/bin/pest",
63+
"test-coverage": "vendor/bin/pest --coverage",
64+
"format": "vendor/bin/pint"
65+
},
66+
"config": {
67+
"sort-packages": true,
68+
"allow-plugins": {
69+
"pestphp/pest-plugin": true,
70+
"phpstan/extension-installer": true
71+
}
72+
},
73+
"extra": {
74+
"laravel": {
75+
"providers": [
76+
"SharpAPI\\ContentDetectEmails\\ContentDetectEmailsProvider"
77+
]
78+
}
79+
},
80+
"minimum-stability": "dev",
81+
"prefer-stable": true
82+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
'api_key' => env('SHARP_API_KEY'),
7+
'base_url' => env('SHARP_API_BASE_URL', 'https://sharpapi.com/api/v1'), // as ENV is mock server needed
8+
// how long (in seconds) the client should wait in polling mode for results
9+
'api_job_status_polling_wait' => env('SHARP_API_JOB_STATUS_POLLING_WAIT', 180),
10+
// how many seconds the client should wait between each result request
11+
// usually Retry-After header is used (default 10s), this value won't have an effect unless
12+
// api_job_status_use_polling_interval is set to TRUE
13+
'api_job_status_polling_interval' => env('SHARP_API_JOB_STATUS_POLLING_INTERVAL', 10),
14+
'api_job_status_use_polling_interval' => env('SHARP_API_JOB_STATUS_USE_POLLING_INTERVAL', false),
15+
// for affiliate program members use
16+
];

src/ContentDetectEmailsProvider.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SharpAPI\ContentDetectEmails;
6+
7+
use Illuminate\Support\ServiceProvider;
8+
9+
/**
10+
* @api
11+
*/
12+
class ContentDetectEmailsProvider extends ServiceProvider
13+
{
14+
/**
15+
* Bootstrap the application services.
16+
*/
17+
public function boot(): void
18+
{
19+
if ($this->app->runningInConsole()) {
20+
$this->publishes([
21+
__DIR__.'/../config/sharpapi-content-detect-emails.php' => config_path('sharpapi-content-detect-emails.php'),
22+
], 'sharpapi-content-detect-emails');
23+
}
24+
}
25+
26+
/**
27+
* Register the application services.
28+
*/
29+
public function register(): void
30+
{
31+
// Merge the package configuration with the app configuration.
32+
$this->mergeConfigFrom(
33+
__DIR__.'/../config/sharpapi-content-detect-emails.php', 'sharpapi-content-detect-emails'
34+
);
35+
}
36+
}

src/ContentDetectEmailsService.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SharpAPI\ContentDetectEmails;
6+
7+
use GuzzleHttp\Exception\GuzzleException;
8+
use InvalidArgumentException;
9+
use SharpAPI\Core\Client\SharpApiClient;
10+
11+
/**
12+
* @api
13+
*/
14+
class ContentDetectEmailsService extends SharpApiClient
15+
{
16+
/**
17+
* Initializes a new instance of the class.
18+
*
19+
* @throws InvalidArgumentException if the API key is empty.
20+
*/
21+
public function __construct()
22+
{
23+
parent::__construct(config('sharpapi-content-detect-emails.api_key'));
24+
$this->setApiBaseUrl(
25+
config(
26+
'sharpapi-content-detect-emails.base_url',
27+
'https://sharpapi.com/api/v1'
28+
)
29+
);
30+
$this->setApiJobStatusPollingInterval(
31+
(int) config(
32+
'sharpapi-content-detect-emails.api_job_status_polling_interval',
33+
5)
34+
);
35+
$this->setApiJobStatusPollingWait(
36+
(int) config(
37+
'sharpapi-content-detect-emails.api_job_status_polling_wait',
38+
180)
39+
);
40+
$this->setUserAgent('SharpAPILaravelContentDetectEmails/1.0.0');
41+
}
42+
43+
/**
44+
* Parses the provided text for any possible emails. Might come in handy in case of processing and validating
45+
* big chunks of data against email addresses or f.e. if you want to detect emails in places
46+
* where they're not supposed to be.
47+
*
48+
* @throws GuzzleException
49+
*
50+
* @api
51+
*/
52+
public function detectEmails(string $text): string
53+
{
54+
$response = $this->makeRequest(
55+
'POST',
56+
'/content/detect_emails',
57+
['content' => $text]
58+
);
59+
60+
return $this->parseStatusUrl($response);
61+
}
62+
}

0 commit comments

Comments
 (0)