|
1
|
|
|
<?php |
|
2
|
|
|
namespace Datatrics\API\Modules; |
|
3
|
|
|
|
|
4
|
|
|
use Datatrics\API\Client; |
|
5
|
|
|
|
|
6
|
|
|
class Behavior extends Base |
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* Private constructor so only the client can create this |
|
10
|
|
|
* @param Client $client |
|
11
|
|
|
*/ |
|
12
|
16 |
|
public function __construct(Client $client) |
|
13
|
|
|
{ |
|
14
|
16 |
|
parent::__construct($client); |
|
15
|
16 |
|
$this->SetUrl("/project/" . $this->GetClient()->GetProjectId() . "/behavior"); |
|
16
|
16 |
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Get a list of behaviors |
|
20
|
|
|
* @param object Containing query arguments |
|
21
|
|
|
* @return object Result of the request |
|
22
|
|
|
*/ |
|
23
|
|
|
public function Get($args = array("limit" => 50)) |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->GetClient()->Get($this->GetUrl(), $args); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Get a list of Visits |
|
30
|
|
|
* @param object Containing query arguments |
|
31
|
|
|
* @return object Result of the request |
|
32
|
|
|
*/ |
|
33
|
|
|
public function GetVisit($args = array("limit" => 50)) |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/visit", $args); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get one or multiple events |
|
40
|
|
|
* @param string event id, leave null for list of events |
|
41
|
|
|
* @param object Containing query arguments |
|
42
|
|
|
* @return object Result of the request |
|
43
|
|
|
*/ |
|
44
|
|
|
public function GetEvent($eventId = null, $args = array("limit" => 50)) |
|
45
|
|
|
{ |
|
46
|
|
|
if (is_null($eventId)) { |
|
47
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/event", $args); |
|
48
|
|
|
} |
|
49
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/event/".$eventId, $args); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Create new event |
|
54
|
|
|
* @param object Containing all the information of a event |
|
55
|
|
|
* @return object Result of the request |
|
56
|
|
|
*/ |
|
57
|
|
|
public function CreateEvent($event) |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/event", $event); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Update a event |
|
64
|
|
|
* @param object Event containing the eventid and fields that need to be updated |
|
65
|
|
|
* @throws \Exception When eventid is not present |
|
66
|
|
|
* @return object Result of the request |
|
67
|
|
|
*/ |
|
68
|
|
|
public function UpdateEvent($event) |
|
69
|
|
|
{ |
|
70
|
|
|
if (!isset($event['eventid'])) { |
|
71
|
|
|
throw new \Exception("event must contain a eventid"); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $this->GetClient()->Put($this->GetUrl()."/event/".$event['eventid'], $event); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Updates a maximum of 50 events at a time. |
|
79
|
|
|
* @param array Containing events with a maximum of 50 |
|
80
|
|
|
* @throws \Exception When more that 50 events are provided |
|
81
|
|
|
* @return object Result of the request |
|
82
|
|
|
*/ |
|
83
|
|
|
public function Bulk($events) |
|
84
|
|
|
{ |
|
85
|
|
|
if (count($events) > 50) { |
|
86
|
|
|
throw new \Exception("Maximum of 50 events allowed at a time"); |
|
87
|
|
|
} |
|
88
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/event/bulk", ['items' => $events]); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|