<?php

require '../vendor/autoload.php';
$username = '******';
$password = '******';
$dataProviderId = '{yourDataProviderId}';
// create the API client instance
try {
    $redisConfig = ['scheme' => 'tcp', 'host' => 'localhost', 'port' => 6379];
    $cache = new Audiens\AdForm\Cache\RedisCache($redisConfig);
    $adform = new Audiens\AdForm\Client($username, $password);
    //, $cache);
} catch (Audiens\AdForm\Exception\OauthException $e) {
    exit($e->getMessage());
}
// Get data usage grouped by segment
$from = new DateTime('first day of this month');
$to = new DateTime('today');
$groupBy = ['segment'];
/** @var stdClass[] */
$dataUsage = $adform->dataUsage()->get($dataProviderId, $from, $to, $groupBy);
foreach ($dataUsage as $usage) {
    echo $usage->segmentsGroup . ": " . $usage->revenue . "\n";
}
<?php

require "../vendor/autoload.php";
$username = '******';
$password = '******';
$dataProviderId = '{yourDataProviderId}';
// create the API client instance
try {
    $redisConfig = ["scheme" => "tcp", "host" => "localhost", "port" => 6379];
    $cache = new Audiens\AdForm\Cache\RedisCache($redisConfig);
    $adform = new Audiens\AdForm\Client($username, $password, $cache);
} catch (Audiens\AdForm\Exception\OauthException $e) {
    exit($e->getMessage());
}
// Get audience grouped by segment
$from = new \DateTime("first day of this month");
$to = new \DateTime("today");
$groupBy = ["segment"];
/** @var stdClass[] */
$dataProviderAudiences = $adform->dataProviderAudience()->get($dataProviderId, $from, $to, $groupBy);
foreach ($dataProviderAudiences as $dataProviderAudience) {
    echo $dataProviderAudience->getDate()->format("d.m.Y.") . " - " . $dataProviderAudience->getDataProvider() . "\n";
    echo "Total: " . $dataProviderAudience->getTotal() . "\n";
    echo "Unique: " . $dataProviderAudience->getUnique() . "\n";
    echo "Total Hits: " . $dataProviderAudience->getTotalHits() . "\n";
    echo "Unique Hits: " . $dataProviderAudience->getUniqueHits() . "\n";
    echo "\n";
}
<?php

require '../vendor/autoload.php';
$username = '******';
$password = '******';
$dataProviderId = '{yourDataProviderId}';
// create the API client instance
try {
    $redisConfig = ['scheme' => 'tcp', 'host' => 'localhost', 'port' => 6379];
    $cache = new Audiens\AdForm\Cache\RedisCache($redisConfig);
    $adform = new Audiens\AdForm\Client($username, $password, $cache);
} catch (Audiens\AdForm\Exception\OauthException $e) {
    exit($e->getMessage());
}
// Get 10 categories
/** @var \Audiens\AdForm\Entity\Category[] $categories */
$categories = $adform->categories()->getItems(10);
foreach ($categories as $category) {
    echo $category->getName() . "\n";
}
// Get 10 categories for your data provider
/** @var \Audiens\AdForm\Entity\Category[] $categories */
$categories = $adform->categories()->getItemsDataProvider($dataProviderId, 10);
foreach ($categories as $category) {
    echo $category->getName() . "\n";
}
try {
    // Create a category
    $category = new Audiens\AdForm\Entity\Category();
    $category->setName('Test')->setDataProviderId($dataProviderId);
    $category = $adform->categories()->create($category);
<?php

require '../vendor/autoload.php';
$username = '******';
$password = '******';
$dataProviderId = '{yourDataProviderId}';
// create the API client instance
try {
    $redisConfig = ['scheme' => 'tcp', 'host' => 'localhost', 'port' => 6379];
    $cache = new Audiens\AdForm\Cache\RedisCache($redisConfig);
    $adform = new Audiens\AdForm\Client($username, $password, $cache);
} catch (Audiens\AdForm\Exception\OauthException $e) {
    exit($e->getMessage());
}
// Get 10 segments
/** @var \Audiens\AdForm\Entity\Segment[] $segments */
$segments = $adform->segments()->getItems(2);
foreach ($segments as $segment) {
    echo $segment->getName() . "\n";
}
// Get 10 segments for your data provider
/** @var \Audiens\AdForm\Entity\Segment[] $segments */
$segments = $adform->segments()->getItemsDataProvider($dataProviderId, 10);
foreach ($segments as $segment) {
    echo $segment->getName() . "\n";
}
// Get 10 segments from a category
$categoryId = '{categoryId}';
/** @var \Audiens\AdForm\Entity\Segment[] $segments */
$segments = $adform->segments()->getItemsDataProvider($categoryId, 10);
foreach ($segments as $segment) {