1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Audiens\AdForm; |
4
|
|
|
|
5
|
|
|
use Audiens\AdForm\Cache\CacheInterface; |
6
|
|
|
use Audiens\AdForm\Manager\AgencyManager; |
7
|
|
|
use Audiens\AdForm\Manager\AudienceManager; |
8
|
|
|
use Audiens\AdForm\Manager\CategoryManager; |
9
|
|
|
use Audiens\AdForm\Manager\DataProviderAudienceManager; |
10
|
|
|
use Audiens\AdForm\Manager\DataUsageManager; |
11
|
|
|
use Audiens\AdForm\Manager\SegmentManager; |
12
|
|
|
|
13
|
|
|
class Client |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Version number of the Adform PHP SDK. |
17
|
|
|
* |
18
|
|
|
* @const string |
19
|
|
|
*/ |
20
|
|
|
public const VERSION = '1.0.1'; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
public const BASE_URL = 'https://dmp-api.adform.com'; |
24
|
|
|
|
25
|
|
|
/** @var Authentication */ |
26
|
|
|
protected $auth; |
27
|
|
|
|
28
|
|
|
/** @var HttpClient */ |
29
|
|
|
protected $httpClient; |
30
|
|
|
|
31
|
|
|
/** @var CacheInterface|null */ |
32
|
|
|
protected $cache; |
33
|
|
|
|
34
|
|
|
/** @var CategoryManager */ |
35
|
|
|
protected static $categories; |
36
|
|
|
|
37
|
|
|
/** @var AudienceManager */ |
38
|
|
|
protected static $audiences; |
39
|
|
|
|
40
|
|
|
/** @var SegmentManager */ |
41
|
|
|
protected static $segments; |
42
|
|
|
|
43
|
|
|
/** @var AgencyManager */ |
44
|
|
|
protected static $agencies; |
45
|
|
|
|
46
|
|
|
/** @var DataUsageManager */ |
47
|
|
|
protected $dataUsage; |
48
|
|
|
|
49
|
|
|
/** @var DataProviderAudienceManager */ |
50
|
|
|
protected $dataProviderAudience; |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function __construct($username, $password, CacheInterface $cache = null) |
54
|
|
|
{ |
55
|
|
|
$this->auth = new Authentication($username, $password); |
56
|
|
|
$this->httpClient = new HttpClient($this->auth); |
57
|
|
|
$this->cache = $cache; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* A proxy method for working with categories |
62
|
|
|
* @return CategoryManager |
63
|
|
|
*/ |
64
|
|
|
public function categories(): CategoryManager |
65
|
|
|
{ |
66
|
|
|
if (static::$categories === null) { |
67
|
|
|
static::$categories = new CategoryManager($this->httpClient, $this->cache); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return static::$categories; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* A proxy method for working with categories |
75
|
|
|
*/ |
76
|
|
|
public function audience(): AudienceManager |
77
|
|
|
{ |
78
|
|
|
if (static::$audiences === null) { |
79
|
|
|
static::$audiences = new AudienceManager($this->httpClient, $this->cache); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return static::$audiences; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* A proxy method for working with segments |
87
|
|
|
*/ |
88
|
|
|
public function segments(): SegmentManager |
89
|
|
|
{ |
90
|
|
|
if (static::$segments === null) { |
91
|
|
|
static::$segments = new SegmentManager($this->httpClient, $this->cache); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return static::$segments; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* A proxy method for working with agencies |
99
|
|
|
*/ |
100
|
|
|
public function agencies(): AgencyManager |
101
|
|
|
{ |
102
|
|
|
if (static::$agencies === null) { |
103
|
|
|
static::$agencies = new AgencyManager($this->httpClient, $this->cache); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return static::$agencies; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* A proxy method for working with data usage reports |
111
|
|
|
*/ |
112
|
|
|
public function dataUsage(): DataUsageManager |
113
|
|
|
{ |
114
|
|
|
if ($this->dataUsage === null) { |
115
|
|
|
$this->dataUsage = new DataUsageManager($this->httpClient, $this->cache); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $this->dataUsage; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* A proxy method for working with data provider audience reports |
123
|
|
|
*/ |
124
|
|
|
public function dataProviderAudience(): DataProviderAudienceManager |
125
|
|
|
{ |
126
|
|
|
if ($this->dataProviderAudience === null) { |
127
|
|
|
$this->dataProviderAudience = new DataProviderAudienceManager($this->httpClient, $this->cache); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return $this->dataProviderAudience; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|