@@ -22,6 +22,9 @@ public function __construct(?ContactsApi $contactsApi = null)
22
22
$ this ->contactsApi = $ contactsApi ?? $ this ->createDefaultContactsApi ();
23
23
}
24
24
25
+ /**
26
+ * @return \Brevo\Client\Api\ContactsApi
27
+ */
25
28
private function createDefaultContactsApi (): ContactsApi
26
29
{
27
30
$ config = Configuration::getDefaultConfiguration ()
@@ -30,11 +33,21 @@ private function createDefaultContactsApi(): ContactsApi
30
33
return new ContactsApi (new Client , $ config );
31
34
}
32
35
36
+ /**
37
+ * @param \Brevo\Client\Api\ContactsApi $contactsApi
38
+ *
39
+ * @return void
40
+ */
33
41
public function setContactsApi (ContactsApi $ contactsApi ): void
34
42
{
35
43
$ this ->contactsApi = $ contactsApi ;
36
44
}
37
45
46
+ /**
47
+ * @param string $email
48
+ *
49
+ * @return \Brevo\Client\Model\GetExtendedContactDetails|null
50
+ */
38
51
public function getContactInfo (string $ email ): ?GetExtendedContactDetails
39
52
{
40
53
try {
@@ -46,7 +59,14 @@ public function getContactInfo(string $email): ?GetExtendedContactDetails
46
59
}
47
60
}
48
61
49
- public function subscribe (string $ email , string $ listId , array $ attributes = []): bool
62
+ /**
63
+ * @param string $email
64
+ * @param integer $listId
65
+ * @param array $attributes
66
+ *
67
+ * @return bool
68
+ */
69
+ public function subscribe (string $ email , int $ listId , array $ attributes = []): bool
50
70
{
51
71
try {
52
72
// Check if contact exists
@@ -76,7 +96,7 @@ public function subscribe(string $email, string $listId, array $attributes = [])
76
96
// Subscribe to list
77
97
$ addContactToList = new AddContactToList ;
78
98
$ addContactToList ->setEmails ([$ email ]);
79
- $ this ->contactsApi ->addContactToList ($ listId , $ addContactToList );
99
+ $ this ->contactsApi ->addContactToList ( $ listId , $ addContactToList );
80
100
81
101
return true ;
82
102
} catch (ApiException $ e ) {
@@ -86,7 +106,13 @@ public function subscribe(string $email, string $listId, array $attributes = [])
86
106
}
87
107
}
88
108
89
- public function unsubscribe (string $ email , string $ listId ): bool
109
+ /**
110
+ * @param string $email
111
+ * @param integer $listId
112
+ *
113
+ * @return bool
114
+ */
115
+ public function unsubscribe (string $ email , int $ listId ): bool
90
116
{
91
117
try {
92
118
$ this ->removeContactFromList ($ email , $ listId );
@@ -103,14 +129,13 @@ public function unsubscribe(string $email, string $listId): bool
103
129
/**
104
130
* @throws \Brevo\Client\ApiException
105
131
*/
106
- private function createOrUpdateContact (string $ email , array $ attributes ): void
132
+ public function createOrUpdateContact (string $ email , array $ attributes ): void
107
133
{
108
134
try {
109
135
$ this ->updateExistingContact ($ email , $ attributes );
110
136
} catch (ApiException $ e ) {
111
137
if ($ e ->getCode () === 404 ) {
112
138
$ this ->createNewContact ($ email , $ attributes );
113
-
114
139
return ;
115
140
}
116
141
throw $ e ;
@@ -134,7 +159,7 @@ private function updateExistingContact(string $email, array $attributes): void
134
159
/**
135
160
* @throws \Brevo\Client\ApiException
136
161
*/
137
- private function createNewContact (string $ email , array $ attributes ): void
162
+ public function createNewContact (string $ email , array $ attributes ): void
138
163
{
139
164
$ createContact = new CreateContact ;
140
165
$ createContact ->setEmail ($ email );
@@ -149,23 +174,30 @@ private function createNewContact(string $email, array $attributes): void
149
174
/**
150
175
* @throws \Brevo\Client\ApiException
151
176
*/
152
- private function addContactToList (string $ email , string $ listId ): void
177
+ public function addContactToList (string $ email , int $ listId ): void
153
178
{
154
- $ listRequest = new AddContactToList ;
179
+ $ listRequest = new AddContactToList () ;
155
180
$ listRequest ->setEmails ([$ email ]);
156
181
$ this ->contactsApi ->addContactToList ($ listId , $ listRequest );
157
182
}
158
183
159
184
/**
160
185
* @throws \Brevo\Client\ApiException
161
186
*/
162
- private function removeContactFromList (string $ email , string $ listId ): void
187
+ private function removeContactFromList (string $ email , int $ listId ): void
163
188
{
164
189
$ listRequest = new RemoveContactFromList ;
165
190
$ listRequest ->setEmails ([$ email ]);
166
191
$ this ->contactsApi ->removeContactFromList ($ listId , $ listRequest );
167
192
}
168
193
194
+ /**
195
+ * @param \Brevo\Client\ApiException $e
196
+ * @param string $context
197
+ * @param bool $isWarning
198
+ *
199
+ * @return void
200
+ */
169
201
private function handleApiException (ApiException $ e , string $ context , bool $ isWarning = false ): void
170
202
{
171
203
$ logMethod = $ isWarning ? 'warning ' : 'error ' ;
0 commit comments