2017 © Pedro Peláez
 

git yandex-direct-client

PHP lib for Yandex Direct API

image

bubnov/yandex-direct-client

PHP lib for Yandex Direct API

  • Monday, January 23, 2017
  • by bubnov
  • Repository
  • 3 Watchers
  • 1 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 4 % Grown

The README.md

YandexDirectClient

Требует curl-расширение!, (*1)

Пакет для работы с сервисом Яндекс.Direct посредством его API., (*2)

  • Подготовлен к использованию через Composer
  • Определен автолоадер (согласно psr-4)
  • Доступны все методы API
  • Дополнительно перед отправкой проводится валидация входных данных через json-schema (База наполняется)

1) Установка Composer

composer require bubnov/yandex-direct-client

2) Использование

<?php
require 'vendor/autoload.php';

$authKey = 'MY-AUTH-TOKEN';

$client = new YandexDirectClient\Client($authKey);

try {
    /**
     * Getting Units for users
     */
    $response = $client->GetClientsUnits(['my-user','customer-user']);

    /**
     * If Response is an array - you can access to each element as in array
     */
    foreach($response as $item){
        /**
         * If the item has a property (see Yandex Direct API docs) - you can access it by getter
         */
        echo "\n" . $item->getLogin() . " has units: " . $item->getUnitsRest();
    }

    /**
     * Or you can access directly Nth element in array
     */
    echo "\nFirst user units: " . $response->get(0)->getUnitsRest();

    /**
     * Generating WordstatReport
     */
    $reportId = $client->CreateNewWordstatReport(['Phrases' => ['Купить холодильник', 'Холодильники недорого']]);
    echo "\nReportId: " . $reportId;

    /**
     * Wait for 10 seconds
     */
    sleep(10);

    /**
     * Getting full reports list
     */
    $reports = $client->GetWordstatReportList();
    foreach($reports as $report){
        /**
         * Find report with $reportId and status 'Done'
         */
        if($report->getReportID() == $reportId && $report->getStatusReport() === 'Done'){
            echo "\nReport is done, reading";
            break;
        }
    }

    /**
     * Get wordstat report by $reportId
     */
    $report = $client->GetWordstatReport($reportId);
    foreach($report as $reportPart){
        foreach($reportPart->getSearchedWith() as $searchedWith){
            echo sprintf(
                "\nPhrase `%s` has %d shows \n", 
                $searchedWith->getPhrase(), 
                $searchedWith->getShows()
            );
        }
    }

    /**
     * Deleting wordstat report
     */
    $status = $client->DeleteWordstatReport($reportId);
    echo $status ? "\nReport successfully deleted" : "\nSomething wrong...";
}
catch (\YandexDirectClient\Exceptions\YandexErrorException $e){
    echo "\nYandexErrorException: " . $e->getMessage() . "\nWith details: " . $e->getErrorDetail() . "\n";
}
catch (\Exception $e){
    echo "\nException: " . $e->getMessage() . "\n";
}

3) TODO

Расширение json schema для методов, (*3)

The Versions

23/01 2017

dev-master

9999999-dev https://github.com/bubnovKelnik/yandex-direct-client.git

PHP lib for Yandex Direct API

  Sources   Download

MIT

The Requires

 

api php yandex direct

15/04 2016

1.0.2

1.0.2.0 https://github.com/bubnovKelnik/yandex-direct-client.git

PHP lib for Yandex Direct API

  Sources   Download

MIT

The Requires

 

api php yandex direct

29/02 2016

1.0.1

1.0.1.0 https://github.com/bubnovKelnik/yandex-direct-client.git

PHP lib for Yandex Direct API

  Sources   Download

MIT

The Requires

 

api php yandex direct

23/04 2015

1.0.0

1.0.0.0 https://github.com/bubnovKelnik/yandex-direct-client.git

PHP lib for Yandex Direct API

  Sources   Download

MIT

The Requires

 

api php yandex direct