1
|
|
|
<?php |
2
|
|
|
namespace Datatrics\API\Modules; |
3
|
|
|
|
4
|
|
|
class Behavior 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 . "/behavior"); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Get a list of behaviors |
18
|
|
|
* @param object Containing query arguments |
19
|
|
|
* @return object Result of the request |
20
|
|
|
*/ |
21
|
|
|
public function Get($args = array("limit" => 50)) |
22
|
|
|
{ |
23
|
|
|
return $this->request(self::HTTP_GET, "?".http_build_query($args)); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Get a list of Visits |
28
|
|
|
* @param object Containing query arguments |
29
|
|
|
* @return object Result of the request |
30
|
|
|
*/ |
31
|
|
|
public function GetVisit($args = array("limit" => 50)) |
32
|
|
|
{ |
33
|
|
|
return $this->request(self::HTTP_GET, "/visit?".http_build_query($args)); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get one or multiple events |
38
|
|
|
* @param string event id, leave null for list of events |
39
|
|
|
* @param object Containing query arguments |
40
|
|
|
* @return object Result of the request |
41
|
|
|
*/ |
42
|
|
|
public function GetEvent($eventId = null, $args = array("limit" => 50)) |
43
|
|
|
{ |
44
|
|
|
return $eventId == null ? $this->request(self::HTTP_GET, "/event?".http_build_query($args)) : $this->request(self::HTTP_GET, "/event/".$eventId."?".http_build_query($args)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Create new event |
49
|
|
|
* @param object Containing all the information of a event |
50
|
|
|
* @return object Result of the request |
51
|
|
|
*/ |
52
|
|
|
public function CreateEvent($event) |
53
|
|
|
{ |
54
|
|
|
return $this->request(self::HTTP_POST, "/evet", $event); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Update a event |
59
|
|
|
* @param object Event containing the eventid and fields that need to be updated |
60
|
|
|
* @throws \Exception When eventid is not present |
61
|
|
|
* @return object Result of the request |
62
|
|
|
*/ |
63
|
|
|
public function UpdateEvent($event) |
64
|
|
|
{ |
65
|
|
|
if (!isset($event['eventid'])) { |
66
|
|
|
throw new \Exception("event must contain a eventid"); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $this->request(self::HTTP_PUT, "/event/".$event['eventid'], $profile); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Updates a maximum of 50 events at a time. |
74
|
|
|
* @param array Containing events with a maximum of 50 |
75
|
|
|
* @throws \Exception When more that 50 events are provided |
76
|
|
|
* @return object Result of the request |
77
|
|
|
*/ |
78
|
|
|
public function UpdateBulk($events) |
79
|
|
|
{ |
80
|
|
|
if (count($events) > 50) { |
81
|
|
|
throw new \Exception("Maximum of 50 events allowed at a time"); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $this->request(self::HTTP_POST, "/event/bulk", $events); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.