|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* A php library for using the Emarsys API. |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/quitoque/emarsys-php-client |
|
7
|
|
|
* @package emarsys-php-client |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
* @copyright Copyright (c) 2017 Quitoque <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Emarsys\Api; |
|
13
|
|
|
|
|
14
|
|
|
use Http\Promise\Promise; |
|
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class Events. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Claude Khedhiri <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class ExternalEvents extends AbstractApi |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @param $eventId |
|
26
|
|
|
* |
|
27
|
|
|
* @return ResponseInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
public function create($eventId) |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->sendRequest($this->createCreateRequest($eventId)); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param $eventId |
|
36
|
|
|
* |
|
37
|
|
|
* @return Promise |
|
38
|
|
|
*/ |
|
39
|
|
|
public function asyncCreate($eventId) |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->sendAsyncRequest($this->createCreateRequest($eventId)); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param int $eventId |
|
46
|
|
|
* @param array $data |
|
47
|
|
|
* |
|
48
|
|
|
* @return ResponseInterface |
|
49
|
|
|
*/ |
|
50
|
|
|
public function trigger($eventId, $data = array()) |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->sendRequest($this->createTriggerRequest($eventId, $data)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param int $eventId |
|
57
|
|
|
* @param array $data |
|
58
|
|
|
* |
|
59
|
|
|
* @return Promise |
|
60
|
|
|
*/ |
|
61
|
|
|
public function asyncTrigger($eventId, $data = array()) |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->sendAsyncRequest($this->createTriggerRequest($eventId, $data)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param int $eventId |
|
68
|
|
|
* @param array $data |
|
69
|
|
|
* |
|
70
|
|
|
* @return \Psr\Http\Message\RequestInterface |
|
71
|
|
|
*/ |
|
72
|
|
|
private function createCreateRequest($eventId, $data = array()) |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->createRequest('POST', "/event/$eventId/trigger", $data); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param int $eventId |
|
79
|
|
|
* @param array $data |
|
80
|
|
|
* |
|
81
|
|
|
* @return \Psr\Http\Message\RequestInterface |
|
82
|
|
|
*/ |
|
83
|
|
|
private function createTriggerRequest($eventId, $data = array()) |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->createRequest('POST', "/event/$eventId/trigger", $data); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|