<?php
use Http\Promise\FulfilledPromise;
use Http\Promise\Promise;
use Leadping\OpenApiClient\LeadpingOpenApiClient;
use Microsoft\Kiota\Abstractions\Authentication\AuthenticationProvider;
use Microsoft\Kiota\Abstractions\RequestInformation;
use Microsoft\Kiota\Http\GuzzleRequestAdapter;
final class LeadpingAuthenticationProvider implements AuthenticationProvider
{
public function __construct(private readonly string $credential) {}
public function authenticateRequest(
RequestInformation $request,
array $additionalAuthenticationContext = []
): Promise {
$request->getHeaders()->tryAdd('Authorization', 'Bearer ' . $this->credential);
return new FulfilledPromise($request);
}
}
$credential = getenv('LEADPING_API_KEY');
if ($credential === false || $credential === '') {
throw new RuntimeException('LEADPING_API_KEY is not set.');
}
$adapter = new GuzzleRequestAdapter(new LeadpingAuthenticationProvider($credential));
$client = new LeadpingOpenApiClient($adapter);
$lead = $client->leads()->byId('lead-id')->get()->wait();