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