Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
basiliscus edited this page Aug 9, 2016 · 51 revisions

Deprecation

This project has now been deprecated. MaleOrang is its replacement.

General info

Ecwid-mailchimp provides access to MailChimp API v2.0 and v1.3 methods from Java code.

Refer to the javadoc pages to learn how to use Ecwid-mailchimp.

Currently Ecwid-mailchimp itself has wrappers for a limited number of MailChimp API methods only (see the complete list). However, it is very easy to extend the API and add support for any method you need.

Sample code

Here is some sample code showing how to use the wrapper.

Suppose you want to subscribe a person to your list and then check his status. That's easy:

// Holds a subscriber's merge_vars info (see http://apidocs.mailchimp.com/api/2.0/lists/subscribe.php )
public static class MergeVars extends MailChimpObject {
	@Field
	public String EMAIL, FNAME, LNAME;

	public MergeVars() { }
	
	public MergeVars(String email, String fname, String lname) {
		this.EMAIL = email;
		this.FNAME = fname;
		this.LNAME = lname;
	}
}

...

// reuse the same MailChimpClient object whenever possible
MailChimpClient mailChimpClient = new MailChimpClient(); 

// Subscribe a person
    SubscribeMethod subscribeMethod = new SubscribeMethod();
    subscribeMethod.apikey = apikey;
    subscribeMethod.id = listId;
    subscribeMethod.email = new Email();
    subscribeMethod.email.email = email;
    subscribeMethod.double_optin = false;
    subscribeMethod.update_existing = true;
    subscribeMethod.merge_vars = new MergeVars(email, "Vasya", "Pupkin");
    mailChimpClient.execute(subscribeMethod);

// check his status
MemberInfoMethod memberInfoMethod = new MemberInfoMethod();
memberInfoMethod.apikey = apikey;
memberInfoMethod.id = listId;
memberInfoMethod.emails = Arrays.asList(subscribeMethod.email);

MemberInfoResult memberInfoResult = mailChimpClient.execute(memberInfoMethod);
MemberInfoData data = memberInfoResult.data.get(0);
System.out.println(data.email+"'s status is "+data.status);

This sample can be found in source code.

Maven integration

Ecwid-mailchimp is accessible as maven artifact, just add the following dependency declaration to your pom:

<dependency>
    <groupId>com.ecwid</groupId>
    <artifactId>ecwid-mailchimp</artifactId>
    <version>2.0.1.0</version>
</dependency>
Clone this wiki locally