PHP code example of sharpapi / sharpapi-laravel-client

1. Go to this page and download the library: Download sharpapi/sharpapi-laravel-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-laravel-client example snippets




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"
            }
        ]
         */
    }
}

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 voice tone'    // optional voice tone
      );
    // $statusUrl example value: 'http://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();

return [
    'api_key' => env('SHARP_API_KEY'),
    'base_url' => env('SHARP_API_BASE_URL', 'https://sharpapi.com/api/v1'), // as ENV is mock server needed
    // how long (in seconds) the client should wait in polling mode for results
    'api_job_status_polling_wait' => env('SHARP_API_JOB_STATUS_POLLING_WAIT', 180),
    // how many seconds the client should wait between each result request
    // usually Retry-After header is used (default 10s), this value won't have an effect unless
    // api_job_status_use_polling_interval is set to TRUE
    'api_job_status_polling_interval' => env('SHARP_API_JOB_STATUS_POLLING_INTERVAL', 10),
    'api_job_status_use_polling_interval' => env('SHARP_API_JOB_STATUS_USE_POLLING_INTERVAL', false),
    // for affiliate program members use
    'user_agent' => env('SHARP_API_USER_AGENT', 'SharpAPILaravelAgent/1.1.0'),
];

SHARP_API_KEY=8bKzQl3cwckfVsnsN8T8p4BsACkziEQJ72U4pXpQ
SHARP_API_JOB_STATUS_POLLING_WAIT=200
SHARP_API_JOB_STATUS_USE_POLLING_INTERVAL=true
SHARP_API_JOB_STATUS_POLLING_INTERVAL=5
SHARP_API_BASE_URL=MOCK_SERVER
SHARP_API_USER_AGENT="SharpAPILaravelAgent/1.1.0"

$statusUrl = \SharpApiService::parseResume('/test/resume.pdf', 'English');

$jobDescriptionParameters = new JobDescriptionParameters(
    name: "PHP Senior Engineer",
    company_name: "ACME LTD",   // optional
    minimum_work_experience: "5 years",   // optional
    minimum_education: "Bachelor Degree",   // optional
    employment_type: "full time",   // optional
    cessing instructions
    language: null   // optional output language
);

$statusUrl = \SharpApiService::generateJobDescription($jobDescriptionParameters);

$statusUrl = \SharpApiService::relatedSkills(
    'MySQL', 
    'English',   // optional language
    10  // optional quantity
  );

$statusUrl = \SharpApiService::relatedJobPositions(
    'Senior PHP Engineer', 
    'English',   // optional language
    10  // optional quantity
  );

$statusUrl = \SharpApiService::productReviewSentiment('customer review contents');

$statusUrl = \SharpApiService::productCategories(
    'Sony Playstation 5', 
    'English',   // optional language
    5,   // optional quantity
    'Tech-savvy',   // optional voice tone
    'Game Console, PS5 Console'    // optional context, current categories to match
  );

$statusUrl = \SharpApiService::generateProductIntro(
    'Sony Playstation 5', 
    SharpApiLanguages::ENGLISH,   // optional language
    300,   // optional length
    'Funny'   // optional voice tone
  );

$statusUrl = \SharpApiService::generateThankYouEmail(
    'Sony Playstation 5', 
    SharpApiLanguages::ENGLISH,    // optional language
    250,    // optional length
    'Neutral',    // optional voice tone
    'Must invite customer to visit again before Holidays'   // optional context
   );

$statusUrl = \SharpApiService::translate(
    'turn', 
    SharpApiLanguages::FRENCH,    // optional language
    'neutral',    // optional voice tone
    'to turn a page'   // optional context
    );

// will result in :
// {"content": "tourner", "to_language": "French", "from_language": "English"}

$statusUrl = \SharpApiService::paraphrase(
    $text, 
    SharpApiLanguages::FRENCH,   // optional language
    500, // optional length
    'neutral',    // optional voice tone
    'avoid using abbreviations'   // optional context
    );

$statusUrl = \SharpApiService::proofread($text);

$statusUrl = \SharpApiService::detectSpam($text);

$statusUrl = \SharpApiService::detectPhones($text);

$statusUrl = \SharpApiService::detectEmails($text);

$statusUrl = \SharpApiService::generateKeywords(
    $text, 
    'English',    // optional language
    5,  // optional length
    'Freaky & Curious'    // optional voice tone
  );

$statusUrl = \SharpApiService::summarizeText(
    $text, 
    'English',     // optional language
    'David Attenborough'    // optional voice tone
  );

$statusUrl = \SharpApiService::generateSeoTags(
    $text, 
    'English',      // optional language
    'David Attenborough'    // optional voice tone
  );

$statusUrl = \SharpApiService::travelReviewSentiment($text);

$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();