1
|
|
|
<?php |
2
|
|
|
namespace Datatrics\API\Modules; |
3
|
|
|
|
4
|
|
|
use Datatrics\API\Client; |
5
|
|
|
|
6
|
|
|
class Campaign extends Base |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Private constructor so only the client can create this |
10
|
|
|
* @param Client $client |
11
|
|
|
*/ |
12
|
20 |
|
public function __construct(Client $client) |
13
|
|
|
{ |
14
|
20 |
|
parent::__construct($client); |
15
|
20 |
|
$this->SetUrl("/project/" . $this->GetClient()->GetProjectId() . "/campaign"); |
16
|
20 |
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get one or multiple campaigns |
20
|
|
|
* @param string campaign id, leave null for list of campaigns |
21
|
|
|
* @param object Containing query arguments |
22
|
|
|
* @return object Result of the request |
23
|
|
|
*/ |
24
|
|
|
public function Get($campaignId = null, $args = array("limit" => 50)) |
25
|
|
|
{ |
26
|
|
|
if (is_null($campaignId)) { |
27
|
|
|
return $this->GetClient()->Get($this->GetUrl(), $args); |
28
|
|
|
} |
29
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$campaignId, $args); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get one or multiple lanes |
34
|
|
|
* @param string campaign id |
35
|
|
|
* @param string lane id, leave null for list of lanes |
36
|
|
|
* @param object Containing query arguments |
37
|
|
|
* @return object Result of the request |
38
|
|
|
*/ |
39
|
|
|
public function GetLane($campaignId, $laneId = null, $args = array("limit" => 50)) |
40
|
|
|
{ |
41
|
|
|
if (is_null($laneId)) { |
42
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$campaignId."/lane", $args); |
43
|
|
|
} |
44
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$campaignId."/lane/".$laneId, $args); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Create new campaign |
49
|
|
|
* @param object Containing all the information of a lane |
50
|
|
|
* @return object Result of the request |
51
|
|
|
*/ |
52
|
|
|
public function Create($campaign) |
53
|
|
|
{ |
54
|
|
|
return $this->GetClient()->Post($this->GetUrl(), $campaign); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Create new lane |
59
|
|
|
* @param string campaign id |
60
|
|
|
* @param object Containing all the information of a lane |
61
|
|
|
* @return object Result of the request |
62
|
|
|
*/ |
63
|
|
|
public function CreateLane($campaignId, $lane) |
64
|
|
|
{ |
65
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/".$campaignId."/lane", $lane); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Update a campaign |
70
|
|
|
* @param object campaign containing the campaign id and fields that need to be updated |
71
|
|
|
* @throws \Exception When boxid is not present |
72
|
|
|
* @return object Result of the request |
73
|
|
|
*/ |
74
|
|
|
public function Update($campaign) |
75
|
|
|
{ |
76
|
|
|
if (!isset($campaign['campaignid'])) { |
77
|
|
|
throw new \Exception("campaign must contain a campaignid"); |
78
|
|
|
} |
79
|
|
|
return $this->GetClient()->Put($this->GetUrl()."/".$campaign['campaignid'], $campaign); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Update a lane |
84
|
|
|
* @param string Id of the campaign |
85
|
|
|
* @param object lane containing the laneid and fields that need to be updated |
86
|
|
|
* @throws \Exception When boxid is not present |
87
|
|
|
* @return object Result of the request |
88
|
|
|
*/ |
89
|
|
|
public function UpdateLane($campaignId, $lane) |
90
|
|
|
{ |
91
|
|
|
if (!isset($lane['laneid'])) { |
92
|
|
|
throw new \Exception("lane must contain a laneid"); |
93
|
|
|
} |
94
|
|
|
return $this->GetClient()->Put($this->GetUrl()."/".$campaignId."/lane/".$lane['laneid'], $lane); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Delete a campaign object by campaign id |
99
|
|
|
* @param string Id of the campaign |
100
|
|
|
* @return object Result of the request |
101
|
|
|
*/ |
102
|
|
|
public function Delete($campaignId) |
103
|
|
|
{ |
104
|
|
|
return $this->GetClient()->Delete($this->GetUrl()."/".$campaignId); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Delete a campaign object by campaign id |
109
|
|
|
* @param string Id of the campaign |
110
|
|
|
* @return object Result of the request |
111
|
|
|
*/ |
112
|
|
|
public function DeleteLane($campaignId, $laneId) |
113
|
|
|
{ |
114
|
|
|
return $this->GetClient()->Delete($this->GetUrl()."/".$campaignId."/lane/".$laneId); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Retrieve stats of a lane by campaign |
119
|
|
|
* @param string Id of the campaign |
120
|
|
|
* @return object Result of the request |
121
|
|
|
*/ |
122
|
|
|
public function Stats($campaignId) |
123
|
|
|
{ |
124
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$campaignId."/stats"); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Retrieve stats of a lane by campaign and lane id |
129
|
|
|
* @param string Id of the campaign |
130
|
|
|
* @param string Id of the lane to be deleted |
131
|
|
|
* @return object Result of the request |
132
|
|
|
*/ |
133
|
|
|
public function StatsLane($campaignId, $laneId) |
134
|
|
|
{ |
135
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$campaignId."/lane/".$laneId."/stats"); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|