From 8ea27d395e52af41db9ffc154fc3bfad34628c65 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Wed, 18 Apr 2012 13:30:53 -0400 Subject: [PATCH 01/36] Initial commit of the modifications from the original project with adjustments to pom and the addition of a new method templateAdd with supporting serialization classes. --- mailjimp-core/pom.xml | 1 + .../java/mailjimp/service/IMailJimpService.java | 15 +++++++++++++++ .../service/impl/AbstractMailJimpService.java | 2 ++ .../service/impl/MailJimpJsonService.java | 15 ++++++++++++++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/mailjimp-core/pom.xml b/mailjimp-core/pom.xml index db7f441..4022f9d 100644 --- a/mailjimp-core/pom.xml +++ b/mailjimp-core/pom.xml @@ -60,4 +60,5 @@ 2.1 + ca.morningstar.mailjimp diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index ea0f65b..47abb20 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -256,6 +256,7 @@ public interface IMailJimpService extends Serializable { */ public boolean listInterestGroupDelete(String listId, String groupName, Integer groupingId) throws MailJimpException; + /** * Change the name of an interest group. * @@ -267,4 +268,18 @@ public interface IMailJimpService extends Serializable { * @throws MailJimpException If the interest group could not be renamed. */ public boolean listInterestGroupUpdate(String listId, String oldName, String newName) throws MailJimpException; + + /** + Parameters + * name the name for the template - names must be unique and a max of 50 bytes + * html a string specifying the entire template to be created. This is NOT campaign content. They are intended to utilize our template language. * + * @return True if succeeded, an error otherwise. + * @throws MailJimpException If the interest group could not be renamed. + */ + public boolean tempateAdd(String name, String html) throws MailJimpException; + + + + + } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/AbstractMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/AbstractMailJimpService.java index a6c1fcc..d0d1cb7 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/AbstractMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/AbstractMailJimpService.java @@ -18,6 +18,7 @@ package mailjimp.service.impl; import mailjimp.service.IMailJimpService; +import mailjimp.service.MailJimpException; abstract class AbstractMailJimpService implements IMailJimpService { protected static final String SERVER_URL_PREFIX_HTTP = "http://"; @@ -102,4 +103,5 @@ protected String buildServerURL() { .append('/'); return serverURL.toString(); } + } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 2bcc453..7240a29 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -113,7 +113,7 @@ public void init() { m.setDateFormat(new SimpleDateFormat("yyyy-MM-MM HH:mm:ss")); } - private V performRequest(String method, Object param, TypeReference typeRef) throws MailJimpException { + protected V performRequest(String method, Object param, TypeReference typeRef) throws MailJimpException { String requestJson = null; try { requestJson = m.writeValueAsString(param); @@ -283,4 +283,17 @@ public Boolean listInterestGroupingDelete(Integer groupingId) throws MailJimpExc log.debug("Delete interesting grouping status: {}", response); return response; } + + + public int createTemplate(String name, String html) throws MailJimpException { + int response = performRequest("templateAdd", new mailjimp.dom.request.template.TemplateAddRequest(apiKey, name, html), new TypeReference() {/* empty */}); + log.debug("Tempate Add: {}", response); + return response; + } + +@Override +public boolean tempateAdd(String name, String html) throws MailJimpException { + // TODO Auto-generated method stub + return false; +} } \ No newline at end of file From 4d578f962204ba79ed45577e8104b6932d578445 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Wed, 18 Apr 2012 13:40:41 -0400 Subject: [PATCH 02/36] this file supports the serialization of the request to create a template. --- .../request/template/TemplateAddRequest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java new file mode 100644 index 0000000..44b5054 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java @@ -0,0 +1,39 @@ +package mailjimp.dom.request.template; + +import org.codehaus.jackson.annotate.JsonProperty; + +import mailjimp.dom.request.MailJimpRequest; + + +public class TemplateAddRequest extends MailJimpRequest { + private static final long serialVersionUID = 1L; + + @JsonProperty + private String name; + + @JsonProperty + private String html; + + public TemplateAddRequest(String apikey, String name, String html) { + super(apikey); + this.name =name; + this.html = html; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getHtml() { + return html; + } + + public void setHtml(String html) { + this.html = html; + } + +} From 137c064da6b33717e0c4d6d820d0bf97733c171f Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 18 Apr 2012 14:50:42 -0300 Subject: [PATCH 03/36] Update README.markdown --- README.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.markdown b/README.markdown index 618481a..8624fd1 100644 --- a/README.markdown +++ b/README.markdown @@ -2,6 +2,10 @@ #### About +This fork is adapted from the original. My goal is to add in some missing service calls surrounding templates and campaigns. + +#### Original About. + MailJimp is a MailChimp library built in Java intended for use within Maven-enabled Spring-based applications. MailJimp was tested against version 1.3 of the MailChimp API though most of the methods will work with version 1.2. (But I really don't know why you would use it ;) The Maven part is not mandatory, of course - feel free to download the source and build yourself the library. The Spring part is also not mandatory, as long as you deploy the library in a container that understands the `@PostConstruct` annotation, or you manually invoke `MailJimpService::init()` after construction. From d697bf472e571aabd658140c5707580798a168cf Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Wed, 18 Apr 2012 14:20:58 -0400 Subject: [PATCH 04/36] fixed duplicate service, fixed template error. --- .../java/mailjimp/dom/MailJimpConstants.java | 12 ++ .../mailjimp/dom/request/MailJimpRequest.java | 2 +- .../mailjimp/service/IMailJimpService.java | 6 +- .../service/impl/AbstractMailJimpService.java | 107 ------------------ .../service/impl/MailJimpJsonService.java | 20 ++-- 5 files changed, 23 insertions(+), 124 deletions(-) delete mode 100644 mailjimp-core/src/main/java/mailjimp/service/impl/AbstractMailJimpService.java diff --git a/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java b/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java index 1b3f6eb..806af93 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java @@ -32,4 +32,16 @@ public interface MailJimpConstants extends Serializable { String MERGE_EMAIL_TYPE = "EMAIL_TYPE"; String MERGE_GROUPINGS = "GROUPINGS"; String MERGE_GROUPS = "groups"; + + // Campaign Consts + + final String CAMPAIGNTYPE_REGULAR = "regular"; + final String CAMPAIGNTYPE_PLAINTEXT = "plaintext"; + final String CAMPAIGNTYPE_ABSPLIT = "absplit"; + final String CAMPAIGNTYPE_RSS = "rss"; + final String CAMPAIGNTYPE_AUTO = "auto"; + + + + } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/MailJimpRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/MailJimpRequest.java index 3c1c415..01de0bb 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/MailJimpRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/MailJimpRequest.java @@ -20,7 +20,7 @@ import java.io.Serializable; public abstract class MailJimpRequest implements Serializable { - protected String apikey; +protected String apikey; protected MailJimpRequest(String apikey) { this.apikey = apikey; diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index 47abb20..a02c8cf 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -273,12 +273,10 @@ public interface IMailJimpService extends Serializable { Parameters * name the name for the template - names must be unique and a max of 50 bytes * html a string specifying the entire template to be created. This is NOT campaign content. They are intended to utilize our template language. * - * @return True if succeeded, an error otherwise. + * @return new templateId * @throws MailJimpException If the interest group could not be renamed. */ - public boolean tempateAdd(String name, String html) throws MailJimpException; - - + public int templateAdd(String name, String html) throws MailJimpException; diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/AbstractMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/AbstractMailJimpService.java deleted file mode 100644 index d0d1cb7..0000000 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/AbstractMailJimpService.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2011 Michael Laccetti - * - * This file is part of MailJimp. - * - * MailJimp is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * MailJimp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with MailJimp. If not, see . - */ -package mailjimp.service.impl; - -import mailjimp.service.IMailJimpService; -import mailjimp.service.MailJimpException; - -abstract class AbstractMailJimpService implements IMailJimpService { - protected static final String SERVER_URL_PREFIX_HTTP = "http://"; - protected static final String SERVER_URL_PREFIX_HTTPS = "https://"; - protected static final String SERVER_URL_MAIN = ".api.mailchimp.com/"; - - //Credentials - protected String username; - protected String password; - protected String apiKey; - protected String apiVersion; - protected boolean ssl = true; - - protected AbstractMailJimpService() { - // empty - } - - protected AbstractMailJimpService(String username, String password, String apiKey, String apiVersion, boolean ssl) { - this.username = username; - this.password = password; - this.apiKey = apiKey; - this.apiVersion = apiVersion; - this.ssl = ssl; - } - - public void setUsername(String username) { - this.username = username; - } - - public void setPassword(String password) { - this.password = password; - } - - public void setApiKey(String apiKey) { - this.apiKey = apiKey; - } - - public void setApiVersion(String apiVersion) { - this.apiVersion = apiVersion; - } - - public void setSsl(boolean ssl) { - this.ssl = ssl; - } - - protected void checkConfig() { - if (apiKey == null || apiKey.isEmpty()) { - throw new IllegalArgumentException("API key cannot be null/empty."); - } - if (apiVersion == null || apiVersion.isEmpty()) { - throw new IllegalArgumentException("API version cannot be null/empty."); - } - } - - /** - * Constructs the url of the MailChimp server to talk to. This takes the data - * center out of the api key and knows if the connection should get secured - * via ssl. - * - * @return The URL of the MailChimp server to use. - */ - protected String buildServerURL() { - StringBuilder serverURL = new StringBuilder(); - // choose the protocol - if (ssl) { - serverURL.append(SERVER_URL_PREFIX_HTTPS); - } else { - serverURL.append(SERVER_URL_PREFIX_HTTP); - } - - final int dcSeparater = apiKey.lastIndexOf('-'); - final String dcLocation = dcSeparater != -1 ? apiKey.substring(dcSeparater + 1) : "us1"; - - serverURL - // parse the data center - .append(dcLocation) - // bring in the clue - .append(SERVER_URL_MAIN) - // add the version - .append(apiVersion) - // and finish with a slash. - .append('/'); - return serverURL.toString(); - } - -} \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 7240a29..3d1413c 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -60,6 +60,7 @@ import mailjimp.dom.response.list.MemberInfo; import mailjimp.dom.response.list.MemberResponseInfo; import mailjimp.dom.security.ApiKey; +import mailjimp.service.AbstractMailJimpService; import mailjimp.service.MailJimpException; import org.apache.commons.io.IOUtils; @@ -284,16 +285,11 @@ public Boolean listInterestGroupingDelete(Integer groupingId) throws MailJimpExc return response; } - - public int createTemplate(String name, String html) throws MailJimpException { - int response = performRequest("templateAdd", new mailjimp.dom.request.template.TemplateAddRequest(apiKey, name, html), new TypeReference() {/* empty */}); - log.debug("Tempate Add: {}", response); - return response; - } - -@Override -public boolean tempateAdd(String name, String html) throws MailJimpException { - // TODO Auto-generated method stub - return false; -} + + @Override + public int templateAdd(String name, String html) throws MailJimpException { + int response = performRequest("templateAdd", new mailjimp.dom.request.template.TemplateAddRequest(apiKey, name, html), new TypeReference() {/* empty */}); + log.debug("Tempate Add: {}", response); + return response; + } } \ No newline at end of file From 176bc5c4b7144cc40ecca428f53095827f35ee4b Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Wed, 18 Apr 2012 14:45:56 -0400 Subject: [PATCH 05/36] fixed javac bug by casting result of generic --- .../main/java/mailjimp/service/impl/MailJimpJsonService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 3d1413c..54c3885 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -151,7 +151,8 @@ protected V performRequest(String method, Object param, TypeReference typ } try { - V val = m.readValue(responseJson, typeRef); + //TMG Added cast to fix bug in JavaC: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954 + V val = (V) m.readValue(responseJson, typeRef); return val; } catch (Exception ex) { log.error(String.format("Could not convert JSON to expected type (%s).", typeRef.getType().getClass().getCanonicalName()), ex); From 07f8ee3fa55798fbd76cb91e4d5a9527b9c45d07 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 10:07:32 -0400 Subject: [PATCH 06/36] added template del and update. added some test cases --- .../request/template/TemplateDelRequest.java | 25 +++++ .../template/TemplateUpdateRequest.java | 55 +++++++++++ .../mailjimp/service/IMailJimpService.java | 23 ++++- .../service/impl/MailJimpJsonService.java | 15 +++ .../service/TestMailJimpJsonService.java | 8 +- .../TestMailJimpJsonServiceTemplate.java | 92 +++++++++++++++++++ mailjimp-core/src/test/resources/.gitignore | 2 + 7 files changed, 215 insertions(+), 5 deletions(-) create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateDelRequest.java create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java create mode 100644 mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java create mode 100644 mailjimp-core/src/test/resources/.gitignore diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateDelRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateDelRequest.java new file mode 100644 index 0000000..6d3ad16 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateDelRequest.java @@ -0,0 +1,25 @@ +package mailjimp.dom.request.template; + +import org.codehaus.jackson.annotate.JsonProperty; + +import mailjimp.dom.request.MailJimpRequest; + +public class TemplateDelRequest extends MailJimpRequest { + + @JsonProperty + private int id; + + public TemplateDelRequest(String apikey, int id) { + super(apikey); + this.id = id; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + +} diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java new file mode 100644 index 0000000..a2ae31a --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java @@ -0,0 +1,55 @@ +package mailjimp.dom.request.template; + +import java.util.HashMap; +import java.util.Map; + +import mailjimp.dom.request.MailJimpRequest; + +import org.codehaus.jackson.annotate.JsonProperty; + + +public class TemplateUpdateRequest extends MailJimpRequest { + private static final long serialVersionUID = 1L; + + private int id = -1; + + @JsonProperty + private Map values = null; + + public TemplateUpdateRequest(String apikey, int id, String name, String html) { + super(apikey); + + if (values == null) + values = new HashMap(); + else + values.clear(); + + this.id = id; + + if (name != null) + values.put("name", name); + + if (html != null) + values.put("html", html); + + + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Map getValues() { + return values; + } + + public void setValues(Map values) { + this.values = values; + } + + +} diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index a02c8cf..bce0b33 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -274,9 +274,28 @@ public interface IMailJimpService extends Serializable { * name the name for the template - names must be unique and a max of 50 bytes * html a string specifying the entire template to be created. This is NOT campaign content. They are intended to utilize our template language. * * @return new templateId - * @throws MailJimpException If the interest group could not be renamed. + * @throws MailJimpException If the template couldn't be added. */ - public int templateAdd(String name, String html) throws MailJimpException; + public int templateAdd(String name, String html) throws MailJimpException; + + + /** + Parameters + * id the template id + * @return boolean success + * @throws MailJimpException If the template id can't be found + */ + boolean templateDel(int id) throws MailJimpException; + + /** + Parameters + * id the template id + * name the new name, null if no change + * html the new html, null if no change + * @return boolean success + * @throws MailJimpException If the template id can't be found or both name and html are null. + */ + boolean templateUpdate(int id, String name, String html) throws MailJimpException; diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 54c3885..1ac0b18 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -293,4 +293,19 @@ public int templateAdd(String name, String html) throws MailJimpException { log.debug("Tempate Add: {}", response); return response; } + + + @Override + public boolean templateDel(int id) throws MailJimpException { + boolean response = performRequest("templateDel", new mailjimp.dom.request.template.TemplateDelRequest(apiKey, id), new TypeReference() {/* empty */}); + log.debug("Tempate Add: {}", response); + return response; + } + + @Override + public boolean templateUpdate(int id, String name, String html) throws MailJimpException { + boolean response = performRequest("templateUpdate", new mailjimp.dom.request.template.TemplateUpdateRequest(apiKey, id, name, html), new TypeReference() {/* empty */}); + log.debug("Tempate Update: {}", response); + return response; + } } \ No newline at end of file diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonService.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonService.java index ffc5e8f..8a4f0ee 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonService.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonService.java @@ -94,6 +94,8 @@ public class TestMailJimpJsonService extends AbstractServiceTester { */ private static String groupName = RandomStringUtils.randomAlphabetic(8); private static String newGroupName = RandomStringUtils.randomAlphabetic(8); + + private static String templateName = RandomStringUtils.randomAlphabetic(8); @BeforeClass public static void setup() { @@ -106,7 +108,7 @@ public static void setup() { public void after() { System.out.println("\n\n\n"); } - + @Test public void testLists() { try { @@ -374,7 +376,7 @@ public void testListInterestGroupAdd() { try { log.debug("Test list interest group add"); Boolean response = mSvc.listInterestGroupAdd(listId, groupName, groupingId); - log.debug("List interest group add: {}", response); + log.debug("List interest group atdd: {}", response); } catch (MailJimpException mje) { processError(mje); } @@ -401,4 +403,4 @@ public void testListInterestGroupDelete() { processError(mje); } } -} \ No newline at end of file + } \ No newline at end of file diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java new file mode 100644 index 0000000..5b8bbdc --- /dev/null +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java @@ -0,0 +1,92 @@ +/* + * Copyright 2011 Michael Laccetti + * + * This file is part of MailJimp. + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ +package mailjimp.service; + +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.After; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Configurable; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration({ "/mailjimp-test-spring-config.xml" }) +@Configurable +public class TestMailJimpJsonServiceTemplate extends AbstractServiceTester { + @Autowired + private IMailJimpService mSvc; + + + private static String templateName = RandomStringUtils.randomAlphabetic(8); + private static String templateNewName = RandomStringUtils.randomAlphabetic(8); + private static Integer templateId = -1; + + @BeforeClass + public static void setup() { + } + + @After + public void after() { + System.out.println("\n\n\n"); + } + + + @Test + public void testTemplateAdd(){ + try { + log.debug("Test template add"); + Integer response = mSvc.templateAdd(templateName, "Test Case Template"); + templateId = response; + log.debug("Template addTemplate: {}", response); + } catch (MailJimpException mje) { + processError(mje); + } + } + + @Test + public void testTemplateUpdate(){ + try { + log.debug("Test template add"); + Boolean response = mSvc.templateUpdate(templateId, templateNewName, "Test Case Template NEW"); + log.debug("Template updateTemplate: {}", response); + Assert.assertTrue(response); + } catch (MailJimpException mje) { + processError(mje); + } + } + + + + @Test + public void testTemplateDel(){ + try { + log.debug("Test template del"); + boolean response = mSvc.templateDel(templateId); + log.debug("Template delTemplate: {}", response); + Assert.assertTrue(response); + } catch (MailJimpException mje) { + processError(mje); + } + } + + +} \ No newline at end of file diff --git a/mailjimp-core/src/test/resources/.gitignore b/mailjimp-core/src/test/resources/.gitignore new file mode 100644 index 0000000..d762c98 --- /dev/null +++ b/mailjimp-core/src/test/resources/.gitignore @@ -0,0 +1,2 @@ +/mailjimp.properties +/mailjimp-test.properties From 4190e2ded8871c58b45e08c8791ac5eac31607e6 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 10:08:24 -0400 Subject: [PATCH 07/36] gitignore for property files containing username/password stuff. --- .../test/resources/mailjimp-test.properties | 14 ----------- .../src/test/resources/mailjimp.properties | 23 ------------------- 2 files changed, 37 deletions(-) delete mode 100644 mailjimp-core/src/test/resources/mailjimp-test.properties delete mode 100644 mailjimp-core/src/test/resources/mailjimp.properties diff --git a/mailjimp-core/src/test/resources/mailjimp-test.properties b/mailjimp-core/src/test/resources/mailjimp-test.properties deleted file mode 100644 index c58cb00..0000000 --- a/mailjimp-core/src/test/resources/mailjimp-test.properties +++ /dev/null @@ -1,14 +0,0 @@ -################################################################################################################### -# # -# Set up some extra properties for the tests. You will need some extra information and setup in your # -# MailChimp account to run the integration tests. # -# # -# The properties file needs to contain the following: # -# mj.test.listId=a_list_id_you_like_to_test # -# mj.test.subscribedUserEMailAddress=an_email_address_of_an_subscribed_user_of_that_list # -# # -################################################################################################################### - -mj.test.listId= -mj.test.groupingId= -mj.test.subscribedUserEMailAddress= \ No newline at end of file diff --git a/mailjimp-core/src/test/resources/mailjimp.properties b/mailjimp-core/src/test/resources/mailjimp.properties deleted file mode 100644 index 98e08f4..0000000 --- a/mailjimp-core/src/test/resources/mailjimp.properties +++ /dev/null @@ -1,23 +0,0 @@ -################################################################################################################### -# # -# We use this to inject the username, password and API key information into the bean directly. # -# Please note that you can also inject them directly via constructor args, if you desire - check out the bean # -# definition for a sample. # -# # -# If you do not provide the username and password, you cannot perform any security-related changes, but that is # -# not a big deal. Right? # -# # -# The properties file needs to contain the following: # -# mj.username=your_username # -# mj.password=your_password # -# mj.apiKey=your_api_key # -# mj.apiVersion=version_to_use # -# mj.ssl=(true|false) # -# # -################################################################################################################### - -mj.username= -mj.password= -mj.apiKey= -mj.apiVersion=1.3 -mj.ssl=true \ No newline at end of file From 03fb32daa6f2581d8ead7d2f0a4097ebcaa53be8 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 10:08:56 -0400 Subject: [PATCH 08/36] gitignore updates --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 2a53469..838ee65 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ target/ **/*.iml **/.idea bin/ + +mailjimp-core/src/test/resources/mailjimp-test.properties + +mailjimp-core/src/test/resources/mailjimp.properties From 3163a472c7432e41a520d408de452b290d40a6de Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 10:30:28 -0400 Subject: [PATCH 09/36] added co-copyright to some files --- .../request/template/TemplateAddRequest.java | 17 +++++++++++++++++ .../request/template/TemplateDelRequest.java | 17 +++++++++++++++++ .../template/TemplateUpdateRequest.java | 18 ++++++++++++++++++ .../mailjimp/service/IMailJimpService.java | 14 ++++++++++++-- .../service/impl/MailJimpJsonService.java | 9 ++++++++- 5 files changed, 72 insertions(+), 3 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java index 44b5054..c2a9b19 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.request.template; import org.codehaus.jackson.annotate.JsonProperty; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateDelRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateDelRequest.java index 6d3ad16..6594722 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateDelRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateDelRequest.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.request.template; import org.codehaus.jackson.annotate.JsonProperty; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java index a2ae31a..bbab344 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.request.template; import java.util.HashMap; @@ -11,6 +28,7 @@ public class TemplateUpdateRequest extends MailJimpRequest { private static final long serialVersionUID = 1L; + @JsonProperty private int id = -1; @JsonProperty diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index bce0b33..d9791a5 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -285,7 +285,7 @@ public interface IMailJimpService extends Serializable { * @return boolean success * @throws MailJimpException If the template id can't be found */ - boolean templateDel(int id) throws MailJimpException; + boolean templateDel(int templateId) throws MailJimpException; /** Parameters @@ -295,7 +295,17 @@ public interface IMailJimpService extends Serializable { * @return boolean success * @throws MailJimpException If the template id can't be found or both name and html are null. */ - boolean templateUpdate(int id, String name, String html) throws MailJimpException; + boolean templateUpdate(int templateId, String name, String html) throws MailJimpException; + + /** + Parameters + * id the template id + * name the new name, null if no change + * html the new html, null if no change + * @return boolean success + * @throws MailJimpException If the template id can't be found or both name and html are null. + */ + Map templateInfo(int templateId, String type) throws MailJimpException; diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 1ac0b18..dcce7dd 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -50,8 +50,8 @@ import mailjimp.dom.request.security.ApiKeyExpireRequest; import mailjimp.dom.request.security.ApiKeyRequest; import mailjimp.dom.response.MailJimpErrorResponse; -import mailjimp.dom.response.list.ListBatchSubscribeResponse; import mailjimp.dom.response.list.InterestGrouping; +import mailjimp.dom.response.list.ListBatchSubscribeResponse; import mailjimp.dom.response.list.ListBatchUnsubscribeResponse; import mailjimp.dom.response.list.ListMemberInfoResponse; import mailjimp.dom.response.list.ListMembersResponse; @@ -308,4 +308,11 @@ public boolean templateUpdate(int id, String name, String html) throws MailJimpE log.debug("Tempate Update: {}", response); return response; } + + @Override + public Map templateInfo(int templateId, String type) throws MailJimpException { + Map response = performRequest("templateInfo", new mailjimp.dom.request.template.TemplateInfoRequest(apiKey, templateId, type), new TypeReference>() {/* empty */}); + log.debug("Tempate Update: {}", response); + return response; + } } \ No newline at end of file From 4bc0b230e3d2b6f6534be061b05d78f466de8e9a Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 10:45:03 -0400 Subject: [PATCH 10/36] added template info, not fully tested as I have no options and seconds. --- .../request/template/TemplateInfoRequest.java | 71 ++++++++++++++++ .../template/TemplateInfoResponse.java | 83 +++++++++++++++++++ .../mailjimp/service/IMailJimpService.java | 7 +- .../service/impl/MailJimpJsonService.java | 7 +- .../TestMailJimpJsonServiceTemplate.java | 17 ++++ 5 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateInfoRequest.java create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateInfoResponse.java diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateInfoRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateInfoRequest.java new file mode 100644 index 0000000..94ee31a --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateInfoRequest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ +package mailjimp.dom.request.template; + +import mailjimp.dom.request.MailJimpRequest; + +import org.codehaus.jackson.annotate.JsonProperty; + + +public class TemplateInfoRequest extends MailJimpRequest { + private static final long serialVersionUID = 1L; + + @JsonProperty + private int tid = -1; + + @JsonProperty + private String type; + + public TemplateInfoRequest(String apikey, int id, String type) { + super(apikey); + this.tid = id; + + if (type == null) + this.type = "user"; + else + this.type = type; + } + + + public int getId() { + return tid; + } + + + public void setId(int id) { + this.tid = id; + } + + + public String getType() { + return type; + } + + + public void setType(String type) { + this.type = type; + } + + + public static long getSerialversionuid() { + return serialVersionUID; + } + + + +} diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateInfoResponse.java b/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateInfoResponse.java new file mode 100644 index 0000000..3b3e2c6 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateInfoResponse.java @@ -0,0 +1,83 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ +package mailjimp.dom.response.template; + +import java.util.List; + +import org.codehaus.jackson.annotate.JsonProperty; + +import mailjimp.dom.response.MailJimpResponse; + +public class TemplateInfoResponse extends MailJimpResponse { + + @JsonProperty("default_content") + private List defaultContent; + + @JsonProperty("sections") + private List sections; + + @JsonProperty + private String source; + + @JsonProperty + private String preview; + + + public TemplateInfoResponse() { + // empty + } + + @Override + public String toString() { + return "TemplateInfoResponse [default_content=" + defaultContent +", sections=" + sections + ", source=" + source +", preview="+preview+"]"; + } + +public List getDefaultContent() { + return defaultContent; +} + +public void setDefaultContent(List defaultContent) { + this.defaultContent = defaultContent; +} + +public List getSections() { + return sections; +} + +public void setSections(List sections) { + this.sections = sections; +} + +public String getSource() { + return source; +} + +public void setSource(String source) { + this.source = source; +} + +public String getPreview() { + return preview; +} + +public void setPreview(String preview) { + this.preview = preview; +} + + +} \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index d9791a5..ebe925b 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -27,12 +27,13 @@ import mailjimp.dom.enums.InterestGroupingUpdateType; import mailjimp.dom.enums.MemberStatus; import mailjimp.dom.request.list.ListBatchSubscribeStruct; +import mailjimp.dom.response.list.InterestGrouping; import mailjimp.dom.response.list.ListBatchSubscribeResponse; import mailjimp.dom.response.list.ListBatchUnsubscribeResponse; -import mailjimp.dom.response.list.InterestGrouping; import mailjimp.dom.response.list.MailingList; import mailjimp.dom.response.list.MemberInfo; import mailjimp.dom.response.list.MemberResponseInfo; +import mailjimp.dom.response.template.TemplateInfoResponse; import mailjimp.dom.security.ApiKey; /** @@ -302,10 +303,10 @@ public interface IMailJimpService extends Serializable { * id the template id * name the new name, null if no change * html the new html, null if no change - * @return boolean success + * @return TemplateInfoResponse success * @throws MailJimpException If the template id can't be found or both name and html are null. */ - Map templateInfo(int templateId, String type) throws MailJimpException; + TemplateInfoResponse templateInfo(int templateId, String type) throws MailJimpException; diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index dcce7dd..f4491d3 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -59,6 +59,7 @@ import mailjimp.dom.response.list.MailingList; import mailjimp.dom.response.list.MemberInfo; import mailjimp.dom.response.list.MemberResponseInfo; +import mailjimp.dom.response.template.TemplateInfoResponse; import mailjimp.dom.security.ApiKey; import mailjimp.service.AbstractMailJimpService; import mailjimp.service.MailJimpException; @@ -310,9 +311,9 @@ public boolean templateUpdate(int id, String name, String html) throws MailJimpE } @Override - public Map templateInfo(int templateId, String type) throws MailJimpException { - Map response = performRequest("templateInfo", new mailjimp.dom.request.template.TemplateInfoRequest(apiKey, templateId, type), new TypeReference>() {/* empty */}); - log.debug("Tempate Update: {}", response); + public TemplateInfoResponse templateInfo(int templateId, String type) throws MailJimpException { + TemplateInfoResponse response = performRequest("templateInfo", new mailjimp.dom.request.template.TemplateInfoRequest(apiKey, templateId, type), new TypeReference() {/* empty */}); + log.debug("Tempate Info: {}", response); return response; } } \ No newline at end of file diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java index 5b8bbdc..a739c03 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java @@ -17,6 +17,8 @@ */ package mailjimp.service; +import mailjimp.dom.response.template.TemplateInfoResponse; + import org.apache.commons.lang3.RandomStringUtils; import org.junit.After; import org.junit.Assert; @@ -74,6 +76,21 @@ public void testTemplateUpdate(){ } } + @Test + public void testTemplateInfo(){ + try { + log.debug("Test template info"); + TemplateInfoResponse response = mSvc.templateInfo(templateId, null); + log.debug("Template infoTemplate: {}", response); + + Assert.assertTrue(response.getSource().equals("Test Case Template NEW")); + Assert.assertTrue(response.getPreview().equals("Test Case Template NEW")); + + } catch (MailJimpException mje) { + processError(mje); + } + } + @Test From afb718b35f57432f7760575a20156adb900aa5c9 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 11:22:45 -0400 Subject: [PATCH 11/36] added undelete --- .../mailjimp/service/IMailJimpService.java | 11 +++-- .../service/impl/MailJimpJsonService.java | 12 +++++- .../TestMailJimpJsonServiceTemplate.java | 41 +++++++++++++++---- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index ebe925b..b38d8f8 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -287,6 +287,13 @@ public interface IMailJimpService extends Serializable { * @throws MailJimpException If the template id can't be found */ boolean templateDel(int templateId) throws MailJimpException; + + /** + Parameters + * id the template id + * @return boolean success + * @throws MailJimpException If the template id can't be found */ + boolean templateUndel(int templateId) throws MailJimpException; /** Parameters @@ -306,8 +313,6 @@ public interface IMailJimpService extends Serializable { * @return TemplateInfoResponse success * @throws MailJimpException If the template id can't be found or both name and html are null. */ - TemplateInfoResponse templateInfo(int templateId, String type) throws MailJimpException; - - + TemplateInfoResponse templateInfo(int templateId, String type) throws MailJimpException; } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index f4491d3..5d163a3 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -299,7 +299,15 @@ public int templateAdd(String name, String html) throws MailJimpException { @Override public boolean templateDel(int id) throws MailJimpException { boolean response = performRequest("templateDel", new mailjimp.dom.request.template.TemplateDelRequest(apiKey, id), new TypeReference() {/* empty */}); - log.debug("Tempate Add: {}", response); + log.debug("Tempate delete: {}", response); + return response; + } + + + @Override + public boolean templateUndel(int id) throws MailJimpException { + boolean response = performRequest("templateUndel", new mailjimp.dom.request.template.TemplateDelRequest(apiKey, id), new TypeReference() {/* empty */}); + log.debug("Tempate undelete: {}", response); return response; } @@ -316,4 +324,6 @@ public TemplateInfoResponse templateInfo(int templateId, String type) throws Mai log.debug("Tempate Info: {}", response); return response; } + + } \ No newline at end of file diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java index a739c03..8f32f10 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java @@ -34,7 +34,10 @@ @ContextConfiguration({ "/mailjimp-test-spring-config.xml" }) @Configurable public class TestMailJimpJsonServiceTemplate extends AbstractServiceTester { - @Autowired + private static final String TEMPLATEHTML = "Test Case Template NEW"; + + +@Autowired private IMailJimpService mSvc; @@ -56,7 +59,7 @@ public void after() { public void testTemplateAdd(){ try { log.debug("Test template add"); - Integer response = mSvc.templateAdd(templateName, "Test Case Template"); + Integer response = mSvc.templateAdd(templateName, "Test Case Template"); // note not TEMPLATEHTML templateId = response; log.debug("Template addTemplate: {}", response); } catch (MailJimpException mje) { @@ -68,7 +71,7 @@ public void testTemplateAdd(){ public void testTemplateUpdate(){ try { log.debug("Test template add"); - Boolean response = mSvc.templateUpdate(templateId, templateNewName, "Test Case Template NEW"); + Boolean response = mSvc.templateUpdate(templateId, templateNewName, TEMPLATEHTML); log.debug("Template updateTemplate: {}", response); Assert.assertTrue(response); } catch (MailJimpException mje) { @@ -83,16 +86,15 @@ public void testTemplateInfo(){ TemplateInfoResponse response = mSvc.templateInfo(templateId, null); log.debug("Template infoTemplate: {}", response); - Assert.assertTrue(response.getSource().equals("Test Case Template NEW")); - Assert.assertTrue(response.getPreview().equals("Test Case Template NEW")); + Assert.assertTrue(response.getSource().equals(TEMPLATEHTML)); + Assert.assertTrue(response.getPreview().equals(TEMPLATEHTML)); } catch (MailJimpException mje) { processError(mje); } } - - + @Test public void testTemplateDel(){ try { @@ -105,5 +107,30 @@ public void testTemplateDel(){ } } + @Test + public void testTemplateUnDel(){ + try { + log.debug("Test template undel"); + boolean response = mSvc.templateUndel(templateId); + log.debug("Template undelTemplate: {}", response); + Assert.assertTrue(response); + } catch (MailJimpException mje) { + processError(mje); + } + } + + + + // cleanup too. + @Test + public void testTemplateFinalDelete(){ + try { + boolean response = mSvc.templateDel(templateId); + Assert.assertTrue(response); + } catch (MailJimpException mje) { + processError(mje); + } + } + } \ No newline at end of file From 9bc049d6a5eec8d286411bce1a5d2046bbfdd261 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 13:08:37 -0400 Subject: [PATCH 12/36] list template added --- .../mailjimp/dom/request/NamedBoolean.java | 30 +++++ .../request/template/TemplateListRequest.java | 100 ++++++++++++++ .../template/TemplateListItemResponse.java | 125 ++++++++++++++++++ .../template/TemplateListResponse.java | 22 +++ .../mailjimp/service/IMailJimpService.java | 7 + .../service/impl/MailJimpJsonService.java | 9 ++ .../TestMailJimpJsonServiceTemplate.java | 18 +++ 7 files changed, 311 insertions(+) create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListItemResponse.java create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListResponse.java diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java b/mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java new file mode 100644 index 0000000..49afa78 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java @@ -0,0 +1,30 @@ +package mailjimp.dom.request; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class NamedBoolean { + + @JsonProperty + private String name; + + @JsonProperty + private Boolean value; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Boolean getValue() { + return value; + } + + public void setValue(Boolean value) { + this.value = value; + } + + +} diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java new file mode 100644 index 0000000..b3f11a6 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java @@ -0,0 +1,100 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ +package mailjimp.dom.request.template; + +import java.util.List; + +import mailjimp.dom.request.MailJimpRequest; +import mailjimp.dom.request.NamedBoolean; + +import org.codehaus.jackson.annotate.JsonProperty; + + +public class TemplateListRequest extends MailJimpRequest { + + private static final long serialVersionUID = 1L; + + @JsonProperty + private int id = -1; + + @JsonProperty + private List types; + + @JsonProperty + private String category; + + @JsonProperty + private List inactives; + + + public TemplateListRequest(String apikey, int id, String category, List types, List inactives) { + super(apikey); + + this.id = id; + this.category = category; + this.types = types; + this.inactives = inactives; + + } + + + public int getId() { + return id; + } + + + public void setId(int id) { + this.id = id; + } + + + public List getTypes() { + return types; + } + + + public void setTypes(List types) { + this.types = types; + } + + + public String getCategory() { + return category; + } + + + public void setCategory(String category) { + this.category = category; + } + + + public List getInactives() { + return inactives; + } + + + public void setInactives(List inactives) { + this.inactives = inactives; + } + + + public static long getSerialversionuid() { + return serialVersionUID; + } + +} diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListItemResponse.java b/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListItemResponse.java new file mode 100644 index 0000000..6d35334 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListItemResponse.java @@ -0,0 +1,125 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ +package mailjimp.dom.response.template; + +import mailjimp.dom.response.MailJimpResponse; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class TemplateListItemResponse extends MailJimpResponse { + + + @JsonProperty("id") + private int id; + + @JsonProperty("name") + private String name; + + @JsonProperty("category") + private String category; + + @JsonProperty("layout") + private String layout; + + @JsonProperty("preview_image") + private String previewImage; + + @JsonProperty("date_created") + private String dateCreated; + + @JsonProperty("edit_source") + private Boolean editSource; + + @JsonProperty("active") + private String active; + + + public TemplateListItemResponse() { + // empty + } + + @Override + public String toString() { + return "TemplateListItemResponse [id=" + id + ", name=" + name + ", layout=" + layout +", preview_image=" + previewImage + + ", date_created="+ dateCreated + ",edit_source=" + editSource + "]"; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLayout() { + return layout; + } + + public void setLayout(String layout) { + this.layout = layout; + } + + public String getPreviewImage() { + return previewImage; + } + + public void setPreviewImage(String previewImage) { + this.previewImage = previewImage; + } + + public String getDateCreated() { + return dateCreated; + } + + public void setDateCreated(String dateCreated) { + this.dateCreated = dateCreated; + } + + public Boolean getEditSource() { + return editSource; + } + + public void setEditSource(Boolean editSource) { + this.editSource = editSource; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getActive() { + return active; + } + + public void setActive(String active) { + this.active = active; + } +} \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListResponse.java b/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListResponse.java new file mode 100644 index 0000000..505c268 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListResponse.java @@ -0,0 +1,22 @@ +package mailjimp.dom.response.template; + +import java.util.List; + +import mailjimp.dom.response.MailJimpResponse; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class TemplateListResponse extends MailJimpResponse { + + @JsonProperty("user") + List listItems; + + public List getListItems() { + return listItems; + } + + public void setListItems(List listItems) { + this.listItems = listItems; + } + +} diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index b38d8f8..74a874b 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -26,6 +26,7 @@ import mailjimp.dom.enums.InterestGroupingType; import mailjimp.dom.enums.InterestGroupingUpdateType; import mailjimp.dom.enums.MemberStatus; +import mailjimp.dom.request.NamedBoolean; import mailjimp.dom.request.list.ListBatchSubscribeStruct; import mailjimp.dom.response.list.InterestGrouping; import mailjimp.dom.response.list.ListBatchSubscribeResponse; @@ -34,6 +35,7 @@ import mailjimp.dom.response.list.MemberInfo; import mailjimp.dom.response.list.MemberResponseInfo; import mailjimp.dom.response.template.TemplateInfoResponse; +import mailjimp.dom.response.template.TemplateListResponse; import mailjimp.dom.security.ApiKey; /** @@ -314,5 +316,10 @@ public interface IMailJimpService extends Serializable { * @throws MailJimpException If the template id can't be found or both name and html are null. */ TemplateInfoResponse templateInfo(int templateId, String type) throws MailJimpException; + + +TemplateListResponse templateList(int templateId, String category, + List types, List inactives) + throws MailJimpException; } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 5d163a3..c058f65 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -30,6 +30,7 @@ import mailjimp.dom.enums.InterestGroupingType; import mailjimp.dom.enums.InterestGroupingUpdateType; import mailjimp.dom.enums.MemberStatus; +import mailjimp.dom.request.NamedBoolean; import mailjimp.dom.request.list.ListBatchSubscribeRequest; import mailjimp.dom.request.list.ListBatchSubscribeStruct; import mailjimp.dom.request.list.ListBatchUnsubscribeRequest; @@ -60,6 +61,7 @@ import mailjimp.dom.response.list.MemberInfo; import mailjimp.dom.response.list.MemberResponseInfo; import mailjimp.dom.response.template.TemplateInfoResponse; +import mailjimp.dom.response.template.TemplateListResponse; import mailjimp.dom.security.ApiKey; import mailjimp.service.AbstractMailJimpService; import mailjimp.service.MailJimpException; @@ -325,5 +327,12 @@ public TemplateInfoResponse templateInfo(int templateId, String type) throws Mai return response; } + @Override + public TemplateListResponse templateList(int templateId, String category, List types, List inactives) throws MailJimpException { + TemplateListResponse response = performRequest("templates", new mailjimp.dom.request.template.TemplateListRequest(apiKey, templateId, category, types, inactives), new TypeReference() {/* empty */}); + log.debug("Tempate List: {}", response); + return response; + } + } \ No newline at end of file diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java index 8f32f10..9a752f6 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java @@ -18,6 +18,7 @@ package mailjimp.service; import mailjimp.dom.response.template.TemplateInfoResponse; +import mailjimp.dom.response.template.TemplateListResponse; import org.apache.commons.lang3.RandomStringUtils; import org.junit.After; @@ -67,6 +68,23 @@ public void testTemplateAdd(){ } } + @Test + public void testTemplateList(){ + try { + log.debug("Test template list"); + TemplateListResponse response = mSvc.templateList(templateId, null, null, null); + + Assert.assertNotNull(response); + Assert.assertNotNull(response.getListItems()); + + log.debug("Template addTemplate: {}", response); + } catch (MailJimpException mje) { + processError(mje); + } + } + + + @Test public void testTemplateUpdate(){ try { From b3069c287f1031060c542c3d57a39ab08874b312 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 13:36:17 -0400 Subject: [PATCH 13/36] partial implementation of listTemplates. --- .../mailjimp/dom/request/NamedBoolean.java | 6 ++++++ .../request/template/TemplateListRequest.java | 18 ++---------------- .../mailjimp/service/IMailJimpService.java | 5 ++--- .../service/impl/MailJimpJsonService.java | 4 ++-- .../TestMailJimpJsonServiceTemplate.java | 8 +++++--- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java b/mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java index 49afa78..3130ad3 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java @@ -10,6 +10,12 @@ public class NamedBoolean { @JsonProperty private Boolean value; + public NamedBoolean(String name, Boolean value) + { + this.name = name; + this.value = value; + } + public String getName() { return name; } diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java index b3f11a6..43ef184 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java @@ -28,9 +28,6 @@ public class TemplateListRequest extends MailJimpRequest { private static final long serialVersionUID = 1L; - - @JsonProperty - private int id = -1; @JsonProperty private List types; @@ -42,10 +39,9 @@ public class TemplateListRequest extends MailJimpRequest { private List inactives; - public TemplateListRequest(String apikey, int id, String category, List types, List inactives) { + public TemplateListRequest(String apikey, String category, List types, List inactives) { super(apikey); - - this.id = id; + this.category = category; this.types = types; this.inactives = inactives; @@ -53,16 +49,6 @@ public TemplateListRequest(String apikey, int id, String category, List getTypes() { return types; } diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index 74a874b..66f4403 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -318,8 +318,7 @@ public interface IMailJimpService extends Serializable { TemplateInfoResponse templateInfo(int templateId, String type) throws MailJimpException; -TemplateListResponse templateList(int templateId, String category, - List types, List inactives) - throws MailJimpException; + TemplateListResponse templateList() throws MailJimpException; +//TemplateListResponse templateList(String category,List types, List inactives) throws MailJimpException; } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index c058f65..9ea975d 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -328,8 +328,8 @@ public TemplateInfoResponse templateInfo(int templateId, String type) throws Mai } @Override - public TemplateListResponse templateList(int templateId, String category, List types, List inactives) throws MailJimpException { - TemplateListResponse response = performRequest("templates", new mailjimp.dom.request.template.TemplateListRequest(apiKey, templateId, category, types, inactives), new TypeReference() {/* empty */}); + public TemplateListResponse templateList() throws MailJimpException { //int templateId, String category, List types, List inactives) throws MailJimpException { + TemplateListResponse response = performRequest("templates", new mailjimp.dom.request.template.TemplateListRequest(apiKey, null, null, null), new TypeReference() {/* empty */}); log.debug("Tempate List: {}", response); return response; } diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java index 9a752f6..54be5f2 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java @@ -17,6 +17,10 @@ */ package mailjimp.service; +import java.util.Arrays; +import java.util.List; + +import mailjimp.dom.request.NamedBoolean; import mailjimp.dom.response.template.TemplateInfoResponse; import mailjimp.dom.response.template.TemplateListResponse; @@ -72,11 +76,9 @@ public void testTemplateAdd(){ public void testTemplateList(){ try { log.debug("Test template list"); - TemplateListResponse response = mSvc.templateList(templateId, null, null, null); - + TemplateListResponse response = mSvc.templateList(); Assert.assertNotNull(response); Assert.assertNotNull(response.getListItems()); - log.debug("Template addTemplate: {}", response); } catch (MailJimpException mje) { processError(mje); From c6e1832edeccbaddedc360be63cbe10a81da348d Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 14:41:15 -0400 Subject: [PATCH 14/36] added create campaign --- .../campaign/CampaignCreateRequest.java | 94 +++++++++++++++++++ .../mailjimp/service/IMailJimpService.java | 5 + .../service/impl/MailJimpJsonService.java | 8 +- .../TestMailJimpJsonServiceCampaign.java | 80 ++++++++++++++++ 4 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java create mode 100644 mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java new file mode 100644 index 0000000..ee1c22c --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java @@ -0,0 +1,94 @@ +package mailjimp.dom.request.campaign; + +import java.util.HashMap; + +import mailjimp.dom.request.MailJimpRequest; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class CampaignCreateRequest extends MailJimpRequest { + + + @JsonProperty + private String type; + + @JsonProperty + HashMap options; + + @JsonProperty + HashMap content; + + + public CampaignCreateRequest(String apikey, String type, HashMap options,HashMap content) { + super(apikey); + + this.type = type; + this.options = options; + this.content = content; + } + + static public HashMap buildOptions(String listId, String subject, String fromEmail, String fromName, String toName, int templateId) + { + HashMap options = new HashMap(); + + options.put("list_id", listId); + options.put("subject", subject); + options.put("from_email",fromEmail); + options.put("from_name",fromName); + options.put("to_name",toName); + options.put("template_id", templateId); + + return options; + } + + static public HashMap buildContentFromString(String html, String text) + { + HashMap content = new HashMap(); + content.put("html", html); + content.put("text", text); + return content; + + } + + static public HashMap buildContentFromUrl(String url) + { + HashMap content = new HashMap(); + content.put("url", url); + return content; + } + + static public HashMap buildContentFromArchive(String archiveBase64, String archiveType) + { + HashMap content = new HashMap(); + content.put("archive", archiveBase64); + content.put("archive_type", archiveType); + return content; + } + + + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public HashMap getOptions() { + return options; + } + + public void setOptions(HashMap options) { + this.options = options; + } + + public HashMap getContent() { + return content; + } + + public void setContent(HashMap content) { + this.content = content; + } +} \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index 66f4403..5b71ee3 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -19,6 +19,7 @@ import java.io.Serializable; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -320,5 +321,9 @@ public interface IMailJimpService extends Serializable { TemplateListResponse templateList() throws MailJimpException; //TemplateListResponse templateList(String category,List types, List inactives) throws MailJimpException; + + + + String campaignCreate(String type, HashMap options, HashMap content) throws MailJimpException; } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 9ea975d..47d94b8 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -30,7 +31,6 @@ import mailjimp.dom.enums.InterestGroupingType; import mailjimp.dom.enums.InterestGroupingUpdateType; import mailjimp.dom.enums.MemberStatus; -import mailjimp.dom.request.NamedBoolean; import mailjimp.dom.request.list.ListBatchSubscribeRequest; import mailjimp.dom.request.list.ListBatchSubscribeStruct; import mailjimp.dom.request.list.ListBatchUnsubscribeRequest; @@ -334,5 +334,11 @@ public TemplateListResponse templateList() throws MailJimpException { //int temp return response; } + @Override + public String campaignCreate(String type, HashMap options, HashMap content) throws MailJimpException { //int templateId, String category, List types, List inactives) throws MailJimpException { + String response = performRequest("campaignCreate", new mailjimp.dom.request.campaign.CampaignCreateRequest(apiKey, type, options, content), new TypeReference() {/* empty */}); + log.debug("Tempate List: {}", response); + return response; + } } \ No newline at end of file diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java new file mode 100644 index 0000000..91e3e45 --- /dev/null +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java @@ -0,0 +1,80 @@ +/* + * Copyright 2011 Michael Laccetti + * + * This file is part of MailJimp. + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ +package mailjimp.service; + +import mailjimp.dom.MailJimpConstants; +import mailjimp.dom.request.campaign.CampaignCreateRequest; + +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.After; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Configurable; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration({ "/mailjimp-test-spring-config.xml" }) +@Configurable +public class TestMailJimpJsonServiceCampaign extends AbstractServiceTester { + + +@Autowired + private IMailJimpService mSvc; + + @Value("${mj.test.listId}") + private String listId; + + @Value("${mj.test.templateId}") + private Integer templateId; + + private static final String TEMPLATEHTML = "Test Case Template NEW"; + private static final String TEMPLATETEXT = "Test Case Template NEW"; + + + @BeforeClass + public static void setup() { + } + + @After + public void after() { + System.out.println("\n\n\n"); + } + + + @Test + public void testCreateCampaign() + { + try { + log.debug("Test campaign create"); + String response = mSvc.campaignCreate(MailJimpConstants.CAMPAIGNTYPE_REGULAR, + CampaignCreateRequest.buildOptions(listId, "Test Subject", "tim.gilbert@morningstar.com", "TestCase User", "Dear Customer", templateId ), + CampaignCreateRequest.buildContentFromString(TEMPLATEHTML, TEMPLATETEXT)); + log.debug("Template updateTemplate: {}", response); + Assert.assertTrue(response != null); + } catch (MailJimpException mje) { + processError(mje); + } + } + + +} \ No newline at end of file From 522e78d1acedf0959fc369a07c4f7780baff192b Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 14:53:23 -0400 Subject: [PATCH 15/36] fixed campaign, added javadoc help. --- .../campaign/CampaignCreateRequest.java | 4 ++-- .../mailjimp/service/IMailJimpService.java | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java index ee1c22c..6193957 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java @@ -27,12 +27,12 @@ public CampaignCreateRequest(String apikey, String type, HashMap this.content = content; } - static public HashMap buildOptions(String listId, String subject, String fromEmail, String fromName, String toName, int templateId) + static public HashMap buildOptions(String listId, String campaignName, String fromEmail, String fromName, String toName, int templateId) { HashMap options = new HashMap(); options.put("list_id", listId); - options.put("subject", subject); + options.put("subject", campaignName); options.put("from_email",fromEmail); options.put("from_name",fromName); options.put("to_name",toName); diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index 5b71ee3..950fb6f 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -318,12 +318,25 @@ public interface IMailJimpService extends Serializable { */ TemplateInfoResponse templateInfo(int templateId, String type) throws MailJimpException; - + /** + Parameters + * @return TemplateListResponse on success with all user templates. + * @throws MailJimpException + */ TemplateListResponse templateList() throws MailJimpException; -//TemplateListResponse templateList(String category,List types, List inactives) throws MailJimpException; - + // there are a lot of template options which I have chosen not to implement since i don't use them, this is how the signature + // might have looked like otherwise. + //TemplateListResponse templateList(String category,List types, List inactives) throws MailJimpException; + /** + Parameters + * type Use MailJimpConstants.CAMPAIGNTYPE to specify the style of campaign + * options Use CampaignCreateRequest.buildOptions to build your options + * content Use CampaignCreateRequest.buildContent to build your content either by string, url, base64 encoded binary. + * @return String with campaign id + * @throws MailJimpException + */ String campaignCreate(String type, HashMap options, HashMap content) throws MailJimpException; } \ No newline at end of file From c386cbe52798aecdc46b91ab65594beba7453dbf Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 15:07:49 -0400 Subject: [PATCH 16/36] delete campaigns added. --- .../campaign/CampaignDeleteRequest.java | 27 +++++++++++++++++++ .../mailjimp/service/IMailJimpService.java | 8 ++++++ .../service/impl/MailJimpJsonService.java | 9 ++++++- .../TestMailJimpJsonServiceCampaign.java | 15 +++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignDeleteRequest.java diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignDeleteRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignDeleteRequest.java new file mode 100644 index 0000000..01f69ec --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignDeleteRequest.java @@ -0,0 +1,27 @@ +package mailjimp.dom.request.campaign; + +import mailjimp.dom.request.MailJimpRequest; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class CampaignDeleteRequest extends MailJimpRequest { + + + @JsonProperty("cid") + private String campaignId; + + public CampaignDeleteRequest(String apikey, String campaignId) { + super(apikey); + this.campaignId = campaignId; + + } + + public String getCampaignId() { + return campaignId; + } + + public void setCampaignId(String campaignId) { + this.campaignId = campaignId; + } + +} \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index 950fb6f..11df386 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -338,5 +338,13 @@ public interface IMailJimpService extends Serializable { * @throws MailJimpException */ String campaignCreate(String type, HashMap options, HashMap content) throws MailJimpException; + + /** + Parameters + * campaignId The Campaign Id + * @return boolean success + * @throws MailJimpException + */ + Boolean campaignDelete(String campaignId) throws MailJimpException; } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 47d94b8..53f0039 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -337,7 +337,14 @@ public TemplateListResponse templateList() throws MailJimpException { //int temp @Override public String campaignCreate(String type, HashMap options, HashMap content) throws MailJimpException { //int templateId, String category, List types, List inactives) throws MailJimpException { String response = performRequest("campaignCreate", new mailjimp.dom.request.campaign.CampaignCreateRequest(apiKey, type, options, content), new TypeReference() {/* empty */}); - log.debug("Tempate List: {}", response); + log.debug("capaign Create: {}", response); + return response; + } + + @Override + public Boolean campaignDelete(String campaignId) throws MailJimpException { + Boolean response = performRequest("campaignDelete", new mailjimp.dom.request.campaign.CampaignDeleteRequest(apiKey, campaignId), new TypeReference() {/* empty */}); + log.debug("campaign Delete: {}", response); return response; } diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java index 91e3e45..bea4986 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java @@ -50,6 +50,7 @@ public class TestMailJimpJsonServiceCampaign extends AbstractServiceTester { private static final String TEMPLATEHTML = "Test Case Template NEW"; private static final String TEMPLATETEXT = "Test Case Template NEW"; + private static String campaignId; @BeforeClass public static void setup() { @@ -69,6 +70,7 @@ public void testCreateCampaign() String response = mSvc.campaignCreate(MailJimpConstants.CAMPAIGNTYPE_REGULAR, CampaignCreateRequest.buildOptions(listId, "Test Subject", "tim.gilbert@morningstar.com", "TestCase User", "Dear Customer", templateId ), CampaignCreateRequest.buildContentFromString(TEMPLATEHTML, TEMPLATETEXT)); + campaignId = response; log.debug("Template updateTemplate: {}", response); Assert.assertTrue(response != null); } catch (MailJimpException mje) { @@ -76,5 +78,18 @@ public void testCreateCampaign() } } + @Test + public void testDeleteCampaign() + { + try { + log.debug("Test campaign delete :" + campaignId); + Boolean response = mSvc.campaignDelete(campaignId); + + log.debug("Template updateTemplate: {}", response); + Assert.assertTrue(response); + } catch (MailJimpException mje) { + processError(mje); + } + } } \ No newline at end of file From 1e6f32ca22bc682eb3919fd17e8ceb8ec8ee2770 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 15:48:43 -0400 Subject: [PATCH 17/36] renamed created campaign to make it obvious its from a test case. --- .../java/mailjimp/service/TestMailJimpJsonServiceCampaign.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java index bea4986..e4af9ac 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java @@ -68,7 +68,7 @@ public void testCreateCampaign() try { log.debug("Test campaign create"); String response = mSvc.campaignCreate(MailJimpConstants.CAMPAIGNTYPE_REGULAR, - CampaignCreateRequest.buildOptions(listId, "Test Subject", "tim.gilbert@morningstar.com", "TestCase User", "Dear Customer", templateId ), + CampaignCreateRequest.buildOptions(listId, "Test Campaign created by Test case", "tim.gilbert@morningstar.com", "TestCase User", "Dear Customer", templateId ), CampaignCreateRequest.buildContentFromString(TEMPLATEHTML, TEMPLATETEXT)); campaignId = response; log.debug("Template updateTemplate: {}", response); From 5bb42e5f23b45bc5e389b3c9531d1bc392a5a89b Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 19 Apr 2012 15:51:54 -0400 Subject: [PATCH 18/36] added gpl stuff to header of files. --- .../mailjimp/dom/request/NamedBoolean.java | 18 ++++++++++++++++++ .../campaign/CampaignCreateRequest.java | 17 +++++++++++++++++ .../campaign/CampaignDeleteRequest.java | 17 +++++++++++++++++ .../TestMailJimpJsonServiceCampaign.java | 4 ++-- .../TestMailJimpJsonServiceTemplate.java | 4 ++-- 5 files changed, 56 insertions(+), 4 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java b/mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java index 3130ad3..bdd1a61 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/NamedBoolean.java @@ -1,3 +1,21 @@ +/* + * Copyright 2011 Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ + package mailjimp.dom.request; import org.codehaus.jackson.annotate.JsonProperty; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java index 6193957..9ef31d9 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.request.campaign; import java.util.HashMap; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignDeleteRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignDeleteRequest.java index 01f69ec..bfb6668 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignDeleteRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignDeleteRequest.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.request.campaign; import mailjimp.dom.request.MailJimpRequest; diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java index e4af9ac..52588b2 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java @@ -1,7 +1,7 @@ /* - * Copyright 2011 Michael Laccetti + * Copyright 2011 Michael Laccetti and Tim Gilbert * - * This file is part of MailJimp. + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp * * MailJimp is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java index 54be5f2..910f96e 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceTemplate.java @@ -1,7 +1,7 @@ /* - * Copyright 2011 Michael Laccetti + * Copyright 2011 Michael Laccetti and Tim Gilbert * - * This file is part of MailJimp. + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp * * MailJimp is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by From 5b7c15f00b96347ceac64c553f3f86531f900620 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Wed, 25 Apr 2012 11:55:01 -0400 Subject: [PATCH 19/36] fixed campaign create bug with subject and title not used properly. removed unused templateId from createCampaign API --- .../dom/request/campaign/CampaignCreateRequest.java | 7 +++---- .../mailjimp/service/TestMailJimpJsonServiceCampaign.java | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java index 9ef31d9..90db512 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java @@ -44,17 +44,16 @@ public CampaignCreateRequest(String apikey, String type, HashMap this.content = content; } - static public HashMap buildOptions(String listId, String campaignName, String fromEmail, String fromName, String toName, int templateId) + static public HashMap buildOptions(String listId, String campaignName, String subject, String fromEmail, String fromName, String toName) { HashMap options = new HashMap(); options.put("list_id", listId); - options.put("subject", campaignName); + options.put("title", campaignName); + options.put("subject", subject); options.put("from_email",fromEmail); options.put("from_name",fromName); options.put("to_name",toName); - options.put("template_id", templateId); - return options; } diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java index 52588b2..282a82c 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java @@ -68,7 +68,7 @@ public void testCreateCampaign() try { log.debug("Test campaign create"); String response = mSvc.campaignCreate(MailJimpConstants.CAMPAIGNTYPE_REGULAR, - CampaignCreateRequest.buildOptions(listId, "Test Campaign created by Test case", "tim.gilbert@morningstar.com", "TestCase User", "Dear Customer", templateId ), + CampaignCreateRequest.buildOptions(listId, "Test Campaign created by Test case", "Test Subject", "tim.gilbert@morningstar.com", "TestCase User", "Dear Customer"), CampaignCreateRequest.buildContentFromString(TEMPLATEHTML, TEMPLATETEXT)); campaignId = response; log.debug("Template updateTemplate: {}", response); From 1ed29deab2c2d9da6b891159b74e3803ba229770 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Wed, 25 Apr 2012 16:50:46 -0400 Subject: [PATCH 20/36] staring to add campaign list. --- .../campaign/CampaignCreateRequest.java | 1 - .../request/campaign/CampaignListRequest.java | 134 ++++++++ .../campaign/CampaignListResponse.java | 34 ++ .../campaign/CampaignListResponseItem.java | 296 ++++++++++++++++++ .../mailjimp/service/IMailJimpService.java | 4 + .../service/impl/MailJimpJsonService.java | 11 +- .../TestMailJimpJsonServiceCampaign.java | 25 +- 7 files changed, 500 insertions(+), 5 deletions(-) create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignListRequest.java create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java index 90db512..f7ffe43 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java @@ -25,7 +25,6 @@ public class CampaignCreateRequest extends MailJimpRequest { - @JsonProperty private String type; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignListRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignListRequest.java new file mode 100644 index 0000000..8bf6dd7 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignListRequest.java @@ -0,0 +1,134 @@ + /* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ + package mailjimp.dom.request.campaign; + + import java.util.Date; + import java.util.HashMap; + import java.util.Locale; + import java.util.TimeZone; + + import mailjimp.dom.request.MailJimpRequest; + + import org.codehaus.jackson.annotate.JsonProperty; + import org.springframework.format.datetime.DateFormatter; + + public class CampaignListRequest extends MailJimpRequest { + + @JsonProperty + private int start; + + @JsonProperty + private int limit; + + @JsonProperty + HashMap filters; + + static DateFormatter df = null; + + + public CampaignListRequest(String apikey, HashMap filters, int start, int limit) { + super(apikey); + this.filters = filters; + this.start = start; + this.limit = limit; + + if (df == null) + { + df = new DateFormatter("yyyy-MM-dd HH:mm:ss"); + df.setTimeZone(TimeZone.getTimeZone("GMT")); + } + } + + static public HashMap buildFilters(String campaignId, String listId, Integer folderId, Integer templateId, String status, + String type, String fromName, String fromEmail, String title, String subject, Date sendTimeStart, Date sendTimeEnd, Boolean exact) + { + HashMap options = new HashMap(); + + if (campaignId != null) + options.put("campaign_id", campaignId); + + if (listId != null) + options.put("list_id", listId); + + if (folderId != 0) + options.put("folderId", (int) folderId); + + if (templateId != null) + options.put("template_id", templateId); + + + if (status != null) + options.put("status", status); + + if (type != null) + options.put("type", type); + + if (fromName != null) + options.put("from_name", fromName); + + if (fromEmail!= null) + options.put("from_email", fromEmail); + + if (title != null) + options.put("title", title); + + if (subject != null) + options.put("subject", subject); + + if (sendTimeStart != null) + options.put("sendtime_start", df.print(sendTimeStart, Locale.US)); + + if (sendTimeEnd != null) + options.put("sendtime_end", df.print(sendTimeStart, Locale.US)); + + if (exact != null) + options.put("exact", (boolean) exact); + + return options; + } + + + + + + + + public int getStart() { + return start; + } + + public void setStart(int start) { + this.start = start; + } + + public int getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } + + public HashMap getFilters() { + return filters; + } + + public void setFilters(HashMap filters) { + this.filters = filters; + } + } diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java new file mode 100644 index 0000000..77c7e90 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java @@ -0,0 +1,34 @@ +package mailjimp.dom.response.campaign; + +import java.io.Serializable; +import java.util.List; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class CampaignListResponse implements Serializable{ + + @JsonProperty + int total; + + @JsonProperty("data") + List items; + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + + +} diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java new file mode 100644 index 0000000..0af0271 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java @@ -0,0 +1,296 @@ +package mailjimp.dom.response.campaign; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class CampaignListResponseItem implements Serializable{ + + @JsonProperty + String id; + + @JsonProperty("web_id") + Integer webId; + + @JsonProperty("list_id") + String listId; + + @JsonProperty("folder_id") + Integer folderId; + + @JsonProperty + int template_id; + + @JsonProperty + String content_type; + @JsonProperty + String title; + @JsonProperty + String type; + @JsonProperty + String create_time; + @JsonProperty + String send_time ; + @JsonProperty + int emails_sent ; + @JsonProperty + String status ; + @JsonProperty + String from_name; + @JsonProperty + String from_email; + @JsonProperty + String subject ; + @JsonProperty + String to_name ; + @JsonProperty + String archive_url; + @JsonProperty + boolean inline_css ; + @JsonProperty + String analytics ; + @JsonProperty + String analytics_tag; + @JsonProperty + boolean authenticate; + @JsonProperty + boolean ecomm360 ; + @JsonProperty + boolean auto_tweet ; + @JsonProperty + String auto_fb_post; + @JsonProperty + boolean auto_footer ; + @JsonProperty + boolean timewarp ; + @JsonProperty + String timewarp_schedule; + @JsonProperty + HashMap tracking; + @JsonProperty + boolean html_clicks ; + @JsonProperty + boolean text_clicks ; + @JsonProperty + boolean opens ; + @JsonProperty + String segment_text; + @JsonProperty + List segment_opts; + @JsonProperty + List type_opts; + + + + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public Integer getWebId() { + return webId; + } + public void setWebId(Integer webId) { + this.webId = webId; + } + public String getListId() { + return listId; + } + public void setListId(String listId) { + this.listId = listId; + } + public Integer getFolderId() { + return folderId; + } + public void setFolderId(Integer folderId) { + this.folderId = folderId; + } + public int getTemplate_id() { + return template_id; + } + public void setTemplate_id(int template_id) { + this.template_id = template_id; + } + public String getContent_type() { + return content_type; + } + public void setContent_type(String content_type) { + this.content_type = content_type; + } + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getCreate_time() { + return create_time; + } + public void setCreate_time(String create_time) { + this.create_time = create_time; + } + public String getSend_time() { + return send_time; + } + public void setSend_time(String send_time) { + this.send_time = send_time; + } + public int getEmails_sent() { + return emails_sent; + } + public void setEmails_sent(int emails_sent) { + this.emails_sent = emails_sent; + } + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + public String getFrom_name() { + return from_name; + } + public void setFrom_name(String from_name) { + this.from_name = from_name; + } + public String getFrom_email() { + return from_email; + } + public void setFrom_email(String from_email) { + this.from_email = from_email; + } + public String getSubject() { + return subject; + } + public void setSubject(String subject) { + this.subject = subject; + } + public String getTo_name() { + return to_name; + } + public void setTo_name(String to_name) { + this.to_name = to_name; + } + public String getArchive_url() { + return archive_url; + } + public void setArchive_url(String archive_url) { + this.archive_url = archive_url; + } + public boolean isInline_css() { + return inline_css; + } + public void setInline_css(boolean inline_css) { + this.inline_css = inline_css; + } + public String getAnalytics() { + return analytics; + } + public void setAnalytics(String analytics) { + this.analytics = analytics; + } + public String getAnalytics_tag() { + return analytics_tag; + } + public void setAnalytics_tag(String analytics_tag) { + this.analytics_tag = analytics_tag; + } + public boolean isAuthenticate() { + return authenticate; + } + public void setAuthenticate(boolean authenticate) { + this.authenticate = authenticate; + } + public boolean isEcomm360() { + return ecomm360; + } + public void setEcomm360(boolean ecomm360) { + this.ecomm360 = ecomm360; + } + public boolean isAuto_tweet() { + return auto_tweet; + } + public void setAuto_tweet(boolean auto_tweet) { + this.auto_tweet = auto_tweet; + } + public String getAuto_fb_post() { + return auto_fb_post; + } + public void setAuto_fb_post(String auto_fb_post) { + this.auto_fb_post = auto_fb_post; + } + public boolean isAuto_footer() { + return auto_footer; + } + public void setAuto_footer(boolean auto_footer) { + this.auto_footer = auto_footer; + } + public boolean isTimewarp() { + return timewarp; + } + public void setTimewarp(boolean timewarp) { + this.timewarp = timewarp; + } + public String getTimewarp_schedule() { + return timewarp_schedule; + } + public void setTimewarp_schedule(String timewarp_schedule) { + this.timewarp_schedule = timewarp_schedule; + } + public HashMap getTracking() { + return tracking; + } + public void setTracking(HashMap tracking) { + this.tracking = tracking; + } + public boolean isHtml_clicks() { + return html_clicks; + } + public void setHtml_clicks(boolean html_clicks) { + this.html_clicks = html_clicks; + } + public boolean isText_clicks() { + return text_clicks; + } + public void setText_clicks(boolean text_clicks) { + this.text_clicks = text_clicks; + } + public boolean isOpens() { + return opens; + } + public void setOpens(boolean opens) { + this.opens = opens; + } + public String getSegment_text() { + return segment_text; + } + public void setSegment_text(String segment_text) { + this.segment_text = segment_text; + } + public List getSegment_opts() { + return segment_opts; + } + public void setSegment_opts(List segment_opts) { + this.segment_opts = segment_opts; + } + public List getType_opts() { + return type_opts; + } + public void setType_opts(List type_opts) { + this.type_opts = type_opts; + } + + + + + } diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index 11df386..3fbcfa5 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -29,6 +29,7 @@ import mailjimp.dom.enums.MemberStatus; import mailjimp.dom.request.NamedBoolean; import mailjimp.dom.request.list.ListBatchSubscribeStruct; +import mailjimp.dom.response.campaign.CampaignListResponse; import mailjimp.dom.response.list.InterestGrouping; import mailjimp.dom.response.list.ListBatchSubscribeResponse; import mailjimp.dom.response.list.ListBatchUnsubscribeResponse; @@ -346,5 +347,8 @@ public interface IMailJimpService extends Serializable { * @throws MailJimpException */ Boolean campaignDelete(String campaignId) throws MailJimpException; + + + CampaignListResponse campaignList(HashMap filters, int start, int limit) throws MailJimpException; } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 53f0039..32a6ca1 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -51,6 +51,7 @@ import mailjimp.dom.request.security.ApiKeyExpireRequest; import mailjimp.dom.request.security.ApiKeyRequest; import mailjimp.dom.response.MailJimpErrorResponse; +import mailjimp.dom.response.campaign.CampaignListResponse; import mailjimp.dom.response.list.InterestGrouping; import mailjimp.dom.response.list.ListBatchSubscribeResponse; import mailjimp.dom.response.list.ListBatchUnsubscribeResponse; @@ -347,5 +348,13 @@ public Boolean campaignDelete(String campaignId) throws MailJimpException { log.debug("campaign Delete: {}", response); return response; } - + + + @Override + public CampaignListResponse campaignList(HashMap filters, int start, int limit) throws MailJimpException { + CampaignListResponse response = performRequest("campaigns", new mailjimp.dom.request.campaign.CampaignListRequest(apiKey, filters, start, limit), new TypeReference() {/* empty */}); + log.debug("campaign List: {}", response); + + return response; + } } \ No newline at end of file diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java index 282a82c..e06351f 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java @@ -17,10 +17,12 @@ */ package mailjimp.service; +import java.util.List; + import mailjimp.dom.MailJimpConstants; import mailjimp.dom.request.campaign.CampaignCreateRequest; +import mailjimp.dom.response.campaign.CampaignListResponse; -import org.apache.commons.lang3.RandomStringUtils; import org.junit.After; import org.junit.Assert; import org.junit.BeforeClass; @@ -62,7 +64,7 @@ public void after() { } - @Test + //@Test public void testCreateCampaign() { try { @@ -78,7 +80,24 @@ public void testCreateCampaign() } } - @Test + @Test + public void testListCampaign() + { + try { + log.debug("Test campaign list"); + + CampaignListResponse response = mSvc.campaignList(null, 0, 10); + + + log.debug("Template list campaigns: {}", response); + Assert.assertTrue(response != null); + } catch (MailJimpException mje) { + processError(mje); + } + } + + + //@Test public void testDeleteCampaign() { try { From 3d6e4d6925cd5f2a10ef354decc610968c2690b5 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 26 Apr 2012 09:00:00 -0400 Subject: [PATCH 21/36] more work improving campaignlist --- .../campaign/CampaignListResponse.java | 7 +- .../campaign/CampaignListResponseItem.java | 69 ++++++++++++++----- .../TestMailJimpJsonServiceCampaign.java | 21 ++++-- 3 files changed, 71 insertions(+), 26 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java index 77c7e90..fd07416 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java @@ -28,7 +28,10 @@ public List getItems() { public void setItems(List items) { this.items = items; } - - + @Override + public String toString() + { + return "CampaignListResponse: [total=" + total+"];"; + } } diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java index 0af0271..c36929f 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java @@ -25,64 +25,97 @@ public class CampaignListResponseItem implements Serializable{ @JsonProperty String content_type; + @JsonProperty String title; + @JsonProperty String type; + @JsonProperty String create_time; + @JsonProperty - String send_time ; + String send_time; + @JsonProperty - int emails_sent ; + int emails_sent; + @JsonProperty - String status ; + String status; + @JsonProperty - String from_name; + String from_name; + @JsonProperty - String from_email; + String from_email; + @JsonProperty - String subject ; + String subject; + @JsonProperty - String to_name ; + String to_name; + @JsonProperty String archive_url; + @JsonProperty - boolean inline_css ; + boolean inline_css; + @JsonProperty - String analytics ; + String analytics; + @JsonProperty String analytics_tag; + @JsonProperty boolean authenticate; + @JsonProperty - boolean ecomm360 ; + boolean ecomm360; + @JsonProperty - boolean auto_tweet ; + boolean auto_tweet; + @JsonProperty - String auto_fb_post; + String auto_fb_post; + @JsonProperty - boolean auto_footer ; + boolean auto_footer; + @JsonProperty - boolean timewarp ; + boolean timewarp; + @JsonProperty - String timewarp_schedule; + String timewarp_schedule; + @JsonProperty HashMap tracking; + @JsonProperty - boolean html_clicks ; + boolean html_clicks; + @JsonProperty - boolean text_clicks ; + boolean text_clicks; + @JsonProperty - boolean opens ; + boolean opens; + @JsonProperty String segment_text; + @JsonProperty List segment_opts; + @JsonProperty List type_opts; + @Override + public String toString() + { + return "CampaignListResponseItem: [id=" + this.id + ", listId=" + this.listId + ", templateId=" + template_id + ", title=" + this.title +"];"; + } public String getId() { diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java index e06351f..d15e297 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java @@ -17,11 +17,10 @@ */ package mailjimp.service; -import java.util.List; - import mailjimp.dom.MailJimpConstants; import mailjimp.dom.request.campaign.CampaignCreateRequest; import mailjimp.dom.response.campaign.CampaignListResponse; +import mailjimp.dom.response.campaign.CampaignListResponseItem; import org.junit.After; import org.junit.Assert; @@ -64,7 +63,7 @@ public void after() { } - //@Test + @Test public void testCreateCampaign() { try { @@ -81,23 +80,33 @@ public void testCreateCampaign() } @Test - public void testListCampaign() + public void testListCampaign() throws InterruptedException { - try { + try { + boolean found = false; log.debug("Test campaign list"); CampaignListResponse response = mSvc.campaignList(null, 0, 10); + // find the campaign I just created + for (CampaignListResponseItem item : response.getItems()) + { + log.debug(item.toString()); + if (item.getId().equals(campaignId)) + found = true; + } + log.debug("Template list campaigns: {}", response); Assert.assertTrue(response != null); + Assert.assertTrue(found); } catch (MailJimpException mje) { processError(mje); } } - //@Test + @Test public void testDeleteCampaign() { try { From 0e17189e2bfa6caecbe48cd3ac74f6263c66dd45 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 26 Apr 2012 09:04:16 -0400 Subject: [PATCH 22/36] added constants for campaigns, added javadoc help reference for interface. --- .../src/main/java/mailjimp/dom/MailJimpConstants.java | 7 +++++-- .../src/main/java/mailjimp/service/IMailJimpService.java | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java b/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java index 806af93..195c6a2 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java @@ -41,7 +41,10 @@ public interface MailJimpConstants extends Serializable { final String CAMPAIGNTYPE_RSS = "rss"; final String CAMPAIGNTYPE_AUTO = "auto"; - - + final String CAMPAIGNSTATUS_SENT = "sent"; + final String CAMPAIGNSTATUS_SAVE = "save"; + final String CAMPAIGNSTATUS_PAUSED = "paused"; + final String CAMPAIGNSTATUS_SCHEDULE = "schedule"; + final String CAMPAIGNSTATUS_SENDING = "sending"; } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index 3fbcfa5..49fd7ba 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -348,7 +348,14 @@ public interface IMailJimpService extends Serializable { */ Boolean campaignDelete(String campaignId) throws MailJimpException; - + /** + Parameters + * filters Filters for returning campaigns see http://apidocs.mailchimp.com/api/rtfm/campaigns.func.php + * start Start position (0 beginning) + * limit number of returns to return (start + limit support pagination) + * @return Object containing a list of campaign items. + * @throws MailJimpException + */ CampaignListResponse campaignList(HashMap filters, int start, int limit) throws MailJimpException; } \ No newline at end of file From 550baf42c7744d07c54c330d44564ec172064bd9 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 26 Apr 2012 10:13:37 -0400 Subject: [PATCH 23/36] modified group ids to distinguish this from the original --- mailjimp-core/pom.xml | 2 +- mailjimp-webhook/pom.xml | 3 ++- pom.xml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mailjimp-core/pom.xml b/mailjimp-core/pom.xml index 4022f9d..4dca859 100644 --- a/mailjimp-core/pom.xml +++ b/mailjimp-core/pom.xml @@ -4,7 +4,7 @@ MailChimp Java API - Core Components - net.mailjimp + ca.morningstar.mailjimp mailjimp-parent 0.4-SNAPSHOT diff --git a/mailjimp-webhook/pom.xml b/mailjimp-webhook/pom.xml index 8b9369b..687732b 100644 --- a/mailjimp-webhook/pom.xml +++ b/mailjimp-webhook/pom.xml @@ -6,7 +6,7 @@ MailChimp Java API - Webhook - net.mailjimp + ca.morningstar.mailjimp mailjimp-parent 0.4-SNAPSHOT @@ -45,4 +45,5 @@ provided + ca.morningstar.mailjimp diff --git a/pom.xml b/pom.xml index 67a6c4e..0098f95 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ 4.0.0 - net.mailjimp + ca.morningstar.mailjimp mailjimp-parent 0.4-SNAPSHOT MailChimp Java API - Meta Project From 63f5d0e7cdc206a130946fa427a8f9e63cec44d7 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 26 Apr 2012 10:16:06 -0400 Subject: [PATCH 24/36] added eclipse junk to gitignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 838ee65..8b18226 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,9 @@ bin/ mailjimp-core/src/test/resources/mailjimp-test.properties mailjimp-core/src/test/resources/mailjimp.properties + +.project + +.settings/org.eclipse.core.resources.prefs + +.settings/org.eclipse.m2e.core.prefs From 8cf7a9470247cb29ac834ad6a7d33dcb37ca0e7b Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Thu, 26 Apr 2012 16:28:03 -0400 Subject: [PATCH 25/36] add support for Google Analytics. --- .../campaign/CampaignCreateRequest.java | 10 ++++- .../campaign/CampaignListResponseItem.java | 39 +++++++++++-------- .../TestMailJimpJsonServiceCampaign.java | 2 +- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java index f7ffe43..442a20f 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignCreateRequest.java @@ -43,7 +43,7 @@ public CampaignCreateRequest(String apikey, String type, HashMap this.content = content; } - static public HashMap buildOptions(String listId, String campaignName, String subject, String fromEmail, String fromName, String toName) + static public HashMap buildOptions(String listId, String campaignName, String subject, String fromEmail, String fromName, String toName, String googleUA) { HashMap options = new HashMap(); @@ -53,6 +53,14 @@ static public HashMap buildOptions(String listId, String campaign options.put("from_email",fromEmail); options.put("from_name",fromName); options.put("to_name",toName); + + if (googleUA != null) + { + HashMap googleua = new HashMap(1); + googleua.put("google", googleUA); + options.put("analytics", googleua); + } + return options; } diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java index c36929f..5cb96f8 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java @@ -1,11 +1,14 @@ package mailjimp.dom.response.campaign; import java.io.Serializable; + import java.util.HashMap; import java.util.List; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.annotate.JsonProperty; +@JsonIgnoreProperties({ "segment_opts", "type_opts" }) //TODO public class CampaignListResponseItem implements Serializable{ @JsonProperty @@ -104,11 +107,13 @@ public class CampaignListResponseItem implements Serializable{ @JsonProperty String segment_text; - @JsonProperty - List segment_opts; - @JsonProperty - List type_opts; + +// @JsonProperty +// List segment_opts; +// +// @JsonProperty +// List type_opts; @Override @@ -310,19 +315,19 @@ public String getSegment_text() { public void setSegment_text(String segment_text) { this.segment_text = segment_text; } - public List getSegment_opts() { - return segment_opts; - } - public void setSegment_opts(List segment_opts) { - this.segment_opts = segment_opts; - } - public List getType_opts() { - return type_opts; - } - public void setType_opts(List type_opts) { - this.type_opts = type_opts; - } - +// public List getSegment_opts() { +// return segment_opts; +// } +// public void setSegment_opts(List segment_opts) { +// this.segment_opts = segment_opts; +// } +// public List getType_opts() { +// return type_opts; +// } +// public void setType_opts(List type_opts) { +// this.type_opts = type_opts; +// } +// diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java index d15e297..b19c7d4 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java @@ -69,7 +69,7 @@ public void testCreateCampaign() try { log.debug("Test campaign create"); String response = mSvc.campaignCreate(MailJimpConstants.CAMPAIGNTYPE_REGULAR, - CampaignCreateRequest.buildOptions(listId, "Test Campaign created by Test case", "Test Subject", "tim.gilbert@morningstar.com", "TestCase User", "Dear Customer"), + CampaignCreateRequest.buildOptions(listId, "Test Campaign created by Test case", "Test Subject", "tim.gilbert@morningstar.com", "TestCase User", "Dear Customer", null), CampaignCreateRequest.buildContentFromString(TEMPLATEHTML, TEMPLATETEXT)); campaignId = response; log.debug("Template updateTemplate: {}", response); From d05d6d146b56099d7e022f1b6cd8bd440de2817d Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Fri, 27 Apr 2012 14:38:44 -0400 Subject: [PATCH 26/36] started adding bounces --- .../CampaignBounceMessagesRequest.java | 108 ++++++++++++++++++ .../CampaignBounceMessageResponse.java | 37 ++++++ .../CampaignBounceMessageResponseItem.java | 46 ++++++++ .../mailjimp/service/IMailJimpService.java | 4 + .../service/impl/MailJimpJsonService.java | 9 ++ 5 files changed, 204 insertions(+) create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignBounceMessagesRequest.java create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponse.java create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignBounceMessagesRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignBounceMessagesRequest.java new file mode 100644 index 0000000..e11bd54 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignBounceMessagesRequest.java @@ -0,0 +1,108 @@ + /* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ + package mailjimp.dom.request.campaign; + + import java.util.Date; + import java.util.HashMap; + import java.util.Locale; + import java.util.TimeZone; + + import mailjimp.dom.request.MailJimpRequest; + + import org.codehaus.jackson.annotate.JsonProperty; + import org.springframework.format.datetime.DateFormatter; + + public class CampaignBounceMessagesRequest extends MailJimpRequest { + + @JsonProperty("cid") + String campaignId; + + @JsonProperty + private int start; + + @JsonProperty + private int limit; + + @JsonProperty + String since; + + static private DateFormatter df = null; + + + public CampaignBounceMessagesRequest(String apikey, String campaignId, Date since, int start, int limit) { + super(apikey); + this.start = start; + this.limit = limit; + this.campaignId = campaignId; + + if (df == null) + { + df = new DateFormatter("yyyy-MM-dd"); + df.setTimeZone(TimeZone.getTimeZone("GMT")); + } + + this.since = df.print(since, Locale.US); + } + + + + + + + public String getCampaignId() { + return campaignId; + } + + + public void setCampaignId(String campaignId) { + this.campaignId = campaignId; + } + + + public int getStart() { + return start; + } + + + public void setStart(int start) { + this.start = start; + } + + + public int getLimit() { + return limit; + } + + + public void setLimit(int limit) { + this.limit = limit; + } + + + public String getSince() { + return since; + } + + + public void setSince(String since) { + this.since = since; + } + + + + } diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponse.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponse.java new file mode 100644 index 0000000..cff1090 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponse.java @@ -0,0 +1,37 @@ +package mailjimp.dom.response.campaign; + +import java.io.Serializable; +import java.util.List; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class CampaignBounceMessageResponse implements Serializable{ + + @JsonProperty + int total; + + @JsonProperty("data") + List items; + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + @Override + public String toString() + { + return "CampaignBounceMessageResponse: [total=" + total+"];"; + } +} diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java new file mode 100644 index 0000000..b190922 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java @@ -0,0 +1,46 @@ +package mailjimp.dom.response.campaign; + +import java.io.Serializable; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class CampaignBounceMessageResponseItem implements Serializable{ + + @JsonProperty + String date; + + @JsonProperty + String email; + + @JsonProperty + String message; + + + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + + + } diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index 49fd7ba..7f30314 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -29,6 +29,7 @@ import mailjimp.dom.enums.MemberStatus; import mailjimp.dom.request.NamedBoolean; import mailjimp.dom.request.list.ListBatchSubscribeStruct; +import mailjimp.dom.response.campaign.CampaignBounceMessageResponse; import mailjimp.dom.response.campaign.CampaignListResponse; import mailjimp.dom.response.list.InterestGrouping; import mailjimp.dom.response.list.ListBatchSubscribeResponse; @@ -357,5 +358,8 @@ public interface IMailJimpService extends Serializable { * @throws MailJimpException */ CampaignListResponse campaignList(HashMap filters, int start, int limit) throws MailJimpException; + + +CampaignBounceMessageResponse campaignBounceMessages(String campaignId, Date since, int start, int limit) throws MailJimpException; } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 32a6ca1..79fdbc6 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -51,6 +51,7 @@ import mailjimp.dom.request.security.ApiKeyExpireRequest; import mailjimp.dom.request.security.ApiKeyRequest; import mailjimp.dom.response.MailJimpErrorResponse; +import mailjimp.dom.response.campaign.CampaignBounceMessageResponse; import mailjimp.dom.response.campaign.CampaignListResponse; import mailjimp.dom.response.list.InterestGrouping; import mailjimp.dom.response.list.ListBatchSubscribeResponse; @@ -355,6 +356,14 @@ public CampaignListResponse campaignList(HashMap filters, int sta CampaignListResponse response = performRequest("campaigns", new mailjimp.dom.request.campaign.CampaignListRequest(apiKey, filters, start, limit), new TypeReference() {/* empty */}); log.debug("campaign List: {}", response); + return response; + } + + @Override + public CampaignBounceMessageResponse campaignBounceMessages(String campaignId, Date since, int start, int limit) throws MailJimpException { + CampaignBounceMessageResponse response = performRequest("campaigns", new mailjimp.dom.request.campaign.CampaignBounceMessagesRequest(apiKey, campaignId, since, start, limit), new TypeReference() {/* empty */}); + log.debug("campaign List: {}", response); + return response; } } \ No newline at end of file From 6e0ccac811f1e18dabb846b42a3e3ff3a9117627 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Fri, 27 Apr 2012 14:47:09 -0400 Subject: [PATCH 27/36] added test case, fixed bug. --- .../CampaignBounceMessageResponseItem.java | 6 +++ .../service/impl/MailJimpJsonService.java | 4 +- .../TestMailJimpJsonServiceCampaign.java | 42 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java index b190922..a389f77 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java @@ -42,5 +42,11 @@ public void setMessage(String message) { } + @Override + public String toString() + { + return "CampaignBoucneMessageResponseItem [date=" + date + ", email=" + email + ", message=" + message + "];"; + } + } diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 79fdbc6..4135bf8 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -361,8 +361,8 @@ public CampaignListResponse campaignList(HashMap filters, int sta @Override public CampaignBounceMessageResponse campaignBounceMessages(String campaignId, Date since, int start, int limit) throws MailJimpException { - CampaignBounceMessageResponse response = performRequest("campaigns", new mailjimp.dom.request.campaign.CampaignBounceMessagesRequest(apiKey, campaignId, since, start, limit), new TypeReference() {/* empty */}); - log.debug("campaign List: {}", response); + CampaignBounceMessageResponse response = performRequest("campaignBounceMessages", new mailjimp.dom.request.campaign.CampaignBounceMessagesRequest(apiKey, campaignId, since, start, limit), new TypeReference() {/* empty */}); + log.debug("campaign Bounce Message: {}", response); return response; } diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java index b19c7d4..446efec 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java @@ -17,8 +17,12 @@ */ package mailjimp.service; +import java.util.Date; + import mailjimp.dom.MailJimpConstants; import mailjimp.dom.request.campaign.CampaignCreateRequest; +import mailjimp.dom.response.campaign.CampaignBounceMessageResponse; +import mailjimp.dom.response.campaign.CampaignBounceMessageResponseItem; import mailjimp.dom.response.campaign.CampaignListResponse; import mailjimp.dom.response.campaign.CampaignListResponseItem; @@ -106,6 +110,44 @@ public void testListCampaign() throws InterruptedException } + @SuppressWarnings("deprecation") +//@Test //TODO enable test after I have sent a campaign + public void testBounceCampaign() throws InterruptedException + { + try { + boolean found = false; + log.debug("Test campaign bounce messages"); + Date since = new Date(); + + if (since.getMonth() == 1) + { + since.setYear(since.getYear()-1); + since.setMonth(11); //DEC + } + else + { + since.setMonth(since.getMonth()-1); + } + + CampaignBounceMessageResponse response = mSvc.campaignBounceMessages(campaignId, since, 0, 10); + + // find the campaign I just created + for (CampaignBounceMessageResponseItem item : response.getItems()) + { + log.debug(item.toString()); + } + + + log.debug("Bounce list campaigns: {}", response); + Assert.assertTrue(response != null); + Assert.assertTrue(found); + } catch (MailJimpException mje) { + processError(mje); + } + } + + + @Test public void testDeleteCampaign() { From 225ff66cd49ff5f1b4bd81c44726337da8cf3903 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Mon, 30 Apr 2012 15:23:53 -0400 Subject: [PATCH 28/36] bounces are now moved to CampaignMembers since bounce is depreciated. --- .../java/mailjimp/dom/MailJimpConstants.java | 4 ++ ...quest.java => CampaignMembersRequest.java} | 30 +++----- .../CampaignBounceMessageResponseItem.java | 52 -------------- ...onse.java => CampaignMembersResponse.java} | 8 +-- .../campaign/CampaignMembersResponseItem.java | 71 +++++++++++++++++++ .../mailjimp/service/IMailJimpService.java | 4 +- .../service/impl/MailJimpJsonService.java | 8 +-- .../TestMailJimpJsonServiceCampaign.java | 22 ++---- 8 files changed, 99 insertions(+), 100 deletions(-) rename mailjimp-core/src/main/java/mailjimp/dom/request/campaign/{CampaignBounceMessagesRequest.java => CampaignMembersRequest.java} (75%) delete mode 100644 mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java rename mailjimp-core/src/main/java/mailjimp/dom/response/campaign/{CampaignBounceMessageResponse.java => CampaignMembersResponse.java} (65%) create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponseItem.java diff --git a/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java b/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java index 195c6a2..b6bbc52 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/MailJimpConstants.java @@ -47,4 +47,8 @@ public interface MailJimpConstants extends Serializable { final String CAMPAIGNSTATUS_SCHEDULE = "schedule"; final String CAMPAIGNSTATUS_SENDING = "sending"; + final String CAMPAIGNMEMBER_STATUS_SENT = "sent"; + final String CAMPAIGNMEMBER_STATUS_HARDBOUNCE = "hard"; + final String CAMPAIGNMEMBER_STATUS_SOFTBOUNCE = "soft"; + final String CAMPAIGNMEMBER_STATUS_ALL = ""; } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignBounceMessagesRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignMembersRequest.java similarity index 75% rename from mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignBounceMessagesRequest.java rename to mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignMembersRequest.java index e11bd54..8f87dcd 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignBounceMessagesRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignMembersRequest.java @@ -27,7 +27,7 @@ import org.codehaus.jackson.annotate.JsonProperty; import org.springframework.format.datetime.DateFormatter; - public class CampaignBounceMessagesRequest extends MailJimpRequest { + public class CampaignMembersRequest extends MailJimpRequest { @JsonProperty("cid") String campaignId; @@ -39,24 +39,14 @@ public class CampaignBounceMessagesRequest extends MailJimpRequest { private int limit; @JsonProperty - String since; + String status; - static private DateFormatter df = null; - - - public CampaignBounceMessagesRequest(String apikey, String campaignId, Date since, int start, int limit) { + public CampaignMembersRequest(String apikey, String campaignId, String status, int start, int limit) { super(apikey); this.start = start; this.limit = limit; - this.campaignId = campaignId; - - if (df == null) - { - df = new DateFormatter("yyyy-MM-dd"); - df.setTimeZone(TimeZone.getTimeZone("GMT")); - } - - this.since = df.print(since, Locale.US); + this.campaignId = campaignId; + this.status = status; } @@ -94,15 +84,13 @@ public void setLimit(int limit) { } - public String getSince() { - return since; + public String getStatus() { + return status; } - - public void setSince(String since) { - this.since = since; + public void setStatus(String status) { + this.status = status; } - } diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java deleted file mode 100644 index a389f77..0000000 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponseItem.java +++ /dev/null @@ -1,52 +0,0 @@ -package mailjimp.dom.response.campaign; - -import java.io.Serializable; - -import org.codehaus.jackson.annotate.JsonProperty; - -public class CampaignBounceMessageResponseItem implements Serializable{ - - @JsonProperty - String date; - - @JsonProperty - String email; - - @JsonProperty - String message; - - - - public String getDate() { - return date; - } - - public void setDate(String date) { - this.date = date; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - - @Override - public String toString() - { - return "CampaignBoucneMessageResponseItem [date=" + date + ", email=" + email + ", message=" + message + "];"; - } - - - } diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponse.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponse.java similarity index 65% rename from mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponse.java rename to mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponse.java index cff1090..39d32af 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignBounceMessageResponse.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponse.java @@ -5,13 +5,13 @@ import org.codehaus.jackson.annotate.JsonProperty; -public class CampaignBounceMessageResponse implements Serializable{ +public class CampaignMembersResponse implements Serializable{ @JsonProperty int total; @JsonProperty("data") - List items; + List items; public int getTotal() { return total; @@ -21,11 +21,11 @@ public void setTotal(int total) { this.total = total; } - public List getItems() { + public List getItems() { return items; } - public void setItems(List items) { + public void setItems(List items) { this.items = items; } diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponseItem.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponseItem.java new file mode 100644 index 0000000..c7ae143 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponseItem.java @@ -0,0 +1,71 @@ +package mailjimp.dom.response.campaign; + +import java.io.Serializable; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class CampaignMembersResponseItem implements Serializable{ + + + @JsonProperty + String email; + + @JsonProperty + String status; + + @JsonProperty + String absplit_group; + + @JsonProperty + String tz_group; + + + @Override + public String toString() + { + return "CampaignBoucneMessageResponseItem [tz_group=" + tz_group + ", email=" + email + ", absplit_group=" + absplit_group + "];"; + } + + + public String getEmail() { + return email; + } + + + public void setEmail(String email) { + this.email = email; + } + + + public String getStatus() { + return status; + } + + + public void setStatus(String status) { + this.status = status; + } + + + public String getAbsplit_group() { + return absplit_group; + } + + + public void setAbsplit_group(String absplit_group) { + this.absplit_group = absplit_group; + } + + + public String getTz_group() { + return tz_group; + } + + + public void setTz_group(String tz_group) { + this.tz_group = tz_group; + } + + + +} diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index 7f30314..341c533 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -29,7 +29,7 @@ import mailjimp.dom.enums.MemberStatus; import mailjimp.dom.request.NamedBoolean; import mailjimp.dom.request.list.ListBatchSubscribeStruct; -import mailjimp.dom.response.campaign.CampaignBounceMessageResponse; +import mailjimp.dom.response.campaign.CampaignMembersResponse; import mailjimp.dom.response.campaign.CampaignListResponse; import mailjimp.dom.response.list.InterestGrouping; import mailjimp.dom.response.list.ListBatchSubscribeResponse; @@ -360,6 +360,6 @@ public interface IMailJimpService extends Serializable { CampaignListResponse campaignList(HashMap filters, int start, int limit) throws MailJimpException; -CampaignBounceMessageResponse campaignBounceMessages(String campaignId, Date since, int start, int limit) throws MailJimpException; + public CampaignMembersResponse campaignMembers(String campaignId, String status, int start, int limit) throws MailJimpException; } \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java index 4135bf8..c95fe77 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/impl/MailJimpJsonService.java @@ -51,7 +51,7 @@ import mailjimp.dom.request.security.ApiKeyExpireRequest; import mailjimp.dom.request.security.ApiKeyRequest; import mailjimp.dom.response.MailJimpErrorResponse; -import mailjimp.dom.response.campaign.CampaignBounceMessageResponse; +import mailjimp.dom.response.campaign.CampaignMembersResponse; import mailjimp.dom.response.campaign.CampaignListResponse; import mailjimp.dom.response.list.InterestGrouping; import mailjimp.dom.response.list.ListBatchSubscribeResponse; @@ -360,9 +360,9 @@ public CampaignListResponse campaignList(HashMap filters, int sta } @Override - public CampaignBounceMessageResponse campaignBounceMessages(String campaignId, Date since, int start, int limit) throws MailJimpException { - CampaignBounceMessageResponse response = performRequest("campaignBounceMessages", new mailjimp.dom.request.campaign.CampaignBounceMessagesRequest(apiKey, campaignId, since, start, limit), new TypeReference() {/* empty */}); - log.debug("campaign Bounce Message: {}", response); + public CampaignMembersResponse campaignMembers(String campaignId, String status, int start, int limit) throws MailJimpException { + CampaignMembersResponse response = performRequest("campaignMembers", new mailjimp.dom.request.campaign.CampaignMembersRequest(apiKey, campaignId, status, start, limit), new TypeReference() {/* empty */}); + log.debug("campaign members: {}", response); return response; } diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java index 446efec..2b29cc7 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonServiceCampaign.java @@ -21,8 +21,8 @@ import mailjimp.dom.MailJimpConstants; import mailjimp.dom.request.campaign.CampaignCreateRequest; -import mailjimp.dom.response.campaign.CampaignBounceMessageResponse; -import mailjimp.dom.response.campaign.CampaignBounceMessageResponseItem; +import mailjimp.dom.response.campaign.CampaignMembersResponse; +import mailjimp.dom.response.campaign.CampaignMembersResponseItem; import mailjimp.dom.response.campaign.CampaignListResponse; import mailjimp.dom.response.campaign.CampaignListResponseItem; @@ -110,29 +110,17 @@ public void testListCampaign() throws InterruptedException } - @SuppressWarnings("deprecation") -//@Test //TODO enable test after I have sent a campaign + //@Test //TODO test after campaign has been sent. public void testBounceCampaign() throws InterruptedException { try { boolean found = false; log.debug("Test campaign bounce messages"); - Date since = new Date(); - if (since.getMonth() == 1) - { - since.setYear(since.getYear()-1); - since.setMonth(11); //DEC - } - else - { - since.setMonth(since.getMonth()-1); - } - - CampaignBounceMessageResponse response = mSvc.campaignBounceMessages(campaignId, since, 0, 10); + CampaignMembersResponse response = mSvc.campaignMembers(campaignId, MailJimpConstants.CAMPAIGNMEMBER_STATUS_HARDBOUNCE, 0,10); // find the campaign I just created - for (CampaignBounceMessageResponseItem item : response.getItems()) + for (CampaignMembersResponseItem item : response.getItems()) { log.debug(item.toString()); } From e1f3fb76edf8d9766f19e43ce8b0dd006c09264a Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Tue, 1 May 2012 14:01:31 -0400 Subject: [PATCH 29/36] added FNAME and LNAME as optional parameters to batch subscribe. --- .../list/ListBatchSubscribeStruct.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStruct.java b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStruct.java index 43629ed..97a1b85 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStruct.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStruct.java @@ -13,6 +13,12 @@ public class ListBatchSubscribeStruct implements Serializable { @JsonProperty("EMAIL_TYPE") private EmailType emailType; + @JsonProperty("FNAME") + private String firstName; + + @JsonProperty("LNAME") + private String lastName; + public ListBatchSubscribeStruct() { // empty } @@ -38,4 +44,21 @@ public EmailType getEmailType() { public void setEmailType(EmailType emailType) { this.emailType = emailType; } + + +public String getFirstName() { + return firstName; +} + +public void setFirstName(String firstName) { + this.firstName = firstName; +} + +public String getLastName() { + return lastName; +} + +public void setLastName(String lastName) { + this.lastName = lastName; +} } From 8fee7b38c1c8a0632bd9a0a872d5778aee00087b Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Fri, 11 May 2012 08:22:02 -0400 Subject: [PATCH 30/36] added new method (untested as of yet) to be able to batch subscribe with a complete merge_vars. --- .../ListBatchSubscribeRequestWithVars.java | 72 +++++++++++++++++++ .../ListBatchSubscribeStructWithVars.java | 29 ++++++++ 2 files changed, 101 insertions(+) create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java create mode 100644 mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStructWithVars.java diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java new file mode 100644 index 0000000..7976a07 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java @@ -0,0 +1,72 @@ +package mailjimp.dom.request.list; + +import java.util.List; + +import org.codehaus.jackson.annotate.JsonProperty; + +import mailjimp.dom.request.MailJimpRequest; + +public class ListBatchSubscribeRequestWithVars extends MailJimpRequest { + @JsonProperty("id") + private String listId; + + private List batch; + + @JsonProperty("double_optin") + private boolean doubleOptin; + + @JsonProperty("update_existing") + private boolean updateExisting; + + @JsonProperty("replace_interests") + private boolean replaceInterests; + + public ListBatchSubscribeRequestWithVars(String apikey, String listId, List batch, boolean doubleOptin, boolean updateExisting, boolean replaceInterests) { + super(apikey); + this.listId = listId; + this.batch = batch; + this.doubleOptin = doubleOptin; + this.updateExisting = updateExisting; + this.replaceInterests = replaceInterests; + } + + public String getListId() { + return listId; + } + + public void setListId(String listId) { + this.listId = listId; + } + + public List getBatch() { + return batch; + } + + public void setBatch(List batch) { + this.batch = batch; + } + + public boolean isDoubleOptin() { + return doubleOptin; + } + + public void setDoubleOptin(boolean doubleOptin) { + this.doubleOptin = doubleOptin; + } + + public boolean isUpdateExisting() { + return updateExisting; + } + + public void setUpdateExisting(boolean updateExisting) { + this.updateExisting = updateExisting; + } + + public boolean isReplaceInterests() { + return replaceInterests; + } + + public void setReplaceInterests(boolean replaceInterests) { + this.replaceInterests = replaceInterests; + } +} \ No newline at end of file diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStructWithVars.java b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStructWithVars.java new file mode 100644 index 0000000..a003116 --- /dev/null +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStructWithVars.java @@ -0,0 +1,29 @@ +package mailjimp.dom.request.list; + +import java.io.Serializable; +import java.util.Map; + +import mailjimp.dom.enums.EmailType; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class ListBatchSubscribeStructWithVars extends ListBatchSubscribeStruct { + @JsonProperty("merge_vars") + private Map mergeVars; + + public ListBatchSubscribeStructWithVars(String emailAddress, EmailType emailType, Map mergeVars) + { + super(emailAddress, emailType); + setMergeVars(mergeVars); + } + + + public Map getMergeVars() { + return mergeVars; + } + + public void setMergeVars(Map mergeVars) { + this.mergeVars = mergeVars; + } + +} From a2f506f81feca5703a7ffb45d211e7d1777f7ca4 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Fri, 11 May 2012 08:40:34 -0400 Subject: [PATCH 31/36] added interface/service support for listbatchsubscribe with vars. --- .../main/java/mailjimp/service/IMailJimpService.java | 8 ++++++-- .../mailjimp/service/impl/MailJimpJsonService.java | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index 341c533..8e37d31 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -29,6 +29,7 @@ import mailjimp.dom.enums.MemberStatus; import mailjimp.dom.request.NamedBoolean; import mailjimp.dom.request.list.ListBatchSubscribeStruct; +import mailjimp.dom.request.list.ListBatchSubscribeStructWithVars; import mailjimp.dom.response.campaign.CampaignMembersResponse; import mailjimp.dom.response.campaign.CampaignListResponse; import mailjimp.dom.response.list.InterestGrouping; @@ -146,8 +147,8 @@ public interface IMailJimpService extends Serializable { * * @throws MailJimpException */ - public ListBatchSubscribeResponse listBatchSubscribe(String listId, List batch, boolean doubleOptin, boolean updateExisting, boolean replaceInterests) throws MailJimpException; - + public ListBatchSubscribeResponse listBatchSubscribe (String listId,List batch, boolean doubleOptin,boolean updateExisting, boolean replaceInterests) throws MailJimpException; + public ListBatchSubscribeResponse listBatchSubscribeWithVars(String listId,List batch, boolean doubleOptin,boolean updateExisting, boolean replaceInterests) throws MailJimpException; /** * Batch subscribe many users to a list. See the batch, boolean doubleOptin, boolean updateExisting, boolean replaceInterests) throws MailJimpException { + ListBatchSubscribeResponse response = performRequest("listBatchSubscribe", new ListBatchSubscribeRequestWithVars(apiKey, listId, batch, doubleOptin, updateExisting, replaceInterests), new TypeReference() {/* empty */}); + log.debug("List batch subscribe response: {}", response); + return response; + } + + @Override public ListBatchUnsubscribeResponse listBatchUnsubscribe(String listId, List emails, boolean deleteMember, boolean sendGoodbye, boolean sendNotify) throws MailJimpException { From f44021766e5376350cc97dc46328e00969bcd375 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Fri, 11 May 2012 09:37:42 -0400 Subject: [PATCH 32/36] tested listBatchSubscribeWithVars --- .../ListBatchSubscribeRequestWithVars.java | 42 ++++++++++++----- .../service/TestMailJimpJsonService.java | 46 +++++++++++++++++++ 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java index 7976a07..0054e59 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java @@ -1,16 +1,20 @@ package mailjimp.dom.request.list; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; -import org.codehaus.jackson.annotate.JsonProperty; - +import mailjimp.dom.MailJimpConstants; import mailjimp.dom.request.MailJimpRequest; +import org.codehaus.jackson.annotate.JsonProperty; + public class ListBatchSubscribeRequestWithVars extends MailJimpRequest { @JsonProperty("id") private String listId; - private List batch; + private List> batch; @JsonProperty("double_optin") private boolean doubleOptin; @@ -23,11 +27,25 @@ public class ListBatchSubscribeRequestWithVars extends MailJimpRequest { public ListBatchSubscribeRequestWithVars(String apikey, String listId, List batch, boolean doubleOptin, boolean updateExisting, boolean replaceInterests) { super(apikey); - this.listId = listId; - this.batch = batch; + this.listId = listId; this.doubleOptin = doubleOptin; this.updateExisting = updateExisting; this.replaceInterests = replaceInterests; + + this.batch = new ArrayList>(batch.size()); + for (ListBatchSubscribeStructWithVars v : batch) + { + HashMap data = new HashMap(); + + data.put(MailJimpConstants.MERGE_EMAIL, v.getEmailAddress()); + data.put(MailJimpConstants.MERGE_EMAIL_TYPE, v.getEmailType()); + data.put(MailJimpConstants.MERGE_FNAME, v.getFirstName()); + data.put(MailJimpConstants.MERGE_LNAME, v.getLastName()); + + data.putAll(v.getMergeVars()); + + this.batch.add(data); + } } public String getListId() { @@ -38,13 +56,7 @@ public void setListId(String listId) { this.listId = listId; } - public List getBatch() { - return batch; - } - public void setBatch(List batch) { - this.batch = batch; - } public boolean isDoubleOptin() { return doubleOptin; @@ -69,4 +81,12 @@ public boolean isReplaceInterests() { public void setReplaceInterests(boolean replaceInterests) { this.replaceInterests = replaceInterests; } + +public List> getBatch() { + return batch; +} + +public void setBatch(List> batch) { + this.batch = batch; +} } \ No newline at end of file diff --git a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonService.java b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonService.java index 8a4f0ee..aff42ac 100644 --- a/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonService.java +++ b/mailjimp-core/src/test/java/mailjimp/service/TestMailJimpJsonService.java @@ -32,6 +32,7 @@ import mailjimp.dom.enums.InterestGroupingUpdateType; import mailjimp.dom.enums.MemberStatus; import mailjimp.dom.request.list.ListBatchSubscribeStruct; +import mailjimp.dom.request.list.ListBatchSubscribeStructWithVars; import mailjimp.dom.response.list.InterestGrouping; import mailjimp.dom.response.list.ListBatchSubscribeResponse; import mailjimp.dom.response.list.ListBatchUnsubscribeResponse; @@ -42,6 +43,7 @@ import org.apache.commons.lang3.RandomStringUtils; import org.junit.After; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -225,6 +227,50 @@ public void testListSubscribeMergeVars() { } } + + @Test + public void testListBatchSubscribeMergeVars() { + final int NUM_EMAILS = 10; + + List data = new ArrayList(); + + for (int ndx = 0; ndx < NUM_EMAILS; ndx++) + { + String name = "test" + RandomStringUtils.randomNumeric(5); + String email = name + "@laccetti.com"; + Map merges = new HashMap(); + merges.put(MailJimpConstants.MERGE_EMAIL, email); + merges.put(MailJimpConstants.MERGE_FNAME, name); + merges.put(MailJimpConstants.MERGE_LNAME, "TestMergeVars"); + merges.put("MMERGE3", "test merge"); + + List> groupings = new ArrayList>(); + Map groups = new HashMap(); + groups.put("name", "Test Group"); + groups.put("groups", "Group 1"); + groupings.add(groups); + merges.put("GROUPINGS", groupings); + + data.add(new ListBatchSubscribeStructWithVars(email, EmailType.HTML, merges)); + } + + + try { + log.debug("Test list subscribe with merges"); + ListBatchSubscribeResponse response = mSvc.listBatchSubscribeWithVars(listId, data, false, true, true); + log.debug("Batch Submitted subscribed: {}", response); + + int count = response.getAddCount() + response.getUpdateCount(); + Assert.assertTrue(count == NUM_EMAILS); + Assert.assertTrue(response.getErrorCount() == 0); + } catch (MailJimpException mje) { + processError(mje); + } + } + + + + @Test public void testListUpdateMember() { try { From ac4a44667544a3d9d674bc28b64c72027db05245 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Fri, 11 May 2012 16:47:28 -0400 Subject: [PATCH 33/36] organize imports. --- .../dom/request/campaign/CampaignMembersRequest.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignMembersRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignMembersRequest.java index 8f87dcd..e0b1590 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignMembersRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignMembersRequest.java @@ -17,15 +17,9 @@ */ package mailjimp.dom.request.campaign; - import java.util.Date; - import java.util.HashMap; - import java.util.Locale; - import java.util.TimeZone; - import mailjimp.dom.request.MailJimpRequest; - import org.codehaus.jackson.annotate.JsonProperty; - import org.springframework.format.datetime.DateFormatter; +import org.codehaus.jackson.annotate.JsonProperty; public class CampaignMembersRequest extends MailJimpRequest { From 7512d179a13f1c91aca1a54a8020aa685456195f Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Mon, 14 May 2012 11:45:08 -0400 Subject: [PATCH 34/36] clean up commit to add docs, copyright etc. --- .../request/campaign/CampaignListRequest.java | 3 +- .../ListBatchSubscribeRequestWithVars.java | 17 +++++++++ .../ListBatchSubscribeStructWithVars.java | 17 +++++++++ .../request/template/TemplateAddRequest.java | 1 - .../request/template/TemplateInfoRequest.java | 2 +- .../request/template/TemplateListRequest.java | 8 ---- .../template/TemplateUpdateRequest.java | 2 +- .../campaign/CampaignListResponse.java | 17 +++++++++ .../campaign/CampaignListResponseItem.java | 17 +++++++++ .../campaign/CampaignMembersResponse.java | 17 +++++++++ .../campaign/CampaignMembersResponseItem.java | 17 +++++++++ .../template/TemplateListResponse.java | 17 +++++++++ .../mailjimp/service/IMailJimpService.java | 37 +++++++++++++++---- 13 files changed, 153 insertions(+), 19 deletions(-) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignListRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignListRequest.java index 8bf6dd7..2914b50 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignListRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/campaign/CampaignListRequest.java @@ -38,6 +38,7 @@ public class CampaignListRequest extends MailJimpRequest { @JsonProperty HashMap filters; + //TODO //TMG MailJimpConstant uses SimpleDateFormat, perhaps I should drop this and use that. static DateFormatter df = null; @@ -48,7 +49,7 @@ public CampaignListRequest(String apikey, HashMap filters, int st this.limit = limit; if (df == null) - { + { df = new DateFormatter("yyyy-MM-dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone("GMT")); } diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java index 0054e59..f2bb5a2 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeRequestWithVars.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.request.list; import java.util.ArrayList; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStructWithVars.java b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStructWithVars.java index a003116..eff5ff3 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStructWithVars.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/list/ListBatchSubscribeStructWithVars.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.request.list; import java.io.Serializable; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java index c2a9b19..e942380 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateAddRequest.java @@ -23,7 +23,6 @@ public class TemplateAddRequest extends MailJimpRequest { - private static final long serialVersionUID = 1L; @JsonProperty private String name; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateInfoRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateInfoRequest.java index 94ee31a..1267b49 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateInfoRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateInfoRequest.java @@ -26,7 +26,7 @@ public class TemplateInfoRequest extends MailJimpRequest { private static final long serialVersionUID = 1L; @JsonProperty - private int tid = -1; + private int tid; @JsonProperty private String type; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java index 43ef184..42b276c 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateListRequest.java @@ -26,8 +26,6 @@ public class TemplateListRequest extends MailJimpRequest { - - private static final long serialVersionUID = 1L; @JsonProperty private List types; @@ -77,10 +75,4 @@ public List getInactives() { public void setInactives(List inactives) { this.inactives = inactives; } - - - public static long getSerialversionuid() { - return serialVersionUID; - } - } diff --git a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java index bbab344..5ea7c18 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/request/template/TemplateUpdateRequest.java @@ -29,7 +29,7 @@ public class TemplateUpdateRequest extends MailJimpRequest { private static final long serialVersionUID = 1L; @JsonProperty - private int id = -1; + private int id; @JsonProperty private Map values = null; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java index fd07416..b519af4 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponse.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.response.campaign; import java.io.Serializable; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java index 5cb96f8..2104d95 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.response.campaign; import java.io.Serializable; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponse.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponse.java index 39d32af..440adfc 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponse.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponse.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.response.campaign; import java.io.Serializable; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponseItem.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponseItem.java index c7ae143..cb2213e 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponseItem.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignMembersResponseItem.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.response.campaign; import java.io.Serializable; diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListResponse.java b/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListResponse.java index 505c268..7dece67 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListResponse.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/template/TemplateListResponse.java @@ -1,3 +1,20 @@ +/* + * Copyright 2011 Michael Laccetti and Tim Gilbert + * + * This file is part of MailJimp and forked MailJimp under https://github.com/knaak/MailJimp + * + * MailJimp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * MailJimp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MailJimp. If not, see . + */ package mailjimp.dom.response.template; import java.util.List; diff --git a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java index 8e37d31..c3a8cf4 100644 --- a/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java +++ b/mailjimp-core/src/main/java/mailjimp/service/IMailJimpService.java @@ -148,6 +148,26 @@ public interface IMailJimpService extends Serializable { * @throws MailJimpException */ public ListBatchSubscribeResponse listBatchSubscribe (String listId,List batch, boolean doubleOptin,boolean updateExisting, boolean replaceInterests) throws MailJimpException; + + + + /** + * Batch subscribe a user to a mailing list while allowing you to pass a List of List Variables. + * See the MailChimp API for more info. + * + * + * @param listId + * @param batch + * @param doubleOptin + * @param updateExisting + * @param replaceInterests + * + * @return The result of this call. Containing add, update and error counts. + * In case of errors contains additional information. + * + * @throws MailJimpException + */ public ListBatchSubscribeResponse listBatchSubscribeWithVars(String listId,List batch, boolean doubleOptin,boolean updateExisting, boolean replaceInterests) throws MailJimpException; /** @@ -322,14 +342,12 @@ public interface IMailJimpService extends Serializable { TemplateInfoResponse templateInfo(int templateId, String type) throws MailJimpException; /** + * Partial implementation of TemplateList which returns all templates in MC Parameters * @return TemplateListResponse on success with all user templates. * @throws MailJimpException */ TemplateListResponse templateList() throws MailJimpException; - // there are a lot of template options which I have chosen not to implement since i don't use them, this is how the signature - // might have looked like otherwise. - //TemplateListResponse templateList(String category,List types, List inactives) throws MailJimpException; /** @@ -360,10 +378,15 @@ public interface IMailJimpService extends Serializable { */ CampaignListResponse campaignList(HashMap filters, int start, int limit) throws MailJimpException; - + /** + * Allows you to pull lists of members from a particular campaign, used to pull bounces, unsubscribes, etc via status field. + Parameters + * filters Filters for returning campaigns see http://apidocs.mailchimp.com/api/rtfm/campaigns.func.php + * start Start position (0 beginning) + * limit number of returns to return (start + limit support pagination) + * @return Object containing a list of campaign items. + * @throws MailJimpException + */ public CampaignMembersResponse campaignMembers(String campaignId, String status, int start, int limit) throws MailJimpException; - - - } \ No newline at end of file From dfe1c8d6e3bd6003c9282007ce12495df2ed7e34 Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Mon, 10 Sep 2012 11:09:44 -0400 Subject: [PATCH 35/36] MailChimp changed the API to have a new field required called visibility. --- .../java/mailjimp/dom/response/list/MailingList.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/list/MailingList.java b/mailjimp-core/src/main/java/mailjimp/dom/response/list/MailingList.java index ff96b81..c26b1cb 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/list/MailingList.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/list/MailingList.java @@ -63,6 +63,9 @@ public class MailingList { @JsonProperty("beamer_address") private String beamerAddress; + @JsonProperty("visibility") + private String visibility; + private MailingListStats stats; private List modules; @@ -203,4 +206,12 @@ public void setModules(List modules) { public String toString() { return "MailingList [id=" + id + ", webId=" + webId + ", name=" + name + ", dateCreated=" + dateCreated + ", emailTypeOption=" + emailTypeOption + ", useAwesomebar=" + useAwesomebar + ", defaultFromName=" + defaultFromName + ", defaultFromEmail=" + defaultFromEmail + ", defaultSubject=" + defaultSubject + ", defaultLanguage=" + defaultLanguage + ", listRating=" + listRating + ", subscribeUrlShort=" + subscribeUrlShort + ", subscribeUrlLong=" + subscribeUrlLong + ", beamerAddress=" + beamerAddress + ", stats=" + stats + ", modules=" + modules + "]"; } + +public String getVisibility() { + return visibility; +} + +public void setVisibility(String visibility) { + this.visibility = visibility; +} } \ No newline at end of file From 776b1621ff8994bd64d7b2415c24fcb07d8b2e9f Mon Sep 17 00:00:00 2001 From: Tim Gilbert Date: Mon, 10 Dec 2012 08:26:03 -0500 Subject: [PATCH 36/36] added new property parent_id MailChimp added a new property to their API without incrementing the API version number. --- .../response/campaign/CampaignListResponseItem.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java index 2104d95..6729ef8 100644 --- a/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java +++ b/mailjimp-core/src/main/java/mailjimp/dom/response/campaign/CampaignListResponseItem.java @@ -124,6 +124,9 @@ public class CampaignListResponseItem implements Serializable{ @JsonProperty String segment_text; + @JsonProperty + String parent_id; + // @JsonProperty @@ -345,6 +348,16 @@ public void setSegment_text(String segment_text) { // this.type_opts = type_opts; // } // + + + public String getParent_id() { + return parent_id; + } + + + public void setParent_id(String parent_id) { + this.parent_id = parent_id; + }