PHP code example of playtini / keitaro-client

1. Go to this page and download the library: Download playtini/keitaro-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/ */

    

playtini / keitaro-client example snippets


use Playtini\KeitaroClient\ClickApi\KeitaroClickApiClient;
use Playtini\KeitaroClient\ClickApi\KeitaroParams;
use Playtini\KeitaroClient\ClickApi\KeitaroRequest;
use Playtini\KeitaroClient\Http\KeitaroHttpClient;
use Symfony\Component\HttpClient\CurlHttpClient;
use Symfony\Component\HttpFoundation\Request;

ampaign token
$clickApiClient = new KeitaroClickApiClient($keitaroHttpClient, $keitaroRequest, $keitaroParams);
$response = $clickApiClient->createResponse($clickApiClient->getResult());
$response->send();




use Playtini\KeitaroClient\AdminApi\KeitaroAdminApiClient;
use Playtini\KeitaroClient\ClickApi\KeitaroClickApiTokenResolver;
use Playtini\KeitaroClient\Http\KeitaroHttpClient;
use Symfony\Component\HttpClient\CurlHttpClient;

$keitaroHttpClient = new KeitaroHttpClient(new CurlHttpClient(), 'https://keitaro.example.com'); // change to your TDS domain
$adminClient = new KeitaroAdminApiClient($keitaroHttpClient, 'ADMIN_API_KEY_HERE'); // change api key
$resolver = new KeitaroClickApiTokenResolver($adminClient);
$resolver->getCampaignToken('test-tds')

use Playtini\KeitaroClient\AdminApi\KeitaroAdminApiClient;
use Playtini\KeitaroClient\Http\KeitaroHttpClient;
use Symfony\Component\HttpClient\CurlHttpClient;

piClient($keitaroHttpClient, 'ADMIN_API_KEY_HERE'); // change api key

print_r($adminClient->campaigns());

public function __invoke(
    string $slug,
    Request $request,
    KeitaroClickApiClientFactory $clientFactory,
    KeitaroClickApiTokenResolver $apiTokenResolver,
): Response
{
    $client = $clientFactory->create(
        request: $request,
        campaignToken: $apiTokenResolver->getCampaignToken($slug), // it's cached
    );
    $client->params->set('log', 1);

    return $client->createResponse($client->getResult());
}

public function __invoke(KeitaroAdminApiClient $keitaroAdminApiClient): JsonResponse
{
    $campaigns = $keitaroAdminApiClient->campaigns();

    $tokens = [];
    foreach ($campaigns as $campaign) {
        $tokens[$campaign->alias] = $campaign->token;
    }

    return new JsonResponse($tokens);
}