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 Tables. |
19
|
|
|
* |
20
|
|
|
* @author Claude Khedhiri <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Tables extends AbstractApi |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @param $table |
26
|
|
|
* @param array $rows |
27
|
|
|
* |
28
|
|
|
* @return ResponseInterface |
29
|
|
|
*/ |
30
|
|
|
public function insertInTo($table, array $rows) |
31
|
|
|
{ |
32
|
|
|
return $this->sendRequest($this->createInsertInToRequest($table, $rows)); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $table |
37
|
|
|
* @param array $rows |
38
|
|
|
* |
39
|
|
|
* @return Promise |
40
|
|
|
*/ |
41
|
|
|
public function asyncInsertInTo($table, array $rows) |
42
|
|
|
{ |
43
|
|
|
return $this->sendAsyncRequest($this->createInsertInToRequest($table, $rows)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param $table |
48
|
|
|
* @param array $row |
49
|
|
|
* @param array $newRow |
50
|
|
|
* |
51
|
|
|
* @return ResponseInterface |
52
|
|
|
*/ |
53
|
|
|
public function replaceInTo($table, array $row, array $newRow) |
54
|
|
|
{ |
55
|
|
|
return $this->sendRequest($this->createReplaceInToRequest($table, $row, $newRow)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $table |
60
|
|
|
* @param array $row |
61
|
|
|
* @param array $newRow |
62
|
|
|
* |
63
|
|
|
* @return Promise |
64
|
|
|
*/ |
65
|
|
|
public function asyncReplaceInTo($table, array $row, array $newRow) |
66
|
|
|
{ |
67
|
|
|
return $this->sendAsyncRequest($this->createReplaceInToRequest($table, $row, $newRow)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param $table |
72
|
|
|
* @param array $search |
73
|
|
|
* @param array $update |
74
|
|
|
* |
75
|
|
|
* @return ResponseInterface |
76
|
|
|
*/ |
77
|
|
|
public function updateInTo($table, array $search, array $update) |
78
|
|
|
{ |
79
|
|
|
return $this->sendRequest($this->createUpdateInToRequest($table, $search, $update)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $table |
84
|
|
|
* @param array $search |
85
|
|
|
* @param array $update |
86
|
|
|
* |
87
|
|
|
* @return Promise |
88
|
|
|
*/ |
89
|
|
|
public function asyncUpdateInTo($table, array $search, array $update) |
90
|
|
|
{ |
91
|
|
|
return $this->sendAsyncRequest($this->createUpdateInToRequest($table, $search, $update)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $table |
96
|
|
|
* @param array $rows |
97
|
|
|
* |
98
|
|
|
* @return \Psr\Http\Message\RequestInterface |
99
|
|
|
*/ |
100
|
|
|
private function createInsertInToRequest($table, array $rows) |
101
|
|
|
{ |
102
|
|
|
return $this->createRequest('POST', "/api/rds/tables/$table/records", $rows); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param string $table |
107
|
|
|
* @param array $row |
108
|
|
|
* @param array $newRow |
109
|
|
|
* |
110
|
|
|
* @return \Psr\Http\Message\RequestInterface |
111
|
|
|
*/ |
112
|
|
|
private function createReplaceInToRequest($table, array $row, array $newRow) |
113
|
|
|
{ |
114
|
|
|
return $this->createRequest('PUT', "/api/rds/tables/$table/records", array($row, $newRow)); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param string $table |
119
|
|
|
* @param array $search |
120
|
|
|
* @param array $update |
121
|
|
|
* |
122
|
|
|
* @return \Psr\Http\Message\RequestInterface |
123
|
|
|
*/ |
124
|
|
|
private function createUpdateInToRequest($table, array $search, array $update) |
125
|
|
|
{ |
126
|
|
|
return $this->createRequest('POST', "/api/rds/tables/$table/records", array(array($search, $update))); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|