|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Dmitry Gladyshev <[email protected]> |
|
4
|
|
|
* @date 17/08/2016 10:37 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Yandex\Direct; |
|
8
|
|
|
|
|
9
|
|
|
use Yandex\Direct\Service\AdExtensions; |
|
10
|
|
|
use Yandex\Direct\Service\AdGroups; |
|
11
|
|
|
use Yandex\Direct\Service\AdImages; |
|
12
|
|
|
use Yandex\Direct\Service\Ads; |
|
13
|
|
|
use Yandex\Direct\Service\AudienceTargets; |
|
14
|
|
|
use Yandex\Direct\Service\BidModifiers; |
|
15
|
|
|
use Yandex\Direct\Service\Bids; |
|
16
|
|
|
use Yandex\Direct\Service\Campaigns; |
|
17
|
|
|
use Yandex\Direct\Service\Changes; |
|
18
|
|
|
use Yandex\Direct\Service\Clients; |
|
19
|
|
|
use Yandex\Direct\Service\Dictionaries; |
|
20
|
|
|
use Yandex\Direct\Service\DynamicTextAdTargets; |
|
21
|
|
|
use Yandex\Direct\Service\Keywords; |
|
22
|
|
|
use Yandex\Direct\Service\RetargetingLists; |
|
23
|
|
|
use Yandex\Direct\Service\Sitelinks; |
|
24
|
|
|
use Yandex\Direct\Service\VCards; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Yandex.Direct v5 API client implementation |
|
28
|
|
|
* |
|
29
|
|
|
* @package Yandex\Direct |
|
30
|
|
|
* |
|
31
|
|
|
* Yandex Services |
|
32
|
|
|
* @method AdExtensions adExtensions(array $options = []) |
|
33
|
|
|
* @method AdGroups adGroups(array $options = []) |
|
34
|
|
|
* @method AdImages adImages(array $options = []) |
|
35
|
|
|
* @method Ads ads(array $options = []) |
|
36
|
|
|
* @method AudienceTargets audienceTargets(array $options = []) |
|
37
|
|
|
* @method BidModifiers bidModifiers(array $options = []) |
|
38
|
|
|
* @method Bids bids(array $options = []) |
|
39
|
|
|
* @method Campaigns campaigns(array $options = []) |
|
40
|
|
|
* @method Clients clients(array $options = []) |
|
41
|
|
|
* @method Changes changes(array $options = []) |
|
42
|
|
|
* @method Dictionaries dictionaries(array $options = []) |
|
43
|
|
|
* @method DynamicTextAdTargets dynamicTextAdsTargets(array $options = []) |
|
44
|
|
|
* @method Keywords keywords(array $options = []) |
|
45
|
|
|
* @method RetargetingLists retargetingLists(array $options = []) |
|
46
|
|
|
* @method Sitelinks sitelinks(array $options = []) |
|
47
|
|
|
* @method VCards vCards(array $options = []) |
|
48
|
|
|
* |
|
49
|
|
|
* Aliases (sugar) |
|
50
|
|
|
* @property AdExtensions $adExtensions |
|
51
|
|
|
* @property AdGroups $adGroups |
|
52
|
|
|
* @property AdImages $adImages |
|
53
|
|
|
* @property Ads $ads |
|
54
|
|
|
* @property AudienceTargets $audienceTargets |
|
55
|
|
|
* @property BidModifiers $bidModifiers |
|
56
|
|
|
* @property Bids $bids |
|
57
|
|
|
* @property Campaigns $campaigns |
|
58
|
|
|
* @property Clients $clients |
|
59
|
|
|
* @property Changes $changes |
|
60
|
|
|
* @property Dictionaries $dictionaries |
|
61
|
|
|
* @property DynamicTextAdTargets $dynamicTextAdsTargets |
|
62
|
|
|
* @property Keywords $keywords |
|
63
|
|
|
* @property RetargetingLists $retargetingLists |
|
64
|
|
|
* @property Sitelinks $sitelinks |
|
65
|
|
|
* @property VCards $vCards |
|
66
|
|
|
*/ |
|
67
|
|
|
class Client |
|
68
|
|
|
{ |
|
69
|
|
|
/** |
|
70
|
|
|
* @var ServiceFactory |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $serviceFactory; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var CredentialsInterface |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $credentials; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param CredentialsInterface $credentials |
|
81
|
|
|
* @param array $options |
|
82
|
|
|
*/ |
|
83
|
32 |
|
public function __construct(CredentialsInterface $credentials, array $options = []) |
|
84
|
|
|
{ |
|
85
|
32 |
|
$this->setCredentials($credentials); |
|
86
|
32 |
|
$this->serviceFactory = new ServiceFactory; |
|
87
|
32 |
|
$this->serviceFactory->setDefaultOptions(array_merge([ |
|
88
|
32 |
|
'credentials' => $this->credentials |
|
89
|
32 |
|
], $options)); |
|
90
|
32 |
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param string $name |
|
94
|
|
|
* @param array $options |
|
95
|
|
|
* @return Service |
|
96
|
|
|
*/ |
|
97
|
32 |
|
public function __call($name, array $options = []) |
|
98
|
|
|
{ |
|
99
|
32 |
|
return $this->serviceFactory->createService($name, current($options) ?: []); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param string $name |
|
104
|
|
|
* @return Service |
|
105
|
|
|
*/ |
|
106
|
16 |
|
public function __get($name) |
|
107
|
|
|
{ |
|
108
|
16 |
|
return $this->__call($name); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param array $options |
|
113
|
|
|
* @return self |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setOptions(array $options) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->serviceFactory->setDefaultOptions($options); |
|
118
|
|
|
return $this; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param CredentialsInterface $credentials |
|
123
|
|
|
* @return self |
|
124
|
|
|
*/ |
|
125
|
32 |
|
public function setCredentials(CredentialsInterface $credentials) |
|
126
|
|
|
{ |
|
127
|
32 |
|
$this->credentials = $credentials; |
|
128
|
32 |
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|