@@ 118-137 (lines=20) @@ | ||
115 | * @return bool |
|
116 | * @throws ApiError |
|
117 | */ |
|
118 | public function hasMember(string $email, string $listName = ''): bool |
|
119 | { |
|
120 | $listId = $this->lists->findByName($listName)->getId(); |
|
121 | ||
122 | $response = $this->client->get(Resources::$Contact, ['ContactsList' => $listId]); |
|
123 | ||
124 | if (! $response->success()) { |
|
125 | throw ApiError::responseError($response->getReasonPhrase(), 'mailjet', $response->getStatus()); |
|
126 | } |
|
127 | ||
128 | $contacts = $response->getData(); |
|
129 | ||
130 | foreach ($contacts as $contact) { |
|
131 | if ($contact['Email'] == $email) { |
|
132 | return true; |
|
133 | } |
|
134 | } |
|
135 | ||
136 | return false; |
|
137 | } |
|
138 | ||
139 | /** |
|
140 | * @param string $email |
|
@@ 145-164 (lines=20) @@ | ||
142 | * @return bool |
|
143 | * @throws ApiError |
|
144 | */ |
|
145 | public function isSubscribed(string $email, string $listName = ''): bool |
|
146 | { |
|
147 | $listId = $this->lists->findByName($listName)->getId(); |
|
148 | ||
149 | $response = $this->client->get(Resources::$ContactGetcontactslists, ['id' => $email]); |
|
150 | ||
151 | if (! $response->success()) { |
|
152 | throw ApiError::responseError($response->getReasonPhrase(), 'mailjet', $response->getStatus()); |
|
153 | } |
|
154 | ||
155 | $contactLists = $response->getData(); |
|
156 | ||
157 | foreach ($contactLists as $list) { |
|
158 | if ($list['ListID'] == $listId && $list['IsUnsub'] != true) { |
|
159 | return true; |
|
160 | } |
|
161 | } |
|
162 | ||
163 | return false; |
|
164 | } |
|
165 | ||
166 | /** |
|
167 | * @param string $email |