1
|
|
|
<?php |
2
|
|
|
namespace Datatrics\API\Modules; |
3
|
|
|
|
4
|
|
|
class Interaction 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 . "/interaction"); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Get one or multiple interactions |
18
|
|
|
* @param string interaction id, leave null for list of boxes |
19
|
|
|
* @param object Containing query arguments |
20
|
|
|
* @return object Result of the request |
21
|
|
|
*/ |
22
|
|
|
public function Get($interactionId = null, $args = array("limit" => 50)) |
23
|
|
|
{ |
24
|
|
|
return $interactionId == null ? $this->request(self::HTTP_GET, "?".http_build_query($args)) : $this->request(self::HTTP_GET, "/".$interactionId."?".http_build_query($args)); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create new interaction |
29
|
|
|
* @param object Containing all the information of a interaction |
30
|
|
|
* @return object Result of the request |
31
|
|
|
*/ |
32
|
|
|
public function Create($interaction) |
33
|
|
|
{ |
34
|
|
|
return $this->request(self::HTTP_POST, "", $interaction); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create new interaction |
39
|
|
|
* @param id of the interaction |
40
|
|
|
* @param object Containing all the information of a interaction |
41
|
|
|
* @return object Result of the request |
42
|
|
|
*/ |
43
|
|
|
public function Update($interactionId, $interaction) |
44
|
|
|
{ |
45
|
|
|
return $this->request(self::HTTP_PUT, "/".$interactionId, $interaction); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Delete a interaction object by interaction id |
50
|
|
|
* @param string Id of the interaction |
51
|
|
|
* @return object Result of the request |
52
|
|
|
*/ |
53
|
|
|
public function Delete($interactionId) |
54
|
|
|
{ |
55
|
|
|
return $this->request(self::HTTP_DELETE, "/".$interactionId); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Updates a maximum of 50 interaction items at a time. |
60
|
|
|
* @param array Containing interaction items with a maximum of 50 |
61
|
|
|
* @throws \Exception When more that 50 interaction items are provided |
62
|
|
|
* @return object Result of the request |
63
|
|
|
*/ |
64
|
|
|
public function UpdateBulk($interactions) |
65
|
|
|
{ |
66
|
|
|
if (count($interactions) > 50) { |
67
|
|
|
throw new \Exception("Maximum of 50 interaction items allowed at a time"); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $this->request(self::HTTP_POST, "/bulk", ['items' => $interactions]); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|