PHP code example of perf2k2 / direct

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

    

perf2k2 / direct example snippets


$reference = new ReferenceClient(
    new Connection(new Credential('token', 'client')),
    new JsonReader()
);

$criteria = (new AdsSelectionCriteria())
    ->setCampaignIds([1000])
    ->setTypes([AdTypeEnum::TEXT_AD()]);

$method = $reference
    ->getAdsService()
    ->getGetMethod()
    ->setSelectionCriteria($criteria)
    ->setFieldNames([AdFieldEnum::Id, AdFieldEnum::State])
    ->setTextAdFieldNames([
        TextAdFieldEnum::VCardId,
        TextAdFieldEnum::Href,
        TextAdFieldEnum::SitelinkSetId,
    ]);

$data = $reference->process($method)->getResult('Ads');
 
$stats = new ReportClient(
    new Connection(new Credential('token', 'client')),
    new TSVReader()
);

$method = $stats
    ->getReportsService()
    ->getBuildMethod()
    ->setSelectionCriteria(
        (new SelectionCriteria())
            ->setDateFrom(new \DateTimeImmutable('yesterday'))
            ->setDateTo(new \DateTimeImmutable('today'))
    )
    ->setFieldNames([FieldEnum::CampaignId(), FieldEnum::CampaignName(), FieldEnum::CampaignType()])
    ->setPage(new Page(10))
    ->setOrderBy([new OrderBy(FieldEnum::CampaignId(), OrderBySortOrderEnum::DESCENDING())])
    ->setReportName('Campaigns stats')
    ->setReportType(ReportTypeEnum::CAMPAIGN_PERFORMANCE_REPORT())
    ->setDateRangeType(DateRangeTypeEnum::CUSTOM_DATE())
    ->setFormat(FormatEnum::TSV())
    ->setIncludeVAT(YesNoEnum::NO())
    ->setIncludeDiscount(YesNoEnum::NO());

$data = $stats->process($method)->asArray();