diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..96f8a97 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Dmitry Gladyshev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e63d1c8 --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +Yandex Direct API v5 PHP client +=============================== + +Поддерживается только 5-ая версия [Yandex.Direct API](https://tech.yandex.ru/direct/doc/dg/concepts/about-docpage/). + +### Требования + * PHP 5.4 и выше с curl-расширением + +### Установка +В файле `composer.json`: +```php +{ + ... + "require": { + ... + "gladyshev/php-yandex-direct-client": "dev-master" + } + ... +} +``` + +### Использование + +```php +use Yandex\Direct\Client; +use Yandex\Direct\Credentials; + +$credentials = new Credentials(YOUR_API_LOGIN, YOUR_API_TOKEN); +$api = new Client($credentials); + +$response = $api->campaigns->get( + ['Ids' => [123545345, 23423234]], // SelectionCriteria + ['Status', 'Currency', 'Funds'] // FieldNames +); + +print_r($response); + +// [ +// 'units' => [ +// 'debit' => 10, +// 'limit' => 50, +// 'rest' => 100500 +// ], +// 'result' => [...] +// ] +``` \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..0541077 --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "gladyshev/yandex-direct-client", + "keywords": ["yandex direct"], + "description": "Yandex Direct API PHP-client", + "type": "library", + "license": "MIT", + "minimum-stability": "stable", + "require": { + "php": ">=5.4", + "psr/log": "1.0.2", + "guzzlehttp/guzzle": "5.3" + }, + "require-dev": { + "phpunit/phpunit": "5.5" + }, + "autoload": { + "psr-4": { + "Yandex\\Direct\\": [ + "src/" + ] + } + }, + "autoload-dev": { + "psr-4": { + "Yandex\\Direct\\Test\\": "tests/" + } + }, + "scripts": { + "cs-check": "phpcs", + "test": "phpunit" + } +} \ No newline at end of file diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..017c7bc --- /dev/null +++ b/composer.lock @@ -0,0 +1,1570 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "ede94458a9ba08a4711e099b3886ddb0", + "content-hash": "ab98735e4fc6ac97b07fdfb984b13319", + "packages": [ + { + "name": "guzzlehttp/guzzle", + "version": "5.3.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "f3c8c22471cb55475105c14769644a49c3262b93" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f3c8c22471cb55475105c14769644a49c3262b93", + "reference": "f3c8c22471cb55475105c14769644a49c3262b93", + "shasum": "" + }, + "require": { + "guzzlehttp/ringphp": "^1.1", + "php": ">=5.4.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0", + "psr/log": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2015-05-20 03:47:55" + }, + { + "name": "guzzlehttp/ringphp", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/RingPHP.git", + "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", + "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", + "shasum": "" + }, + "require": { + "guzzlehttp/streams": "~3.0", + "php": ">=5.4.0", + "react/promise": "~2.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "ext-curl": "Guzzle will use specific adapters if cURL is present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Ring\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.", + "time": "2015-05-20 03:37:09" + }, + { + "name": "guzzlehttp/streams", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/streams.git", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Stream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple abstraction over streams of data", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "stream" + ], + "time": "2014-10-12 19:18:40" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10 12:19:37" + }, + { + "name": "react/promise", + "version": "v2.4.1", + "source": { + "type": "git", + "url": "https://github.com/reactphp/promise.git", + "reference": "8025426794f1944de806618671d4fa476dc7626f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/promise/zipball/8025426794f1944de806618671d4fa476dc7626f", + "reference": "8025426794f1944de806618671d4fa476dc7626f", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "React\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "time": "2016-05-03 17:50:52" + } + ], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-06-14 21:17:01" + }, + { + "name": "myclabs/deep-copy", + "version": "1.5.5", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "399c1f9781e222f6eb6cc238796f5200d1b7f108" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/399c1f9781e222f6eb6cc238796f5200d1b7f108", + "reference": "399c1f9781e222f6eb6cc238796f5200d1b7f108", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "doctrine/collections": "1.*", + "phpunit/phpunit": "~4.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "homepage": "https://github.com/myclabs/DeepCopy", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2016-10-31 17:19:45" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-12-27 11:43:31" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/type-resolver": "^0.2.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2016-09-30 07:12:33" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.2.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2016-11-25 06:54:22" + }, + { + "name": "phpspec/prophecy", + "version": "v1.6.2", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "6c52c2722f8460122f96f86346600e1077ce22cb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/6c52c2722f8460122f96f86346600e1077ce22cb", + "reference": "6c52c2722f8460122f96f86346600e1077ce22cb", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", + "sebastian/comparator": "^1.1", + "sebastian/recursion-context": "^1.0|^2.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.0", + "phpunit/phpunit": "^4.8 || ^5.6.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2016-11-21 14:58:47" + }, + { + "name": "phpunit/php-code-coverage", + "version": "4.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "6cba06ff75a1a63a71033e1a01b89056f3af1e8d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6cba06ff75a1a63a71033e1a01b89056f3af1e8d", + "reference": "6cba06ff75a1a63a71033e1a01b89056f3af1e8d", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "^1.4.2", + "sebastian/code-unit-reverse-lookup": "~1.0", + "sebastian/environment": "^1.3.2 || ^2.0", + "sebastian/version": "~1.0|~2.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "^5.4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.4.0", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2016-11-01 05:06:24" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2016-10-03 07:40:28" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21 13:50:34" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4|~5" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2016-05-12 18:03:57" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3b402f65a4cc90abf6e1104e388b896ce209631b", + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2016-11-15 14:06:22" + }, + { + "name": "phpunit/phpunit", + "version": "5.5.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "c7b3e1dcc1d183f26d5ba282881fe65c2cbb5b2b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c7b3e1dcc1d183f26d5ba282881fe65c2cbb5b2b", + "reference": "c7b3e1dcc1d183f26d5ba282881fe65c2cbb5b2b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "myclabs/deep-copy": "~1.3", + "php": "^5.6 || ^7.0", + "phpspec/prophecy": "^1.3.1", + "phpunit/php-code-coverage": "^4.0.1", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "^1.0.6", + "phpunit/phpunit-mock-objects": "^3.2", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "^1.3 || ^2.0", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/object-enumerator": "~1.0", + "sebastian/resource-operations": "~1.0", + "sebastian/version": "~1.0|~2.0", + "symfony/yaml": "~2.1|~3.0" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.5.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2016-08-05 04:49:02" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "3.4.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "90a08f5deed5f7ac35463c161f2e8fa0e5652faf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/90a08f5deed5f7ac35463c161f2e8fa0e5652faf", + "reference": "90a08f5deed5f7ac35463c161f2e8fa0e5652faf", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.6 || ^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^1.2 || ^2.0" + }, + "conflict": { + "phpunit/phpunit": "<5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2016-11-27 07:52:03" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/c36f5e7cfce482fde5bf8d10d41a53591e0198fe", + "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2016-02-13 06:45:14" + }, + { + "name": "sebastian/comparator", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "6a1ed12e8b2409076ab22e3897126211ff8b1f7f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/6a1ed12e8b2409076ab22e3897126211ff8b1f7f", + "reference": "6a1ed12e8b2409076ab22e3897126211ff8b1f7f", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2 || ~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2016-11-19 09:18:40" + }, + { + "name": "sebastian/diff", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-12-08 07:14:41" + }, + { + "name": "sebastian/environment", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2016-11-26 07:53:53" + }, + { + "name": "sebastian/exporter", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2016-06-17 09:04:28" + }, + { + "name": "sebastian/global-state", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2015-10-12 03:26:01" + }, + { + "name": "sebastian/object-enumerator", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "d4ca2fb70344987502567bc50081c03e6192fb26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/d4ca2fb70344987502567bc50081c03e6192fb26", + "reference": "d4ca2fb70344987502567bc50081c03e6192fb26", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2016-01-28 13:25:10" + }, + { + "name": "sebastian/recursion-context", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "913401df809e99e4f47b27cdd781f4a258d58791" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791", + "reference": "913401df809e99e4f47b27cdd781f4a258d58791", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2015-11-11 19:50:13" + }, + { + "name": "sebastian/resource-operations", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28 20:34:47" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03 07:35:21" + }, + { + "name": "symfony/yaml", + "version": "v3.1.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "9da375317228e54f4ea1b013b30fa47417e84943" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/9da375317228e54f4ea1b013b30fa47417e84943", + "reference": "9da375317228e54f4ea1b013b30fa47417e84943", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2016-11-18 21:05:29" + }, + { + "name": "webmozart/assert", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2016-11-23 20:04:58" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.4" + }, + "platform-dev": [] +} diff --git a/examples/change_settings.php b/examples/change_settings.php new file mode 100644 index 0000000..cb9431d --- /dev/null +++ b/examples/change_settings.php @@ -0,0 +1,24 @@ + + * @created 10.12.16 16:49 + */ + +use Yandex\Direct\Client; +use Yandex\Direct\Credentials; +use Yandex\Direct\Logger\EchoLog; + +$client = new Client(new Credentials('_LOGIN_', '_TOKEN_')); + +// Меняем логгер +$client->campaigns([ + 'transport' => '\\Yandex\\Direct\\Transport\\JsonTransport', + 'transportSettings' => [ + 'logger' => new EchoLog + ] +])->get(['Ids' => [123456, 654321]], ['Funds']); + +// Можно изменить доступы +$client->campaigns([ + 'transport' => new Credentials('agrom', '0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f') +])->get(['Ids' => [123456, 654321]], ['Funds']); \ No newline at end of file diff --git a/examples/custom_logger.php b/examples/custom_logger.php new file mode 100644 index 0000000..dfab8d8 --- /dev/null +++ b/examples/custom_logger.php @@ -0,0 +1,31 @@ + + * @created 07.11.16 12:45 + */ + +use Yandex\Direct\Client; +use Yandex\Direct\Credentials; +use Psr\Log\AbstractLogger; +use Yandex\Direct\Transport\JsonTransport; + +/** + * Simple psr-3 logger + * Class MyLogger + */ +class MyLogger extends AbstractLogger +{ + public function log($level, $message, array $context = array()) + { + echo "[$level] $message\n"; + } +} + +$transport = new JsonTransport; +$transport->setLogger(new MyLogger); + +$client = new Client(new Credentials('_LOGIN_', '_TOKEN_'), [ + 'transport' => $transport +]); + +$client->campaigns->get(['Ids' => [123456, 654321]], ['Status']); \ No newline at end of file diff --git a/examples/sandbox.php b/examples/sandbox.php new file mode 100644 index 0000000..3ce5f80 --- /dev/null +++ b/examples/sandbox.php @@ -0,0 +1,22 @@ + + * @created 10.12.16 16:10 + */ + +use Yandex\Direct\Client; +use Yandex\Direct\Credentials; +use Yandex\Direct\Logger\EchoLog; +use Yandex\Direct\Transport\JsonTransport; + +$credentials = new Credentials('_LOGIN_', '_TOKEN_'); + +$options['transport'] = new JsonTransport; +$options['transport']->setOptions([ + 'baseUrl' => 'https://api-sandbox.direct.yandex.com', + 'logger' => new EchoLog +]); + +$client = new Client($credentials, $options); + +$client->campaigns->get(['Ids' => [123456, 654321]], ['Funds']); \ No newline at end of file diff --git a/examples/simple.php b/examples/simple.php new file mode 100644 index 0000000..70f71cf --- /dev/null +++ b/examples/simple.php @@ -0,0 +1,28 @@ + + * @created 07.11.16 12:38 + */ + +use Psr\Log\NullLogger; +use Yandex\Direct\Client; +use Yandex\Direct\Credentials; + +// Создаем и инициализируем инстанс клиента +$client = new Client(new Credentials('_LOGIN_', '_TOKEN_')); + +// Вызовы сервисов и их методов очень удобны =) +$client->campaigns->get(['Ids' => [123456, 654321]], ['Funds']); + +// Есть множество способов переконфигурировать библиотеку, например так: +$client->campaigns([ + 'transport' => '\\Yandex\\Direct\\Transport\\JsonTransport', + 'transportSettings' => [ + 'logger' => new NullLogger + ] +])->get(['Ids' => [123456, 654321]], ['Funds']); + +// Можно изменить доступы +$client->campaigns([ + 'transport' => new Credentials('agrom', '0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f') +])->get(['Ids' => [123456, 654321]], ['Funds']); \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..bf7de20 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,20 @@ + + + + + ./tests + + + + + + ./src + + ./src/Exception + + + + diff --git a/src/Client.php b/src/Client.php new file mode 100644 index 0000000..f39bf1a --- /dev/null +++ b/src/Client.php @@ -0,0 +1,110 @@ + + * @date 17/08/2016 10:37 + */ + +namespace Yandex\Direct; + +use Yandex\Direct\Service\AdExtensions; +use Yandex\Direct\Service\AdGroups; +use Yandex\Direct\Service\AdImages; +use Yandex\Direct\Service\Ads; +use Yandex\Direct\Service\BidModifiers; +use Yandex\Direct\Service\Bids; +use Yandex\Direct\Service\Campaigns; +use Yandex\Direct\Service\Changes; +use Yandex\Direct\Service\Clients; +use Yandex\Direct\Service\Dictionaries; +use Yandex\Direct\Service\DynamicTextAdTargets; +use Yandex\Direct\Service\Keywords; +use Yandex\Direct\Service\RetargetingLists; +use Yandex\Direct\Service\Sitelinks; +use Yandex\Direct\Service\VCards; + + +/** + * Yandex.Direct v5 API client implementation + * + * @package Yandex\Direct + * + * Yandex Services + * @method AdExtensions adExtensions(array $options = []) + * @method AdGroups adGroups(array $options = []) + * @method AdImages adImages(array $options = []) + * @method Ads ads(array $options = []) + * @method BidModifiers bidModifiers(array $options = []) + * @method Bids bids(array $options = []) + * @method Campaigns campaigns(array $options = []) + * @method Clients clients(array $options = []) + * @method Changes changes(array $options = []) + * @method Dictionaries dictionaries(array $options = []) + * @method DynamicTextAdTargets dynamicTextAdsTargets(array $options = []) + * @method Keywords keywords(array $options = []) + * @method RetargetingLists retargetingLists(array $options = []) + * @method Sitelinks sitelinks(array $options = []) + * @method VCards vCards(array $options = []) + * + * Aliases (sugar) + * @property AdExtensions $adExtensions + * @property AdGroups $adGroups + * @property AdImages $adImages + * @property Ads $ads + * @property BidModifiers $bidModifiers + * @property Bids $bids + * @property Campaigns $campaigns + * @property Clients $clients + * @property Changes $changes + * @property Dictionaries $dictionaries + * @property DynamicTextAdTargets $dynamicTextAdsTargets + * @property Keywords $keywords + * @property RetargetingLists $retargetingLists + * @property Sitelinks $sitelinks + * @property VCards $vCards + */ +class Client +{ + /** + * @var ServiceFactory + */ + protected $factory; + + /** + * @param CredentialsInterface $credentials + * @param array $options + */ + public function __construct(CredentialsInterface $credentials, array $options = []) + { + $this->factory = new ServiceFactory; + $this->factory->setDefaultOptions(array_merge([ + 'credentials' => $credentials + ], $options)); + } + + /** + * @param string $name + * @param array $options + * @return Service + */ + public function __call($name, array $options = []) + { + return $this->factory->createService($name, current($options) ?: []); + } + + /** + * @param $name + * @return Service + */ + public function __get($name) + { + return $this->__call($name); + } + + /** + * @param array $options + */ + public function setOptions(array $options) + { + $this->factory->setDefaultOptions($options); + } +} \ No newline at end of file diff --git a/src/ConfigurableInterface.php b/src/ConfigurableInterface.php new file mode 100644 index 0000000..7226d03 --- /dev/null +++ b/src/ConfigurableInterface.php @@ -0,0 +1,17 @@ + + * @date 23/08/2016 14:42 + */ + +namespace Yandex\Direct; + + +interface ConfigurableInterface +{ + /** + * @param array $options + * @return void + */ + public function setOptions(array $options); +} \ No newline at end of file diff --git a/src/ConfigurableTrait.php b/src/ConfigurableTrait.php new file mode 100644 index 0000000..55b94a5 --- /dev/null +++ b/src/ConfigurableTrait.php @@ -0,0 +1,42 @@ + + * @date 17/08/2016 10:47 + */ + +namespace Yandex\Direct; + +use Yandex\Direct\Exception\InvalidArgumentException; + + +/** + * Class ConfigurableTrait + * @package Yandex\Direct + */ + +trait ConfigurableTrait +{ + public function setOptions(array $options, $ignoreMissingOptions = false) + { + foreach ($options as $option => $value) + { + $setter = 'set' . ucfirst($option); + + if (method_exists($this, $setter)) { + $this->$setter($value); + continue; + } + + if (property_exists($this, $option)) { + $this->$option = $value; + continue; + } + + if (!$ignoreMissingOptions) { + throw new InvalidArgumentException( + "Property `{$option}` not found in class `" . __CLASS__ . "`." + ); + } + } + } +} \ No newline at end of file diff --git a/src/Credentials.php b/src/Credentials.php new file mode 100644 index 0000000..76d3a83 --- /dev/null +++ b/src/Credentials.php @@ -0,0 +1,79 @@ + + * @date 16/08/2016 19:48 + */ + +namespace Yandex\Direct; + + +/** + * Class Credentials + * @package Yandex\Direct\Credentials + */ +final class Credentials implements CredentialsInterface +{ + /** + * @var string + */ + protected $token; + + /** + * @var string + */ + protected $masterToken; + + /** + * @var string + */ + protected $login; + + /** + * Credentials constructor. + * + * @param string $login + * @param string $token + * @param string $masterToken + */ + public function __construct($login = '', $token = '', $masterToken = '') + { + $this->login = $login; + $this->token = $token; + $this->masterToken = $masterToken; + } + + /** + * @return string + */ + public function getMasterToken() + { + return $this->masterToken; + } + + /** + * @return string + */ + public function getToken() + { + return $this->token; + } + + /** + * @return string + */ + public function getLogin() + { + return $this->login; + } + + /** + * @param string $login + * @param string $token + * @param string $masterToken + * @return Credentials + */ + static public function buildCredentials($login = '', $token = '', $masterToken = '') + { + return new self($login, $token, $masterToken); + } +} \ No newline at end of file diff --git a/src/CredentialsInterface.php b/src/CredentialsInterface.php new file mode 100644 index 0000000..a4c758f --- /dev/null +++ b/src/CredentialsInterface.php @@ -0,0 +1,32 @@ + + * @date 23/08/2016 18:25 + */ + +namespace Yandex\Direct; + + +/** + * Class CredentialsInterface + * @package Yandex\Direct\Credentials + */ +interface CredentialsInterface +{ + /** + * @return string + */ + public function getMasterToken(); + + + /** + * @return string + */ + public function getToken(); + + + /** + * @return string + */ + public function getLogin(); +} \ No newline at end of file diff --git a/src/Exception/ErrorResponseException.php b/src/Exception/ErrorResponseException.php new file mode 100644 index 0000000..470fb54 --- /dev/null +++ b/src/Exception/ErrorResponseException.php @@ -0,0 +1,50 @@ + + * @date 26/08/2016 14:24 + */ + +namespace Yandex\Direct\Exception; + + +/** + * Class ErrorResponseException + * @package Yandex\Direct\Exception + */ +class ErrorResponseException extends Exception +{ + /** + * @var int + */ + protected $requestId; + + /** + * @var string + */ + protected $details; + + /** + * @param string $message + * @param string $details + * @param int $code + * @param int $requestId + * @param \Exception $previous + */ + public function __construct($message, $details = '', $code = 0, $requestId = 0, \Exception $previous = null) + { + $this->details = $details; + $this->requestId = $requestId; + parent::__construct($message, $code, $previous); + } + + /** + * @return string + */ + public function __toString() + { + $str = 'Exception ' . __CLASS__ . " code {$this->code} with message '{$this->message}' in `{$this->file}`" . PHP_EOL; + $str .= 'Details: ' . $this->details . PHP_EOL; + $str .= 'Stack trace:' . PHP_EOL . $this->getTraceAsString(); + return $str; + } +} \ No newline at end of file diff --git a/src/Exception/Exception.php b/src/Exception/Exception.php new file mode 100644 index 0000000..11f1c5e --- /dev/null +++ b/src/Exception/Exception.php @@ -0,0 +1,11 @@ + + */ + +namespace Yandex\Direct\Exception; + + +class Exception extends \Exception +{ +} \ No newline at end of file diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php new file mode 100644 index 0000000..ee389dd --- /dev/null +++ b/src/Exception/InvalidArgumentException.php @@ -0,0 +1,11 @@ + + */ + +namespace Yandex\Direct\Exception; + + +class InvalidArgumentException extends Exception +{ +} \ No newline at end of file diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php new file mode 100644 index 0000000..7067e0b --- /dev/null +++ b/src/Exception/RuntimeException.php @@ -0,0 +1,11 @@ + + */ + +namespace Yandex\Direct\Exception; + + +class RuntimeException extends Exception +{ +} \ No newline at end of file diff --git a/src/Exception/TransportRequestException.php b/src/Exception/TransportRequestException.php new file mode 100644 index 0000000..2f3ef5c --- /dev/null +++ b/src/Exception/TransportRequestException.php @@ -0,0 +1,89 @@ + + * @date 17/08/2016 13:16 + */ + +namespace Yandex\Direct\Exception; + + +/** + * Class TransportRequestException + * @package Yandex\Direct\Exception + */ +class TransportRequestException extends RuntimeException +{ + /** + * @var string + */ + protected $requestHeaders; + + /** + * @var string + */ + protected $requestBody; + + /** + * @var string + */ + protected $responseHeaders; + + /** + * @var string + */ + protected $responseBody; + + /** + * TransportRequestException constructor. + * + * @param string $message + * @param int $code + * @param array $requestHeaders + * @param string $requestBody + * @param array $responseHeaders + * @param string $responseBody + * @param \Exception|null|Exception $previous + */ + public function __construct($message, $code, $requestHeaders = [], $requestBody = '', + $responseHeaders = [], $responseBody = '', \Exception $previous = null) + { + $this->requestBody = $requestBody; + $this->requestHeaders = $requestHeaders; + $this->responseBody = $responseBody; + $this->responseHeaders = $responseHeaders; + + parent::__construct($message, $code, $previous); + } + + /** + * @return string + */ + public function getRequestHeaders() + { + return $this->requestHeaders; + } + + /** + * @return string + */ + public function getRequestBody() + { + return $this->requestBody; + } + + /** + * @return string + */ + public function getResponseHeaders() + { + return $this->responseHeaders; + } + + /** + * @return string + */ + public function getResponseBody() + { + return $this->responseBody; + } +} \ No newline at end of file diff --git a/src/Logger/EchoLog.php b/src/Logger/EchoLog.php new file mode 100644 index 0000000..1ce6100 --- /dev/null +++ b/src/Logger/EchoLog.php @@ -0,0 +1,25 @@ + + * @created 02.11.16 13:52 + */ + +namespace Yandex\Direct\Logger; + + +use Psr\Log\AbstractLogger; +use Psr\Log\LoggerInterface; + +class EchoLog extends AbstractLogger +{ + /** + * @param string $level + * @param string $message + * @param array $context + */ + public function log($level, $message, array $context = []) + { + echo date("Y/m/d H:i:s") . " [{$level}] " . $message . PHP_EOL; + } + +} \ No newline at end of file diff --git a/src/Logger/YiiLog.php b/src/Logger/YiiLog.php new file mode 100644 index 0000000..b8e2d3d --- /dev/null +++ b/src/Logger/YiiLog.php @@ -0,0 +1,63 @@ + + * @created 02.11.16 14:29 + */ + +namespace Yandex\Direct\Logger; + +use Yii; +use Psr\Log\AbstractLogger; +use Psr\Log\LogLevel; + +/** + * Class YiiLog. Works with Yii-framework environment only. + * + * @package Yandex\Direct\Logger + */ +class YiiLog extends AbstractLogger +{ + /** + * @var string + */ + private $category = ''; + + /** + * YiiLog constructor. + * @param string $category + */ + public function __construct($category = 'app') + { + $this->category = $category; + } + + /** + * @param mixed $level + * @param string $message + * @param array $context + */ + public function log($level, $message, array $context = []) + { + Yii::log($message, $this->mapLevel($level), $this->category); + } + + /** + * @param $level + * @return mixed + */ + protected function mapLevel($level) + { + $map = [ + LogLevel::DEBUG => 'trace', + LogLevel::WARNING => 'warning', + LogLevel::ERROR => 'error', + LogLevel::CRITICAL => 'error', + LogLevel::NOTICE => 'warning', + LogLevel::EMERGENCY => 'warning', + LogLevel::ALERT => 'warning', + LogLevel::INFO => 'info' + ]; + + return isset($map[$level]) ? $map[$level] : $level; + } +} \ No newline at end of file diff --git a/src/Service.php b/src/Service.php new file mode 100644 index 0000000..3522a8c --- /dev/null +++ b/src/Service.php @@ -0,0 +1,113 @@ + + * @date 17/08/2016 11:28 + */ + +namespace Yandex\Direct; + +use Yandex\Direct\Exception\ErrorResponseException; +use Yandex\Direct\Transport\TransportInterface; +use Yandex\Direct\Transport\TransportRequest; +use Yandex\Direct\Transport\TransportResponse; + + +/** + * Class Service + * @package Yandex\Direct + */ +abstract class Service implements ConfigurableInterface +{ + use ConfigurableTrait; + + /** + * @var string + */ + protected $name; + + /** + * @var TransportInterface + */ + protected $transport; + + /** + * @var Credentials + */ + protected $credentials; + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @param TransportInterface $transport + */ + public function setTransport($transport) + { + $this->transport = $transport; + } + + /** + * @param Credentials $credentials + */ + public function setCredentials($credentials) + { + $this->credentials = $credentials; + } + + /** + * @param TransportResponse $response + * @throws ErrorResponseException + */ + protected static function handleErrorResponse(TransportResponse $response) + { + $json = json_decode($response->getBody(), true); + + if (isset($json['error']) + && $json['error'] + ) { + throw new ErrorResponseException( + $json['error']['error_string'], + $json['error']['error_detail'], + $json['error']['error_code'], + $json['error']['request_id'] + ); + } + } + + /** + * Do API request with needle headers + * + * @param array $params + * @param bool $useOperatorUnits + * @param array $headers + * @return mixed + */ + public function request(array $params, $useOperatorUnits = true, $headers = []) + { + $response = $this->transport->request(new TransportRequest([ + 'service' => $this->name, + 'credentials' => $this->credentials, + 'params' => $params, + 'headers' => $headers, + 'useOperatorUnits' => $useOperatorUnits + ])); + + self::handleErrorResponse($response); + + $result = json_decode($response->getBody(), true); + + $result['units'] = [ + 'debit' => $response->getUnitsDebit(), + 'limit' => $response->getUnitsLimit(), + 'rest' => $response->getUnitsRest() + ]; + + return $result; + } + +} \ No newline at end of file diff --git a/src/Service/AdExtensions.php b/src/Service/AdExtensions.php new file mode 100644 index 0000000..83b5a11 --- /dev/null +++ b/src/Service/AdExtensions.php @@ -0,0 +1,82 @@ + + * @date 23/08/2016 15:16 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class AdExtensions + * @package Yandex\Direct\Service + */ +final class AdExtensions extends Service +{ + /** + * Создает расширения. + * + * @param $AdExtensions + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/adextensions/add-docpage/ + */ + public function add($AdExtensions) + { + return $this->request([ + 'method' => 'add', + 'params' => [ + 'AdExtensions' => $AdExtensions + ] + ]); + } + + /** + * Удаляет расширения. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/adextensions/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Возвращает расширения, отвечающие заданным критериям. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $CalloutFieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/adextensions/get-docpage/ + */ + public function get($SelectionCriteria, $FieldNames, $CalloutFieldNames = null, $Page = null) + { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames, + ]; + + if ($CalloutFieldNames) { + $params['CalloutFieldNames'] = $CalloutFieldNames; + } + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } +} \ No newline at end of file diff --git a/src/Service/AdGroups.php b/src/Service/AdGroups.php new file mode 100644 index 0000000..f67e2a0 --- /dev/null +++ b/src/Service/AdGroups.php @@ -0,0 +1,114 @@ + + * @date 22/08/2016 16:05 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class AdGroups + * @package Yandex\Direct\Service + */ +final class AdGroups extends Service +{ + /** + * Создает группы объявлений. + * + * @param $AdGroups + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/adgroups/add-docpage/ + */ + public function add($AdGroups) + { + return $this->request([ + 'method' => 'add', + 'params' => [ + 'AdGroups' => $AdGroups + ] + ]); + } + + /** + * Удаляет группы объявлений. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/adgroups/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Возвращает параметры групп, отвечающих заданным критериям. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $MobileAppAdGroupFieldNames + * @param $DynamicTextAdGroupFieldNames + * @param $DynamicTextFeedAdGroupFieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/adgroups/delete-docpage/ + */ + public function get($SelectionCriteria, + $FieldNames, + $MobileAppAdGroupFieldNames = null, + $DynamicTextAdGroupFieldNames = null, + $DynamicTextFeedAdGroupFieldNames = null, + $Page = null + ) { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames + ]; + + if ($MobileAppAdGroupFieldNames) { + $params['MobileAppAdGroupFieldNames'] = $MobileAppAdGroupFieldNames; + } + + if ($DynamicTextAdGroupFieldNames) { + $params['DynamicTextAdGroupFieldNames'] = $DynamicTextAdGroupFieldNames; + } + + if ($DynamicTextFeedAdGroupFieldNames) { + $params['DynamicTextFeedAdGroupFieldNames'] = $DynamicTextFeedAdGroupFieldNames; + } + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } + + /** + * Изменяет параметры групп объявлений. + * + * @param $AdGroups + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/adgroups/update-docpage/ + */ + public function update($AdGroups) + { + return $this->request([ + 'method' => 'update', + 'params' => [ + 'AdGroups' => $AdGroups + ] + ]); + } +} \ No newline at end of file diff --git a/src/Service/AdImages.php b/src/Service/AdImages.php new file mode 100644 index 0000000..8138299 --- /dev/null +++ b/src/Service/AdImages.php @@ -0,0 +1,77 @@ + + * @date 26/08/2016 13:44 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class AdImages + * @package Yandex\Direct\Service + */ +final class AdImages extends Service +{ + /** + * Выполняет синхронную загрузку изображений в виде бинарных данных. + * + * @param $AdImages + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/adimages/add-docpage/ + */ + public function add($AdImages) + { + return $this->request([ + 'method' => 'add', + 'params' => [ + 'AdImages' => $AdImages + ] + ]); + } + + /** + * Удаляет изображения. + * + * @param $SelectionCriteria + * @return mixed + * @see https://tech.yandex.ru/direct/doc/ref-v5/adimages/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Возвращает изображения, отвечающие заданным критериям. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/adimages/get-docpage/ + */ + public function get($SelectionCriteria, $FieldNames, $Page = null) + { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames, + ]; + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } +} \ No newline at end of file diff --git a/src/Service/Ads.php b/src/Service/Ads.php new file mode 100644 index 0000000..6b633ac --- /dev/null +++ b/src/Service/Ads.php @@ -0,0 +1,196 @@ + + * @date 26/08/2016 13:51 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class Ads + * @package Yandex\Direct\Service + */ +final class Ads extends Service +{ + /** + * @param $Ads + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/ads/add-docpage/ + */ + public function add($Ads) + { + return $this->request([ + 'method' => 'add', + 'params' => [ + 'Ads' => $Ads + ] + ]); + } + + /** + * @param $Ads + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/ads/update-docpage/ + */ + public function update($Ads) + { + return $this->request([ + 'method' => 'update', + 'params' => [ + 'Ads' => $Ads + ] + ]); + } + + /** + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/ads/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria /* IdsCriteria */ + ] + ]); + } + + /** + * @param $SelectionCriteria + * @return array + * https://tech.yandex.ru/direct/doc/ref-v5/ads/suspend-docpage/ + */ + public function suspend($SelectionCriteria) + { + return $this->request([ + 'method' => 'suspend', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria /* IdsCriteria */ + ] + ]); + } + + /** + * @param $SelectionCriteria + * @return array + * https://tech.yandex.ru/direct/doc/ref-v5/ads/resume-docpage/ + */ + public function resume($SelectionCriteria) + { + return $this->request([ + 'method' => 'resume', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria /* IdsCriteria */ + ] + ]); + } + + /** + * @param $SelectionCriteria + * @return array + * https://tech.yandex.ru/direct/doc/ref-v5/ads/archive-docpage/ + */ + public function archive($SelectionCriteria) + { + return $this->request([ + 'method' => 'archive', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria /* IdsCriteria */ + ] + ]); + } + + /** + * @param $SelectionCriteria + * @return array + * https://tech.yandex.ru/direct/doc/ref-v5/ads/unarchive-docpage/ + */ + public function unarchive($SelectionCriteria) + { + return $this->request([ + 'method' => 'unarchive', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria /* IdsCriteria */ + ] + ]); + } + + /** + * @param $SelectionCriteria + * @return array + * https://tech.yandex.ru/direct/doc/ref-v5/ads/moderate-docpage/ + */ + public function moderate($SelectionCriteria) + { + return $this->request([ + 'method' => 'moderate', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria /* IdsCriteria */ + ] + ]); + } + + + /** + * Возвращает параметры объявлений, отвечающих заданным критериям. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $TextAdFieldNames + * @param $MobileAppAdFieldNames + * @param $DynamicTextAdFieldNames + * @param $TextImageAdFieldNames + * @param $MobileAppImageAdFieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/ads/get-docpage/ + */ + public function get($SelectionCriteria, + $FieldNames, + $TextAdFieldNames = null, + $MobileAppAdFieldNames = null, + $DynamicTextAdFieldNames = null, + $TextImageAdFieldNames = null, + $MobileAppImageAdFieldNames = null, + $Page = null + ) { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, /* AdsSelectionCriteria */ + 'FieldNames' => $FieldNames + ]; + + if ($TextAdFieldNames) { + $params['TextAdFieldNames'] = $TextAdFieldNames; + } + + if ($MobileAppAdFieldNames) { + $params['MobileAppAdFieldNames'] = $MobileAppAdFieldNames; + } + + if ($DynamicTextAdFieldNames) { + $params['DynamicTextAdFieldNames'] = $DynamicTextAdFieldNames; + } + + if ($TextImageAdFieldNames) { + $params['TextImageAdFieldNames'] = $TextImageAdFieldNames; + } + + if ($MobileAppImageAdFieldNames) { + $params['MobileAppImageAdFieldNames'] = $MobileAppImageAdFieldNames; + } + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } +} \ No newline at end of file diff --git a/src/Service/AudienceTargets.php b/src/Service/AudienceTargets.php new file mode 100644 index 0000000..5297a82 --- /dev/null +++ b/src/Service/AudienceTargets.php @@ -0,0 +1,128 @@ + + * @created 08.12.16 16:07 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class AudienceTargets + * @package Yandex\Direct\Service + */ +class AudienceTargets extends Service +{ + /** + * Создает условия нацеливания на аудиторию, назначает ставки и приоритеты для создаваемых ретаргетингов. + * + * @param $AudienceTargets + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/audiencetargets/add-docpage/ + */ + public function add($AudienceTargets) + { + return $this->request([ + 'method' => 'add', + 'params' => [ + 'AudienceTargets' => $AudienceTargets + ] + ]); + } + + /** + * Удаляет условия нацеливания на аудиторию. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/audiencetargets/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Возвращает параметры условий нацеливания на аудиторию. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/audiencetargets/get-docpage/ + */ + public function get($SelectionCriteria, $FieldNames, $Page = null) + { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames, + ]; + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } + + /** + * Возобновляет показы по ранее остановленным условиям нацеливания на аудиторию. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/audiencetargets/resume-docpage/ + */ + public function resume($SelectionCriteria) + { + return $this->request([ + 'method' => 'resume', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Назначает ставки и приоритеты для условий нацеливания на аудиторию. + * + * @param $Bids + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/audiencetargets/setBids-docpage/ + */ + public function setBids($Bids) + { + return $this->request([ + 'method' => 'setBids', + 'params' => [ + 'Bids' => $Bids + ] + ]); + } + + /** + * Останавливает показы по условиям нацеливания на аудиторию. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/audiencetargets/suspend-docpage/ + */ + public function suspend($SelectionCriteria) + { + return $this->request([ + 'method' => 'suspend', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } +} \ No newline at end of file diff --git a/src/Service/BidModifiers.php b/src/Service/BidModifiers.php new file mode 100644 index 0000000..6616aba --- /dev/null +++ b/src/Service/BidModifiers.php @@ -0,0 +1,132 @@ + + * @date 29/08/2016 12:33 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class BidModifiers + * @package Yandex\Direct\Service + */ +final class BidModifiers extends Service +{ + /** + * Создает корректировки ставок. + * + * @param $BidModifiers + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/bidmodifiers/add-docpage/ + */ + public function add($BidModifiers) + { + return $this->request([ + 'method' => 'add', + 'params' => [ + 'BidModifiers' => $BidModifiers + ] + ]); + } + + /** + * Удаляет корректировки ставок. + * + * @param $SelectionCriteria + * @return mixed + * @see https://tech.yandex.ru/direct/doc/ref-v5/bidmodifiers/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria /* IdsCriteria */ + ] + ]); + } + + /** + * Возвращает параметры корректировок, отвечающих заданным критериям. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $MobileAdjustmentFieldNames + * @param $DemographicsAdjustmentFieldNames + * @param $RetargetingAdjustmentFieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/bidmodifiers/get-docpage/ + */ + public function get($SelectionCriteria, + $FieldNames, + $MobileAdjustmentFieldNames = null, + $DemographicsAdjustmentFieldNames = null, + $RetargetingAdjustmentFieldNames = null, + $Page = null + + ) { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames + ]; + + if ($MobileAdjustmentFieldNames) { + $params['MobileAdjustmentFieldNames'] = $MobileAdjustmentFieldNames; + } + + if ($DemographicsAdjustmentFieldNames) { + $params['DemographicsAdjustmentFieldNames'] = $DemographicsAdjustmentFieldNames; + } + + if ($RetargetingAdjustmentFieldNames) { + $params['RetargetingAdjustmentFieldNames'] = $RetargetingAdjustmentFieldNames; + } + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } + + /** + * Изменяет значения коэффициентов в корректировках ставок. + * + * @param $BidModifiers + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/bidmodifiers/set-docpage/ + */ + public function setAuto($BidModifiers) + { + return $this->request([ + 'method' => 'setAuto', + 'params' => [ + 'BidModifiers' => $BidModifiers + ] + ]); + } + + /** + * Включает/выключает набор корректировок. + * + * @param $BidModifierToggleItems + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/bidmodifiers/toggle-docpage/ + */ + public function toggle($BidModifierToggleItems) + { + return $this->request([ + 'method' => 'toggle', + 'params' => [ + 'BidModifierToggleItems' => $BidModifierToggleItems + ] + ]); + } +} \ No newline at end of file diff --git a/src/Service/Bids.php b/src/Service/Bids.php new file mode 100644 index 0000000..9253e59 --- /dev/null +++ b/src/Service/Bids.php @@ -0,0 +1,79 @@ + + * @date 29/08/2016 12:32 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class Bids + * @package Yandex\Direct\Service + */ +final class Bids extends Service +{ + /** + * Назначает фиксированные ставки и приоритеты для ключевых фраз. + * + * @param $Bids + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/bids/set-docpage/ + */ + public function set($Bids) + { + return $this->request([ + 'method' => 'set', + 'params' => [ + 'Bids' => $Bids + ] + ]); + } + + /** + * Конструктор ставок — рассчитывает ставки для фраз по заданному алгоритму. + * + * @param $Bids + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/bids/setAuto-docpage/ + */ + public function setAuto($Bids) + { + return $this->request([ + 'method' => 'setAuto', + 'params' => [ + 'Bids' => $Bids + ] + ]); + } + + /** + * Возвращает ставки и приоритеты для ключевых фраз, отвечающих заданным критериям, а также данные, + * полезные при подборе ставок: данные аукциона по позициям показа на поиске и ставки для охвата различных + * долей аудитории в сетях. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/bids/get-docpage/ + */ + public function get($SelectionCriteria, $FieldNames, $Page = null) + { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames, + ]; + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } +} \ No newline at end of file diff --git a/src/Service/Campaigns.php b/src/Service/Campaigns.php new file mode 100644 index 0000000..2f56566 --- /dev/null +++ b/src/Service/Campaigns.php @@ -0,0 +1,173 @@ + + * @date 26/08/2016 14:03 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class Campaigns + * @package Yandex\Direct\Service + */ +final class Campaigns extends Service +{ + + /** + * @param array $Campaigns + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/add-docpage/ + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/add-text-campaign-docpage/ + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/add-dynamic-text-campaign-docpage/ + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/add-mobile-app-campaign-docpage/ + */ + public function add($Campaigns) + { + return $this->request([ + 'method' => 'add', + 'params' => [ + 'Campaigns' => $Campaigns + ] + ]); + } + + /** + * @param array $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/archive-docpage/ + */ + public function archive($SelectionCriteria) + { + return $this->request([ + 'method' => 'archive', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * @param array $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * @param array $SelectionCriteria + * @param array $FieldNames + * @param array $TextCampaignFieldNames + * @param array $MobileAppCampaignFieldNames + * @param array $DynamicTextCampaignFieldNames + * @param array $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/get-docpage/ + */ + public function get($SelectionCriteria, + $FieldNames, + $TextCampaignFieldNames = null, + $MobileAppCampaignFieldNames = null, + $DynamicTextCampaignFieldNames = null, + $Page = null + ) { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames, + ]; + + if ($TextCampaignFieldNames) { + $params['TextCampaignFieldNames'] = $TextCampaignFieldNames; + } + + if ($MobileAppCampaignFieldNames) { + $params['MobileAppCampaignFieldNames'] = $MobileAppCampaignFieldNames; + } + + if ($DynamicTextCampaignFieldNames) { + $params['DynamicTextCampaignFieldNames'] = $DynamicTextCampaignFieldNames; + } + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } + + /** + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/resume-docpage/ + */ + public function resume($SelectionCriteria) + { + return $this->request([ + 'method' => 'resume', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * @param array $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/suspend-docpage/ + */ + public function suspend($SelectionCriteria) + { + return $this->request([ + 'method' => 'suspend', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * @param array $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/unarchive-docpage/ + */ + public function unarchive($SelectionCriteria) + { + return $this->request([ + 'method' => 'unarchive', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * @param array $Campaigns + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/update-docpage/ + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/update-text-campaign-docpage/ + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/update-dynamic-text-campaign-docpage/ + * @see https://tech.yandex.ru/direct/doc/ref-v5/campaigns/update-mobile-app-campaign-docpage/ + */ + public function update($Campaigns) + { + return $this->request([ + 'method' => 'update', + 'params' => [ + 'Campaigns' => $Campaigns + ] + ]); + } +} \ No newline at end of file diff --git a/src/Service/Changes.php b/src/Service/Changes.php new file mode 100644 index 0000000..d7f1a51 --- /dev/null +++ b/src/Service/Changes.php @@ -0,0 +1,88 @@ + + * @date 29/08/2016 12:33 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class Changes + * @package Yandex\Direct\Service + */ +final class Changes extends Service +{ + /** + * Сообщает о наличии изменений в справочниках часовых поясов и регионов начиная с указанной даты. + * Также используется для получения текущего серверного времени. + * + * @param $Timestamp + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/changes/checkDictionaries-docpage/ + */ + public function checkDictionaries($Timestamp) + { + return $this->request([ + 'method' => 'checkDictionaries', + 'params' => [ + 'Timestamp' => $Timestamp + ] + ]); + } + + /** + * Сообщает о наличии изменений в кампаниях клиента начиная с указанной даты. + * + * @param $Timestamp + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/changes/checkCampaigns-docpage/ + */ + public function checkCampaigns($Timestamp) + { + return $this->request([ + 'method' => 'checkCampaigns', + 'params' => [ + 'Timestamp' => $Timestamp + ] + ]); + } + + /** + * Сообщает о наличии изменений в кампаниях, группах и объявлениях клиента начиная с указанной даты. + * + * @param $Timestamp + * @param $FieldNames + * @param $CampaignIds + * @param $AdGroupIds + * @param $AdIds + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/changes/check-docpage/ + */ + public function check($Timestamp, $FieldNames, $CampaignIds = null, $AdGroupIds = null, $AdIds = null) + { + $params = [ + 'Timestamp' => $Timestamp, + 'FieldNames' => $FieldNames + ]; + + if ($CampaignIds) { + $params['CampaignIds'] = $CampaignIds; + } + + if ($AdGroupIds) { + $params['AdGroupIds'] = $AdGroupIds; + } + + if ($AdIds) { + $params['AdIds'] = $AdIds; + } + + return $this->request([ + 'method' => 'check', + 'params' => $params + ]); + } +} \ No newline at end of file diff --git a/src/Service/Clients.php b/src/Service/Clients.php new file mode 100644 index 0000000..7b08940 --- /dev/null +++ b/src/Service/Clients.php @@ -0,0 +1,34 @@ + + * @created 29.11.16 14:09 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class Clients + * @package Yandex\Direct\Service + */ +final class Clients extends Service +{ + /** + * Возвращает параметры рекламодателя и представителя. + * + * @param array $FieldNames + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/clients/get-docpage/ + */ + public function get($FieldNames) + { + return $this->request([ + 'method' => 'get', + 'params' => [ + 'FieldNames' => $FieldNames + ] + ]); + } +} \ No newline at end of file diff --git a/src/Service/Dictionaries.php b/src/Service/Dictionaries.php new file mode 100644 index 0000000..d86eb5a --- /dev/null +++ b/src/Service/Dictionaries.php @@ -0,0 +1,35 @@ + + * @date 29/08/2016 12:33 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class Dictionaries + * @package Yandex\Direct\Service + */ +final class Dictionaries extends Service +{ + /** + * Возвращает справочные данные: регионы, часовые пояса, курсы валют, список станций метрополитена, + * ограничения на значения параметров, внешние сети (SSP) и др. + * + * @param $DictionaryNames + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/dictionaries/get-docpage/ + */ + public function get($DictionaryNames) + { + return $this->request([ + 'method' => 'get', + 'params' => [ + 'DictionaryNames' => $DictionaryNames + ] + ]); + } +} \ No newline at end of file diff --git a/src/Service/DynamicTextAdTargets.php b/src/Service/DynamicTextAdTargets.php new file mode 100644 index 0000000..1049129 --- /dev/null +++ b/src/Service/DynamicTextAdTargets.php @@ -0,0 +1,129 @@ + + * @date 29/08/2016 12:34 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class DynamicTextAdTargets + * @package Yandex\Direct\Service + */ +final class DynamicTextAdTargets extends Service +{ + /** + * Создает условия нацеливания для динамических объявлений, + * назначает ставки или приоритеты для создаваемых условий. + * + * @param $Webpages + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/dynamictextadtargets/add-docpage/ + */ + public function add($Webpages) + { + return $this->request([ + 'method' => 'add', + 'params' => [ + 'Webpages' => $Webpages + ] + ]); + } + + /** + * Удаляет условия нацеливания для динамических объявлений. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/dynamictextadtargets/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Возвращает параметры условий нацеливания для динамических объявлений. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/dynamictextadtargets/get-docpage/ + */ + public function get($SelectionCriteria, $FieldNames, $Page = null) + { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames, + ]; + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } + + /** + * Возобновляет показы по ранее остановленным условиям нацеливания для динамических объявлений. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/dynamictextadtargets/resume-docpage/ + */ + public function resume($SelectionCriteria) + { + return $this->request([ + 'method' => 'resume', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Назначает ставки и приоритеты для условий нацеливания для динамических объявлений. + * + * @param $Bids + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/dynamictextadtargets/setBids-docpage/ + */ + public function setBids($Bids) + { + return $this->request([ + 'method' => 'setBids', + 'params' => [ + 'Bids' => $Bids + ] + ]); + } + + /** + * Останавливает показы по условиям нацеливания для динамических объявлений. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/dynamictextadtargets/suspend-docpage/ + */ + public function suspend($SelectionCriteria) + { + return $this->request([ + 'method' => 'suspend', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } +} \ No newline at end of file diff --git a/src/Service/Keywords.php b/src/Service/Keywords.php new file mode 100644 index 0000000..9279d1a --- /dev/null +++ b/src/Service/Keywords.php @@ -0,0 +1,129 @@ + + * @date 29/08/2016 12:34 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class Keywords + * @package Yandex\Direct\Service + */ +final class Keywords extends Service +{ + /** + * Создает ключевые фразы. + * + * @param $Keywords + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/keywords/add-docpage/ + */ + public function add($Keywords) + { + return $this->request([ + 'method' => 'add', + 'params' => [ + 'Keywords' => $Keywords + ] + ]); + } + + /** + * Удаляет ключевые фразы. + * + * @param $SelectionCriteria + * @return mixed + * @see https://tech.yandex.ru/direct/doc/ref-v5/keywords/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Возвращает параметры ключевых фраз, отвечающих заданным критериям: значения подстановочных переменных, + * статус и состояние, продуктивность, статистику показов и кликов, ставки и приоритеты. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/keywords/get-docpage/ + */ + public function get($SelectionCriteria, $FieldNames, $Page = null) + { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames + ]; + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } + + /** + * Возобновляет показы по ранее остановленным ключевым фразам. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/keywords/resume-docpage/ + */ + public function resume($SelectionCriteria) + { + return $this->request([ + 'method' => 'resume', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Останавливает показы по ключевым фразам. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/keywords/suspend-docpage/ + */ + public function suspend($SelectionCriteria) + { + return $this->request([ + 'method' => 'suspend', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Изменяет параметры фраз. + * + * @param $Keywords + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/keywords/update-docpage/ + */ + public function update($Keywords) + { + return $this->request([ + 'method' => 'update', + 'params' => [ + 'Keywords' => $Keywords + ] + ]); + } +} \ No newline at end of file diff --git a/src/Service/RetargetingLists.php b/src/Service/RetargetingLists.php new file mode 100644 index 0000000..dd25081 --- /dev/null +++ b/src/Service/RetargetingLists.php @@ -0,0 +1,96 @@ + + * @created 03.12.16 15:26 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class RetargetingLists + * @package Yandex\Direct\Service + */ +class RetargetingLists extends Service +{ + /** + * Создает условия подбора аудитории. + * + * @param $RetargetingLists + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/retargetinglists/add-docpage/ + */ + public function add($RetargetingLists) + { + return $this->request([ + 'method' => 'get', + 'params' => [ + 'RetargetingLists' => $RetargetingLists + ] + ]); + } + + /** + * Удаляет условия подбора аудитории. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/retargetinglists/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Возвращает условия подбора аудитории. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/retargetinglists/get-docpage/ + */ + public function get($SelectionCriteria, $FieldNames, $Page = null) + { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames, + ]; + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } + + /** + * Изменяет параметры условий подбора аудитории. + * + * @param $RetargetingLists + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/retargetinglists/update-docpage/ + */ + public function update($RetargetingLists) + { + return $this->request([ + 'method' => 'update', + 'params' => [ + 'RetargetingLists' => $RetargetingLists + ] + ]); + } + + +} \ No newline at end of file diff --git a/src/Service/Sitelinks.php b/src/Service/Sitelinks.php new file mode 100644 index 0000000..d339a8a --- /dev/null +++ b/src/Service/Sitelinks.php @@ -0,0 +1,76 @@ + + * @date 29/08/2016 12:34 + */ + +namespace Yandex\Direct\Service; + +use Yandex\Direct\Service; + +/** + * Class Sitelinks + * @package Yandex\Direct\Service + */ +final class Sitelinks extends Service +{ + /** + * Создает наборы быстрых ссылок. + * + * @param SitelinksSets + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/sitelinks/add-docpage/ + */ + public function add($SitelinksSets) + { + return $this->request([ + 'method' => 'add', + 'params' => [ + 'SitelinksSets' => $SitelinksSets + ] + ]); + } + + /** + * Удаляет наборы быстрых ссылок. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/sitelinks/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Возвращает наборы быстрых ссылок, отвечающие заданным критериям. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/sitelinks/get-docpage/ + */ + public function get($SelectionCriteria, $FieldNames, $Page = null) + { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames, + ]; + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } +} \ No newline at end of file diff --git a/src/Service/VCards.php b/src/Service/VCards.php new file mode 100644 index 0000000..b6a0b6a --- /dev/null +++ b/src/Service/VCards.php @@ -0,0 +1,77 @@ + + * @date 29/08/2016 12:35 + */ + +namespace Yandex\Direct\Service; + + +use Yandex\Direct\Service; + +/** + * Class VCards + * @package Yandex\Direct\Service + */ +final class VCards extends Service +{ + /** + * Создает виртуальные визитки. + * + * @param $VCards + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/vcards/add-docpage/ + */ + public function add($VCards) + { + return $this->request([ + 'method' => 'add', + 'params' => [ + 'VCards' => $VCards + ] + ]); + } + + /** + * Удаляет виртуальные визитки. + * + * @param $SelectionCriteria + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/vcards/delete-docpage/ + */ + public function delete($SelectionCriteria) + { + return $this->request([ + 'method' => 'delete', + 'params' => [ + 'SelectionCriteria' => $SelectionCriteria + ] + ]); + } + + /** + * Возвращает виртуальные визитки, отвечающие заданным критериям. + * + * @param $SelectionCriteria + * @param $FieldNames + * @param $Page + * @return array + * @see https://tech.yandex.ru/direct/doc/ref-v5/vcards/get-docpage/ + */ + public function get($SelectionCriteria, $FieldNames, $Page = null) + { + $params = [ + 'SelectionCriteria' => $SelectionCriteria, + 'FieldNames' => $FieldNames, + ]; + + if ($Page) { + $params['Page'] = $Page; + } + + return $this->request([ + 'method' => 'get', + 'params' => $params + ]); + } +} \ No newline at end of file diff --git a/src/ServiceFactory.php b/src/ServiceFactory.php new file mode 100644 index 0000000..a381cf0 --- /dev/null +++ b/src/ServiceFactory.php @@ -0,0 +1,114 @@ + + * @date 23/08/2016 13:42 + */ + +namespace Yandex\Direct; + +use Yandex\Direct\Exception\InvalidArgumentException; +use Yandex\Direct\Transport\TransportInterface; + + +/** + * Class ServiceFactory + * + * @package Yandex\Direct + */ +class ServiceFactory +{ + const E_INVALID_NAME = 1; + const E_INVALID_OPTION = 2; + + /** + * Default Service options + * + * @var array + */ + protected $defaultOptions = [ + 'transport' => 'Yandex\\Direct\\Transport\\JsonTransport', + 'transportOptions' => [], + 'credentials' => null + ]; + + /** + * Set default service options + * + * @param array $options + */ + public function setDefaultOptions(array $options) + { + $this->defaultOptions = array_merge($this->defaultOptions, $options); + } + + /** + * @param $serviceName + * @param array $options + * @return mixed + * @throws InvalidArgumentException + */ + public function createService($serviceName, array $options = []) + { + $className = $this->getServiceNamespace() . '\\' . ucfirst($serviceName); + + // Override service base options + $options = array_merge($this->defaultOptions, [ + 'name' => $serviceName + ], $options); + + + // Prepare service options + if (is_string($options['transport'])) { + $options['transport'] = $this->buildTransport($options['transport'], $options['transportOptions']); + } + + unset($options['transportOptions']); + + if (class_exists($className)) { + $instance = new $className($serviceName); + if (!$instance instanceof Service) { + throw new InvalidArgumentException( + "Service class `{$className}` is not instance of `Yandex\\Direct\\Service`.", self::E_INVALID_NAME + ); + } + $instance->setOptions($options); + return $instance; + } + + throw new InvalidArgumentException("Service class `{$className}` is not found.", self::E_INVALID_NAME); + } + + /** + * @param string $transportClass + * @param array $transportOptions + * @return TransportInterface + * @throws InvalidArgumentException + */ + protected function buildTransport($transportClass, array $transportOptions = []) + { + if (!class_exists($transportClass)) { + throw new InvalidArgumentException("Transport class `{$transportClass}` is not found.", self::E_INVALID_OPTION); + } + + $transport = new $transportClass; + + if (!$transport instanceof TransportInterface) { + throw new InvalidArgumentException( + "Transport class `{$transportClass}` is not instance of + `Yandex\\Direct\\Transport\\TransportInterface`", self::E_INVALID_OPTION + ); + } + + $transport->setOptions($transportOptions); + + return $transport; + } + + /** + * @return string + */ + protected function getServiceNamespace() + { + return __NAMESPACE__ . '\\' . 'Service'; + } +} \ No newline at end of file diff --git a/src/Transport/JsonTransport.php b/src/Transport/JsonTransport.php new file mode 100644 index 0000000..5e94001 --- /dev/null +++ b/src/Transport/JsonTransport.php @@ -0,0 +1,208 @@ + + * @date 16/08/2016 18:06 + */ + +namespace Yandex\Direct\Transport; + +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; +use Yandex\Direct\ConfigurableTrait; +use Yandex\Direct\Exception\RuntimeException; +use Yandex\Direct\Exception\TransportRequestException; + + +/** + * Class JsonTransport + * @package Yandex\Direct\Transport + */ +final class JsonTransport implements TransportInterface, LoggerAwareInterface +{ + use ConfigurableTrait; + + /** + * @var string + */ + private $baseUrl = 'https://api.direct.yandex.com'; + + /** + * @var ClientInterface + */ + private $httpClient; + + /** + * Custom Service urls + * @var array + */ + private $serviceUrls = []; + + /** + * @var array + */ + private $headers = []; + + /** + * @var LoggerInterface + */ + private $logger; + + /** + * @var string + */ + private $language = 'ru'; + + /** + * JsonTransport constructor. + * + * @param array $options + */ + public function __construct(array $options = []) + { + $this->setOptions($options); + } + + /** + * @inheritdoc + */ + public function getServiceUrl($serviceName) + { + if (isset($this->serviceUrls[$serviceName])) { + // If service url is absolute + if (preg_match('#http[s]*://#u', $this->serviceUrls[$serviceName])) { + return $this->serviceUrls[$serviceName]; + } + return $this->baseUrl . $this->serviceUrls[$serviceName]; + } + + return $this->baseUrl . '/json/v5/' . strtolower($serviceName); + } + + /** + * @inheritdoc + */ + public function setLogger(LoggerInterface $logger) + { + $this->logger = $logger; + } + + /** + * @inheritdoc + */ + public function request(TransportRequest $request) + { + $log = $this->getLogger(); + + try { + $client = $this->getHttpClient(); + /* + * Build http request by transport request + */ + $httpRequest = $client->createRequest('POST', $this->getServiceUrl($request->getService()), [ + 'headers' => $this->prepareHeaders($request), + 'body' => $this->prepareBody($request) + ]); + + /* + * Requesting API with logging + */ + $log->debug("[request] " . $this->formatBodyLog($httpRequest->__toString())); + + $httpResponse = $client->send($httpRequest); + + $log->debug("[response] " . $this->formatBodyLog($httpResponse->__toString())); + + $httpResponseHeaders = $httpResponse->getHeaders(); + + + return new TransportResponse([ + 'headers' => $httpResponse->getHeaders(), + 'body' => $httpResponse->getBody()->__toString(), + 'requestId' => isset($httpResponseHeaders['RequestId']) ? current($httpResponseHeaders['RequestId']) : null, + 'units' => isset($httpResponseHeaders['Units']) ? current($httpResponseHeaders['Units']) : null + ]); + + } catch (RequestException $e) { + $log->error("Transport error: {$e->getMessage()} [CODE: {$e->getCode()}]"); + throw new TransportRequestException( + $e->getMessage(), + $e->getCode(), + $e->getRequest()->getHeaders(), + $e->getRequest()->getBody(), + $e->hasResponse() ? $e->getResponse()->getHeaders() : [], + $e->hasResponse() ? $e->getResponse()->getBody() : '', + $e->getPrevious() + ); + } catch (\Exception $e) { + $log->error("Runtime error: {$e->getMessage()} [CODE: {$e->getCode()}]"); + throw new RuntimeException($e->getMessage(), $e->getCode(), $e->getPrevious()); + } + } + + /** + * @return ClientInterface + */ + private function getHttpClient() + { + if ($this->httpClient === null) { + $this->httpClient = new Client([ + 'baseUrl' => $this->baseUrl + ]); + } + return $this->httpClient; + } + + /** + * @return LoggerInterface + */ + private function getLogger() + { + // Use stub if logger is not initialized + if ($this->logger === null) { + $this->logger = new NullLogger; + } + return $this->logger; + } + + /** + * @param TransportRequest $request + * @return array + */ + private function prepareHeaders(TransportRequest $request) + { + return array_merge([ + 'Authorization' => 'Bearer ' . $request->getCredentials()->getToken(), + 'Client-Login' => $request->getCredentials()->getLogin(), + 'Use-Operator-Units' => $request->getUseOperatorUnits(), + 'Accept-Language' => $this->language, + 'Content-Type' => 'application/json; charset=utf-8' + ], $this->headers); + } + + /** + * @param TransportRequest $request + * @return string + */ + private function prepareBody(TransportRequest $request) + { + return json_encode( + array_merge([ + 'method' => $request->getMethod(), + ], $request->getParams()), + JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT + ); + } + + /** + * @param $message + * @return string + */ + private function formatBodyLog($message) + { + return "\n---\n{$message}\n---\n"; + } +} \ No newline at end of file diff --git a/src/Transport/TransportInterface.php b/src/Transport/TransportInterface.php new file mode 100644 index 0000000..c75f05b --- /dev/null +++ b/src/Transport/TransportInterface.php @@ -0,0 +1,25 @@ + + * @date 16/08/2016 20:58 + */ + +namespace Yandex\Direct\Transport; + +use Psr\Log\LoggerAwareInterface; +use Yandex\Direct\ConfigurableInterface; + +interface TransportInterface extends ConfigurableInterface +{ + /** + * @param string $serviceName + * @return string + */ + public function getServiceUrl($serviceName); + + /** + * @param TransportRequest $request + * @return TransportResponse + */ + public function request(TransportRequest $request); +} \ No newline at end of file diff --git a/src/Transport/TransportRequest.php b/src/Transport/TransportRequest.php new file mode 100644 index 0000000..7104aa7 --- /dev/null +++ b/src/Transport/TransportRequest.php @@ -0,0 +1,116 @@ + + * @date 17/08/2016 13:52 + */ + +namespace Yandex\Direct\Transport; + +use Yandex\Direct\ConfigurableTrait; +use Yandex\Direct\CredentialsInterface; +use Yandex\Direct\Exception\InvalidArgumentException; + + +/** + * Class TransportRequest + * @package Yandex\Direct + */ +class TransportRequest +{ + use ConfigurableTrait; + + /** + * @var string + */ + protected $useOperatorUnits = 'true'; + + /** + * @var string + */ + protected $method; + + /** + * @var string + */ + protected $service; + + /** + * @var array + */ + protected $params = []; + + /** + * Custom headers + * @var array + */ + protected $headers = []; + + /** + * @var CredentialsInterface + */ + protected $credentials; + + + public function __construct(array $options = []) + { + $this->setOptions($options); + } + + /** + * @return string + */ + public function getService() + { + return $this->service; + } + + /** + * @return string + */ + public function getMethod() + { + return $this->method; + } + + /** + * @return array + */ + public function getParams() + { + return $this->params; + } + + /** + * @return string + */ + public function getUseOperatorUnits() + { + return $this->useOperatorUnits; + } + + /** + * @param bool $useOperatorUnits + * @throws InvalidArgumentException + */ + public function setUseOperatorUnits($useOperatorUnits) + { + if (is_numeric($useOperatorUnits) || is_bool($useOperatorUnits)) { + $this->useOperatorUnits = $useOperatorUnits ? 'true' : 'false'; + } else { + if (!in_array($useOperatorUnits, ['true', 'false'])) { + throw new InvalidArgumentException("Invalid value `\$seOperatorUnits`, valid is boolean and `true` or `false`."); + } + $this->useOperatorUnits = $useOperatorUnits; + } + } + + /** + * @return CredentialsInterface + */ + public function getCredentials() + { + return $this->credentials; + } + + +} \ No newline at end of file diff --git a/src/Transport/TransportResponse.php b/src/Transport/TransportResponse.php new file mode 100644 index 0000000..85cd362 --- /dev/null +++ b/src/Transport/TransportResponse.php @@ -0,0 +1,133 @@ + + * @date 17/08/2016 13:44 + */ + +namespace Yandex\Direct\Transport; + +use Yandex\Direct\ConfigurableTrait; +use Yandex\Direct\Exception\InvalidArgumentException; + + +/** + * Class TransportRequest + * @package Yandex\Direct + */ +class TransportResponse +{ + use ConfigurableTrait; + + const UNITS_TYPE_DEBIT = 0; + const UNITS_TYPE_REST = 1; + const UNITS_TYPE_LIMIT = 2; + + /** + * TransportResponse constructor. + * + * @param array $options + */ + public function __construct(array $options) + { + $this->setOptions($options); + } + + /** + * @var array + */ + protected $units = [null, null, null]; + + /** + * @var string + */ + protected $requestId; + + /** + * @var string + */ + protected $body; + + /** + * @var array + */ + protected $headers = []; + + /** + * @return array + */ + public function getUnits() + { + return $this->units; + } + + /** + * @param string $rawUnits + * @throws InvalidArgumentException + */ + public function setUnits($rawUnits) + { + $units = explode('/', $rawUnits); + if (is_array($units) + && count($units) > 0 + ) { + $this->units = $units; + } + } + + + /** + * @return string + */ + public function getRequestId() + { + return $this->requestId; + } + + /** + * @return int + */ + public function getUnitsDebit() + { + return $this->getUnits()[self::UNITS_TYPE_DEBIT]; + } + + /** + * @return int + */ + public function getUnitsRest() + { + return $this->getUnits()[self::UNITS_TYPE_REST]; + } + + /** + * @return int + */ + public function getUnitsLimit() + { + return $this->getUnits()[self::UNITS_TYPE_LIMIT]; + } + + /** + * @return string + */ + public function getBody() + { + return $this->body; + } + + /** + * The keys represent the header name as it will be sent over the wire, and + * each value is an array of strings associated with the header. + * + * // Represent the headers as a string + * foreach ($message->getHeaders() as $name => $values) { + * echo $name . ": " . implode(", ", $values); + * } + * + * @return array + */ + public function getHeaders() + { + return $this->headers; + } +} \ No newline at end of file diff --git a/tests/ClientTest.php b/tests/ClientTest.php new file mode 100644 index 0000000..237e06b --- /dev/null +++ b/tests/ClientTest.php @@ -0,0 +1,104 @@ + + * @date 16/08/2016 17:20 + */ + +namespace Yandex\Direct\Test; + + +use Yandex\Direct\Client; +use Yandex\Direct\CredentialsInterface; + +class ApiTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var Client + */ + private $client; + + public function setUp() + { + $this->client = new Client(new DummyCredentials); + } + + /** + * @expectedException \Yandex\Direct\Exception\InvalidArgumentException + */ + public function testInvalidServiceExceptionGetMagic() + { + $this->client->hahaImNotExistinService; + } + + /** + * @expectedException \Yandex\Direct\Exception\InvalidArgumentException + */ + public function testInvalidServiceExceptionCallMagic() + { + $this->client->hahaImNotExistinService(); + } + + + /** + * @dataProvider providerYandexServices + * @param $serviceName + */ + public function testHasAllServicesWithGetMagic($serviceName) + { + $service = $this->client->{lcfirst($serviceName)}; + $this->assertInstanceOf('Yandex\\Direct\\Service\\' . $serviceName, $service); + $this->assertInstanceOf('Yandex\\Direct\\Service', $service); + + unset($service); + + $service = $this->client->{$serviceName}; + $this->assertInstanceOf('Yandex\\Direct\\Service\\' . $serviceName, $service); + $this->assertInstanceOf('Yandex\\Direct\\Service', $service); + } + + /** + * @dataProvider providerYandexServices + * @param $serviceName + */ + public function testHasAllServicesWithCallMagic($serviceName) + { + $service = $this->client->{lcfirst($serviceName)}(); + $this->assertInstanceOf('Yandex\\Direct\\Service\\' . $serviceName, $service); + $this->assertInstanceOf('Yandex\\Direct\\Service', $service); + + unset($service); + + $service = $this->client->{$serviceName}(); + $this->assertInstanceOf('Yandex\\Direct\\Service\\' . $serviceName, $service); + $this->assertInstanceOf('Yandex\\Direct\\Service', $service); + } + + + public function providerYandexServices() + { + return [ + ['AdExtensions'], + ['AdGroups'], + ['AdImages'], + ['Ads'], + ['AudienceTargets'], + ['BidModifiers'], + ['Bids'], + ['Campaigns'], + ['Changes'], + ['Dictionaries'], + ['DynamicTextAdTargets'], + ['Keywords'], + ['RetargetingLists'], + ['Sitelinks'], + ['VCards'], + ]; + } +} + + +class DummyCredentials implements CredentialsInterface { + public function getMasterToken() { return '';} + public function getToken() { return '';} + public function getLogin() { return '';} +} \ No newline at end of file diff --git a/tests/Transport/JsonTransportTest.php b/tests/Transport/JsonTransportTest.php new file mode 100644 index 0000000..602932f --- /dev/null +++ b/tests/Transport/JsonTransportTest.php @@ -0,0 +1,36 @@ + + * @date 17/08/2016 12:51 + */ + +namespace Yandex\Direct\Test\Transport; + + +use Yandex\Direct\Transport\JsonTransport; + +/** + * Class JsonTransport + * @package Yandex\Direct\Test\Transport + */ +class JsonTransportTest extends \PHPUnit_Framework_TestCase +{ + public function testResolvingServiceUrls() + { + $transport = new JsonTransport; + $transport->setOptions([ + 'baseUrl' => 'https://api-sandbox.yandex.direct', + 'serviceUrls' => [ + 'A' => '/json/v5/ads', + 'B' => 'http://api.yandex.direct.com/json/v5/ads', + 'C' => 'https://api.yandex.direct.com/json/v5/ads' + ] + ]); + + foreach (['A', 'B', 'C', 'D'] as $service) { + $this->assertRegExp('#http[s]*://#u', $a = $transport->getServiceUrl($service)); + } + } + + +} \ No newline at end of file