GithubHelp home page GithubHelp logo

pgreate / keitaro-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from playtini/keitaro-client

0.0 0.0 0.0 121 KB

Keitaro Client: Click API, Admin API

License: GNU General Public License v3.0

PHP 100.00%

keitaro-client's Introduction

Keitaro PHP Client

Keitaro is a tool for affiliate and performance marketing.

It has 2 APIs: Click API, Admin API.

Maintainer

This library is created and supported by Playtini.

We're hiring marketers (FB, Tiktok, UAC, in-app, Google) and developers (PHP, JS): playtini.ua/jobs

Install

composer require playtini/keitaro-client

Click API

Accept traffic at your server, let Keitaro track and route your traffic.

Click API is available in Pro and Business Keitaro editions.

Click API docs:

Usage:

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;

require_once(__DIR__ . '/vendor/autoload.php');

$keitaroHttpClient = new KeitaroHttpClient(new CurlHttpClient(), 'https://keitaro.example.com'); // change to your TDS domain
$keitaroRequest = KeitaroRequest::create(Request::createFromGlobals()),
$keitaroParams = KeitaroParams::createFromKeitaroRequest($keitaroRequest, 'CAMPAIGN_TOKEN_HERE'); // change campaign token
$clickApiClient = new KeitaroClickApiClient($keitaroHttpClient, $keitaroRequest, $keitaroParams);
$response = $clickApiClient->createResponse($clickApiClient->getResult());
$response->send();

If you don't know campaign token but know campaign alias (unique URL part in TDS link - like https://keitaro.example.com/THIS_IS_ALIAS ) then use KeitaroClickApiTokenResolver to get token via Admin API.

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')

For dependency injection you can use KeitaroClickApiClientFactory.

Admin API

View, edit data at Keitaro without using UI.

Admin API is available only in Business Keitaro edition.

Admin API docs:

Usage:

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

require_once(__DIR__ . '/vendor/autoload.php');

$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

print_r($adminClient->campaigns());

Warning! Only several endpoints are implemented. If you need more please add an issue, we'll make them sooner.

Symfony config example

config/services.yaml

    Playtini\KeitaroClient\Http\KeitaroHttpClient:
        bind:
            $trackerUrl: '%env(KEITARO_TRACKER_URL)%'

    Playtini\KeitaroClient\AdminApi\KeitaroAdminApiClient:
        bind:
            $adminApiKey: '%env(KEITARO_ADMIN_API_KEY)%'

    Playtini\KeitaroClient\ClickApi\KeitaroClickApiClientFactory: {public: true}
    Playtini\KeitaroClient\ClickApi\KeitaroClickApiTokenResolver: {public: true}
KEITARO_TRACKER_URL=https://keitaro.example.com
KEITARO_ADMIN_API_KEY=aaa111bbb222aaa111bbb222

Don't forget to set real values in environment variables.

Click API controller method

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

Admin API controller method

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

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

    return new JsonResponse($tokens);
}

keitaro-client's People

Contributors

luchaninov avatar pgreate avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.