-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExistingMethodExample.java
42 lines (36 loc) · 1.49 KB
/
ExistingMethodExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.ecwid.maleorang.examples;
import com.ecwid.maleorang.MailchimpClient;
import com.ecwid.maleorang.MailchimpObject;
import com.ecwid.maleorang.method.v3_0.lists.members.EditMemberMethod;
import com.ecwid.maleorang.method.v3_0.lists.members.MemberInfo;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
/**
* Demonstrates how to use an existing method implementation (namely {@link com.ecwid.maleorang.method.v3_0.lists.members.EditMemberMethod.CreateOrUpdate}).
*/
public class ExistingMethodExample {
private final String apiKey, listId;
@Parameters({"mailchimp.test.apikey", "mailchimp.test.listid"})
private ExistingMethodExample(String apiKey, String listId) {
this.apiKey = apiKey;
this.listId = listId;
}
/**
* Subscribes a user to list.
*/
@Test
public void run() throws Exception {
MailchimpClient client = new MailchimpClient(apiKey);
try {
EditMemberMethod.CreateOrUpdate method = new EditMemberMethod.CreateOrUpdate(listId, "[email protected]");
method.status = "subscribed";
method.merge_fields = new MailchimpObject();
method.merge_fields.mapping.put("FNAME", "Vasya");
method.merge_fields.mapping.put("LNAME", "Pupkin");
MemberInfo member = client.execute(method);
System.err.println("The user has been successfully subscribed: " + member);
} finally {
client.close();
}
}
}