1 <?php
2 namespace MailChimp\Lists;
3
4 class Members extends Lists
5 {
6 /**
7 * Get a list of list members
8 * @param string $list_id
9 * @param array $query (See Above) OPTIONAL associative array of query parameters.
10 * @return object
11 */
12 public function getListMembers($list_id, array $query = [])
13 {
14 return self::execute("GET", "lists/{$list_id}/members", $query);
15 }
16
17 /**
18 * Get a single list members
19 * @param string $list_id
20 * @param string $email_address
21 * @param array $query (See Above) OPTIONAL associative array of query parameters.
22 * @return object
23 */
24 public function getListMember($list_id, $email_address, array $query = [])
25 {
26 $hash = self::getMemberHash($email_address);
27 return self::execute("GET", "lists/{$list_id}/members/{$hash}", $query);
28 }
29
30 /**
31 * Get the last 50 events of a member’s activity on a specific list, including opens, clicks, and unsubscribes.
32 * Available query fields:
33 * array["fields"] array list of strings of response fields to return
34 * array["exclude_fields"] array list of strings of response fields to exclude (not to be used with "fields")
35 * @param string $list_id
36 * @param string $email_address
37 * @param array $query (See Above) OPTIONAL associative array of query parameters.
38 * @return object
39 */
40 public function getMemberActiity($list_id, $email_address, array $query = [])
41 {
42 $hash = self::getMemberHash($email_address);
43 return self::execute("GET", "lists/{$list_id}/members/{$hash}/activity", $query);
44 }
45
46 /**
47 * Get the last 50 Goal events for a member on a specific list
48 * Available query fields:
49 * array["fields"] array list of strings of response fields to return
50 * array["exclude_fields"] array list of strings of response fields to exclude (not to be used with "fields")
51 * @param string $list_id
52 * @param string $email_address
53 * @param array $query (See Above) OPTIONAL associative array of query parameters.
54 * @return object
55 */
56 public function getMemberGoals($list_id, $email_address, array $query = [])
57 {
58 $hash = self::getMemberHash($email_address);
59 return self::execute("GET", "lists/{$list_id}/members/{$hash}/goals", $query);
60 }
61
62 /**
63 * Get recent notes for a specific list member
64 * Available query fields:
65 * array["fields"] array list of strings of response fields to return
66 * array["exclude_fields"] array list of strings of response fields to exclude (not to be used with "fields")
67 * array["count"] int number of records to return
68 * array["offset"] int number of records from a collection to skip.
69 * @param string $list_id
70 * @param string $email_address
71 * @param array $query (See Above) OPTIONAL associative array of query parameters.
72 * @return object
73 */
74 public function getMemberNotes($list_id, $email_address, array $query = [])
75 {
76 $hash = self::getMemberHash($email_address);
77 return self::execute("GET", "lists/{$list_id}/members/{$hash}/notes", $query);
78 }
79
80 /**
81 * Get a specific note for a specific list member.
82 * Available query fields:
83 * array["fields"] array list of strings of response fields to return
84 * array["exclude_fields"] array list of strings of response fields to exclude (not to be used with "fields")
85 * @param string $list_id
86 * @param string $email_address
87 * @param array $query (See Above) OPTIONAL associative array of query parameters.
88 * @return object
89 */
90 public function getMemberNote($list_id, $email_address, $note_id, array $query = [])
91 {
92 $hash = self::getMemberHash($email_address);
93 return self::execute("GET", "lists/{$list_id}/members/{$hash}/notes/{$note_id}", $query);
94 }
95
96
97 /**
98 * Add List Member
99 * "email_address" string required
100 * "status" string required
101 * Possible Values: subscribed,unsubscribed,cleaned,pending
102 * array["optional_settings"]
103 * @param string $list_id
104 * @param string $email_address
105 * @param string $status
106 * @param array $optional_settings
107 * @return object
108 */
109 public function addListMember($list_id, $email_address, $status, array $optional_settings = null)
110 {
111 $optional_fields = ["email_type", "merge_fields", "interests", "language", "vip", "location"];
112 $data = [
113 "email_address" => $email_address,
114 "status" => $status
115 ];
116
117 if (isset($optional_settings)) {
118 $data = array_merge($data, self::optionalFields($optional_fields, $optional_settings));
119 }
120
121 return self::execute("POST", "lists/{$list_id}/members", $data);
122 }
123
124 /**
125 * Add or Update List Member
126 * array["data"]
127 * ["status"] string required
128 * Possible Values: subscribed,unsubscribed,cleaned,pending
129 * @param string $list_id
130 * @param string $email_address
131 * @param array subscriber data
132 * @return object
133 */
134 public function upsertListMember($list_id, $email_address, array $data = [])
135 {
136 $hash = self::getMemberHash($email_address);
137 return self::execute("PUT", "lists/{$list_id}/members/{$hash}", $data);
138 }
139
140 /**
141 * Update List Member
142 * array["data"]
143 * ["email_address"] string required
144 * ["status"] string required
145 * Possible Values: subscribed,unsubscribed,cleaned,pending
146 * @param string $list_id
147 * @param array subscriber data
148 * @return object
149 */
150 public function updateListMember($list_id, $email_address, array $data = [])
151 {
152 $hash = self::getMemberHash($email_address);
153 return self::execute("PATCH", "lists/{$list_id}/members/{$hash}", $data);
154 }
155
156 /**
157 * Add a new note for a specific subscriber
158 * array["data"]
159 * ["note"] string The content of the note.
160 * @param string $list_id
161 * @param string $email_address
162 * @param array $data (See Above) OPTIONAL associative array of query parameters.
163 * @return object
164 */
165 public function addMemberNote($list_id, $email_address, array $data = [])
166 {
167 $hash = self::getMemberHash($email_address);
168 return self::execute("POST", "lists/{$list_id}/members/{$hash}/notes", $data);
169 }
170
171 /**
172 * Update a specific note for a specific list member.
173 * array["data"]
174 * ["note"] string The content of the note.
175 * @param string $list_id
176 * @param string $email_address
177 * @param int $noteId
178 * @param array $data (See Above) OPTIONAL associative array of query parameters.
179 * @return object
180 */
181 public function updateMemberNote($list_id, $email_address, $note_id, array $data = [])
182 {
183 $hash = self::getMemberHash($email_address);
184 return self::execute("PATCH", "lists/{$list_id}/members/{$hash}/notes/{$note_id}", $data);
185 }
186
187 /**
188 * Delete a specific note for a specific list member.
189 * @param string $list_id
190 * @param string $email_address
191 * @param int $noteId
192 */
193 public function deleteMemberNote($list_id, $email_address, $note_id)
194 {
195 $hash = self::getMemberHash($email_address);
196 return self::execute("DELETE", "lists/{$list_id}/members/{$hash}/notes/{$note_id}");
197 }
198
199 /**
200 * Delete a subscriber
201 * @param string $list_id
202 * @param string email address
203 */
204 public function deleteListMember($list_id, $email_address)
205 {
206 $hash = self::getMemberHash($email_address);
207 return self::execute("DELETE", "lists/{$list_id}/members/{$hash}");
208 }
209
210 }
211