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) |
||
19 | { |
||
20 | $this->MailChimp = $MailChimp; |
||
21 | $this->batch_id = $batch_id; |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Add an HTTP DELETE request operation to the batch - for deleting data |
||
26 | * @param string $id ID for the operation within the batch |
||
27 | * @param string $method URL of the API request method |
||
28 | * @return void |
||
29 | */ |
||
30 | public function delete($id, $method) |
||
34 | |||
35 | /** |
||
36 | * Add an HTTP GET request operation to the batch - for retrieving data |
||
37 | * @param string $id ID for the operation within the batch |
||
38 | * @param string $method URL of the API request method |
||
39 | * @param array $args Assoc array of arguments (usually your data) |
||
40 | * @return void |
||
41 | */ |
||
42 | public function get($id, $method, $args = array()) |
||
46 | |||
47 | /** |
||
48 | * Add an HTTP PATCH request operation to the batch - for performing partial updates |
||
49 | * @param string $id ID for the operation within the batch |
||
50 | * @param string $method URL of the API request method |
||
51 | * @param array $args Assoc array of arguments (usually your data) |
||
52 | * @return void |
||
53 | */ |
||
54 | public function patch($id, $method, $args = array()) |
||
58 | |||
59 | /** |
||
60 | * Add an HTTP POST request operation to the batch - for creating and updating items |
||
61 | * @param string $id ID for the operation within the batch |
||
62 | * @param string $method URL of the API request method |
||
63 | * @param array $args Assoc array of arguments (usually your data) |
||
64 | * @return void |
||
65 | */ |
||
66 | public function post($id, $method, $args = array()) |
||
70 | |||
71 | /** |
||
72 | * Add an HTTP PUT request operation to the batch - for creating new items |
||
73 | * @param string $id ID for the operation within the batch |
||
74 | * @param string $method URL of the API request method |
||
75 | * @param array $args Assoc array of arguments (usually your data) |
||
76 | * @return void |
||
77 | */ |
||
78 | public function put($id, $method, $args = array()) |
||
82 | |||
83 | /** |
||
84 | * Execute the batch request |
||
85 | * @param int $timeout Request timeout in seconds (optional) |
||
86 | * @return array|false Assoc array of API response, decoded from JSON |
||
87 | */ |
||
88 | public function execute($timeout = 10) |
||
100 | |||
101 | /** |
||
102 | * Check the status of a batch request. If the current instance of the Batch object |
||
103 | * was used to make the request, the batch_id is already known and is therefore optional. |
||
104 | * @param string $batch_id ID of the batch about which to enquire |
||
105 | * @return array|false Assoc array of API response, decoded from JSON |
||
106 | */ |
||
107 | public function check_status($batch_id = null) |
||
115 | |||
116 | /** |
||
117 | * Add an operation to the internal queue. |
||
118 | * @param string $http_verb GET, POST, PUT, PATCH or DELETE |
||
119 | * @param string $id ID for the operation within the batch |
||
120 | * @param string $method URL of the API request method |
||
121 | * @param array $args Assoc array of arguments (usually your data) |
||
122 | * @return void |
||
123 | */ |
||
124 | private function queueOperation($http_verb, $id, $method, $args = null) |
||
139 | } |
||
140 |