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