1 | <?php |
||
11 | class Batch |
||
12 | { |
||
13 | private $MailChimp; |
||
14 | |||
15 | private $operations = array(); |
||
16 | private $batch_id; |
||
17 | |||
18 | public function __construct(MailChimp $MailChimp, $batch_id = null) |
||
23 | |||
24 | /** |
||
25 | * Add an HTTP DELETE request operation to the batch - for deleting data |
||
26 | * |
||
27 | * @param string $id ID for the operation within the batch |
||
28 | * @param string $method URL of the API request method |
||
29 | * |
||
30 | * @return void |
||
31 | */ |
||
32 | public function delete($id, $method) |
||
36 | |||
37 | /** |
||
38 | * Add an HTTP GET request operation to the batch - for retrieving data |
||
39 | * |
||
40 | * @param string $id ID for the operation within the batch |
||
41 | * @param string $method URL of the API request method |
||
42 | * @param array $args Assoc array of arguments (usually your data) |
||
43 | * |
||
44 | * @return void |
||
45 | */ |
||
46 | public function get($id, $method, $args = array()) |
||
50 | |||
51 | /** |
||
52 | * Add an HTTP PATCH request operation to the batch - for performing partial updates |
||
53 | * |
||
54 | * @param string $id ID for the operation within the batch |
||
55 | * @param string $method URL of the API request method |
||
56 | * @param array $args Assoc array of arguments (usually your data) |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | public function patch($id, $method, $args = array()) |
||
64 | |||
65 | /** |
||
66 | * Add an HTTP POST request operation to the batch - for creating and updating items |
||
67 | * |
||
68 | * @param string $id ID for the operation within the batch |
||
69 | * @param string $method URL of the API request method |
||
70 | * @param array $args Assoc array of arguments (usually your data) |
||
71 | * |
||
72 | * @return void |
||
73 | */ |
||
74 | public function post($id, $method, $args = array()) |
||
78 | |||
79 | /** |
||
80 | * Add an HTTP PUT request operation to the batch - for creating new items |
||
81 | * |
||
82 | * @param string $id ID for the operation within the batch |
||
83 | * @param string $method URL of the API request method |
||
84 | * @param array $args Assoc array of arguments (usually your data) |
||
85 | * |
||
86 | * @return void |
||
87 | */ |
||
88 | public function put($id, $method, $args = array()) |
||
92 | |||
93 | /** |
||
94 | * Execute the batch request |
||
95 | * |
||
96 | * @param int $timeout Request timeout in seconds (optional) |
||
97 | * |
||
98 | * @return array|false Assoc array of API response, decoded from JSON |
||
99 | */ |
||
100 | public function execute($timeout = 10) |
||
112 | |||
113 | /** |
||
114 | * Check the status of a batch request. If the current instance of the Batch object |
||
115 | * was used to make the request, the batch_id is already known and is therefore optional. |
||
116 | * |
||
117 | * @param string $batch_id ID of the batch about which to enquire |
||
118 | * |
||
119 | * @return array|false Assoc array of API response, decoded from JSON |
||
120 | */ |
||
121 | public function check_status($batch_id = null) |
||
129 | |||
130 | /** |
||
131 | * Get operations |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | public function get_operations() |
||
139 | |||
140 | /** |
||
141 | * Add an operation to the internal queue. |
||
142 | * |
||
143 | * @param string $http_verb GET, POST, PUT, PATCH or DELETE |
||
144 | * @param string $id ID for the operation within the batch |
||
145 | * @param string $method URL of the API request method |
||
146 | * @param array $args Assoc array of arguments (usually your data) |
||
147 | * |
||
148 | * @return void |
||
149 | */ |
||
150 | private function queueOperation($http_verb, $id, $method, $args = null) |
||
170 | } |
||
171 |