1 <?php
2 namespace MailChimp\Batches;
3
4 use MailChimp\MailChimp as MailChimp;
5
6 class Batches extends MailChimp
7 {
8
9 /**
10 * Get a summary of batch requests that have been made.
11 *
12 * Available query fields:
13 * array["fields"] array list of strings of response fields to return
14 * array["exclude_fields"] array list of strings of response fields to exclude (not to be used with "fields")
15 * array["count"] int number of records to return
16 * array["offset"] int number of records from a collection to skip.
17 * @param array $query (See Above) OPTIONAL associative array of query parameters.
18 * @return object
19 */
20 public function getBatches (array $query = [])
21 {
22 return self::execute("GET", "batches", $query);
23 }
24
25 /**
26 * Get the status of a batch request.
27 *
28 * Available query fields:
29 * array["fields"] array list of strings of response fields to return
30 * array["exclude_fields"] array list of strings of response fields to exclude (not to be used with "fields")
31 * @param string $batch_id
32 * @param array $query (See Above) OPTIONAL associative array of query parameters.
33 * @return object
34 */
35 public function getBatch ($batch_id, array $query = [])
36 {
37 return self::execute("GET", "batches/{$batch_id}", $query);
38 }
39
40 /**
41 * Begin processing a batch operations request.
42 *
43 * @param array $data
44 * @return object
45 */
46 public function createBatch ($data = array(["method" => "", "path" => "", "params" => null, "body"=> null, "operation_id" => null]) )
47 {
48 $operation = [];
49
50 foreach ($data as $d) {
51 $op = [];
52 $op["method"] = $d["method"];
53 $op["path"] = $d["path"];
54
55 if ($d["method"] == "GET" && !empty($d["params"])) {
56 $op["params"] = $d["params"];
57 } elseif ($d["method"] == "POST" || $d["method"] == "PATCH" || $d["method"] == "PUT") {
58 $op["body"] = $d["body"];
59 }
60
61 if (isset($d["operation_id"])) {
62 $op["operation_id"] = $d["operation_id"];
63 }
64
65 $operation[] = $op;
66 }
67
68 $operations = [ "operations" => $operation ];
69 return self::execute("POST", "batches", $operations);
70 }
71
72 /**
73 * Delete a batch request and stop if from processing further.
74 *
75 * @param string $batch_id
76 */
77 public function deleteBatch ($batch_id)
78 {
79 return self::execute("DELETE", "batches/{$batch_id}");
80 }
81
82 }
83