PHP code example of sharpapi / sharpapi-php-client
1. Go to this page and download the library: Download sharpapi/sharpapi-php-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sharpapi / sharpapi-php-client example snippets
$sharpApi = new \SharpAPI\SharpApiService\SharpApiService(SHARP_API_KEY);
$statusUrl = $sharpApi->productCategories(
'Lenovo Chromebook Laptop (2023), 14" FHD Touchscreen Slim 3,
8-Core MediaTek Kompanio 520 CPU, 4GB RAM, 128GB Storage',
'German', // optional language
400, // optional quantity
'optional neutral voice tone', // optional voice tone
'optional current e-store categories' // optional context, current categories to match
);
$resultSharpApiJob = $sharpApi->fetchResults($statusUrl);
var_dump($resultSharpApiJob->getResultJson());
use GuzzleHttp\Exception\ClientException;
// Step 1: dispatch the job to the API with one of the methods, for example:
try {
$statusUrl = \SharpApiService::summarizeText(
$text,
'German' // optional language
500, // optional length
'neutral' // optional voice tone
);
// $statusUrl example value: 'https://sharpapi.com/api/v1/job/status/75acb6dc-a975-4969-9ef1-c62cebc511cb'
} catch (ClientException $e) {
$e->getResponse()
}
// Step 2: request to check job status in polling mode and wait for the result
$jobResult = \SharpApiService::fetchResults($statusUrl);
// Step 3: get results of dispatched API job, f.e. this returns job result as a prettied JSON
$jobResultJson = $jobResult->getResultJson();
// ..or PHP array:
$jobResultArray = $jobResult->getResultArray();
// ..or PHP stdClass:
$jobResultObject = $jobResult->getResultObject();
namespace App\Http\Controllers;
use GuzzleHttp\Exception\GuzzleException;
use SharpAPI\SharpApiService\SharpApiService;
class SharpTest extends Controller
{
public function __construct(public SharpApiService $sharpApiService)
{
}
/**
* @throws GuzzleException
*/
public function detect_phones(): void
{
$statusUrl = $this->sharpApiService->detectPhones(
'Where to find us? Call with a sales tech advisor:
Call: 1800-394-7486 or our Singapore office +65 8888 8888'
);
$result = $this->sharpApiService->fetchResults($statusUrl);
dd($result->getResultJson());
/* returned:
[
{
"detected_number": "1800-394-7486",
"parsed_number": "+18003947486"
},
{
"detected_number": "+65 8888 8888",
"parsed_number": "+6588888888"
}
]
*/
}
}
$statusUrl = \SharpApiService::toursAndActivitiesProductCategories(
'Oasis of the Bay'
'Ha Long', // optional city
'Vietnam', // optional country
'English', // optional language
10, // optional quantity
'Adventurous', // optional voice tone
'Bay Hotels, Ha Long Hotels' // optional context, current categories to match
);
$statusUrl = \SharpApiService::hospitalityProductCategories(
'Hotel Crystal 大人専用'
'Tokyo', // optional city
'Japan', // optional country
'English', // optional language
10, // optional quantity
'Adventurous', // optional voice tone
'Tokyo Hotels, Crystal Hotels' // optional context, current categories to match
);
$statusUrl = \SharpApiService::quota();
$statusUrl = \SharpApiService::ping();
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.