diff --git a/pom.xml b/pom.xml
index fbc785d..dd9751c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,50 +33,58 @@
-
- org.apache.httpcomponents
- httpclient
- 4.1.1
-
-
- junit
- junit
- 4.10
- test
-
-
- org.codehaus.jackson
- jackson-mapper-asl
- 1.9.4
-
-
- org.mockito
- mockito-all
- 1.8.4
- test
-
-
- commons-io
- commons-io
- 2.0
- test
-
+
+ org.apache.httpcomponents
+ httpclient
+ 4.1.1
+
+
+ junit
+ junit
+ 4.10
+ test
+
+
+ org.codehaus.jackson
+ jackson-mapper-asl
+ 1.9.4
+
+
+ org.mockito
+ mockito-all
+ 1.8.4
+ test
+
+
+ commons-io
+ commons-io
+ 2.0
+ test
+
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 2.3.2
-
- 1.5
- 1.5
-
-
-
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.5
+ 1.5
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.12.4
+
+ true
+
+
+
diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/exception/RequestFailedException.java b/src/main/java/com/cribbstechnologies/clients/mandrill/exception/RequestFailedException.java
index 5a2113b..f442408 100644
--- a/src/main/java/com/cribbstechnologies/clients/mandrill/exception/RequestFailedException.java
+++ b/src/main/java/com/cribbstechnologies/clients/mandrill/exception/RequestFailedException.java
@@ -1,6 +1,6 @@
package com.cribbstechnologies.clients.mandrill.exception;
-public class RequestFailedException extends Throwable {
+public class RequestFailedException extends Exception {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/model/Attachment.java b/src/main/java/com/cribbstechnologies/clients/mandrill/model/Attachment.java
new file mode 100644
index 0000000..118907e
--- /dev/null
+++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/Attachment.java
@@ -0,0 +1,44 @@
+package com.cribbstechnologies.clients.mandrill.model;
+
+/**
+ *
+ * @author Martin Zapata
+ *
+ */
+
+public class Attachment implements java.io.Serializable {
+
+ private String type, name, content;
+
+ public Attachment(String type, String name, String content) {
+ this.type = type;
+ this.name = name;
+ this.content = content;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+
+}
diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessage.java b/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessage.java
index a843770..1db59be 100644
--- a/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessage.java
+++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessage.java
@@ -17,9 +17,11 @@ public class MandrillMessage {
private String[] tags = new String[0];
private String[] google_analytics_domains = new String[0];
private String[] google_analytics_campaign = new String[0];
- private List global_merge_vars;
- List merge_vars;
-
+ private Map metadata;
+ private List global_merge_vars;
+ List merge_vars;
+ private String subaccount;
+ private List attachments;
private Map headers;
public String getSubject() {
@@ -142,4 +144,28 @@ public List getMerge_vars() {
public void setMerge_vars(List merge_vars) {
this.merge_vars = merge_vars;
}
+
+ public List getAttachments() {
+ return attachments;
+ }
+
+ public void setAttachments(List attachments) {
+ this.attachments = attachments;
+ }
+
+ public String getSubaccount() {
+ return subaccount;
+ }
+
+ public void setSubaccount(String subaccount) {
+ this.subaccount = subaccount;
+ }
+
+ public Map getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(Map metadata) {
+ this.metadata = metadata;
+ }
}
diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessageRequest.java b/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessageRequest.java
index f54c348..2af5b0a 100644
--- a/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessageRequest.java
+++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessageRequest.java
@@ -11,7 +11,5 @@ public MandrillMessage getMessage() {
public void setMessage(MandrillHtmlMessage message) {
this.message = message;
}
-
-
}
diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRecipient.java b/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRecipient.java
index 5542dc2..0a9e0c4 100644
--- a/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRecipient.java
+++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRecipient.java
@@ -1,29 +1,43 @@
package com.cribbstechnologies.clients.mandrill.model;
public class MandrillRecipient {
-
- String email;
- String name;
-
- public MandrillRecipient(String name, String email) {
- this.email = email;
- this.name = name;
- }
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
+
+ String email;
+ String name;
+ String type;
+
+ public MandrillRecipient(String name, String email) {
+ this.email = email;
+ this.name = name;
+ }
+
+ public MandrillRecipient(String name, String email, String type) {
+ this(name, email);
+ this.type = type;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
}
diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/model/ServiceMethods.java b/src/main/java/com/cribbstechnologies/clients/mandrill/model/ServiceMethods.java
index 292ec94..70423e7 100644
--- a/src/main/java/com/cribbstechnologies/clients/mandrill/model/ServiceMethods.java
+++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/ServiceMethods.java
@@ -52,6 +52,7 @@ public class Senders {
public static final String DOMAINS = "senders/domain.json";
public static final String INFO = "senders/info.json";
public static final String TIME_SERIES = "senders/time-series.json";
+ public static final String CHECK_DOMAIN = "senders/check-domain.json";
}
public class Urls {
diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/senders/AuthenticationInfo.java b/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/senders/AuthenticationInfo.java
new file mode 100644
index 0000000..2b5eb20
--- /dev/null
+++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/senders/AuthenticationInfo.java
@@ -0,0 +1,46 @@
+/*
+ * AuthenticationInfo.java
+ *
+ * Created on Apr 27, 2016, 1:07:39 PM
+ *
+ * Copyright (C) 2014, Blueprint Solutions Inc.
+ * All rights reserved.
+ */
+
+package com.cribbstechnologies.clients.mandrill.model.response.senders;
+
+/**
+ *
+ * @author Aleem Sunderji, aleem@bp-solutions.net
+ */
+public class AuthenticationInfo {
+
+ // Instance variables
+ protected boolean valid;
+ protected String valid_after;
+ protected String error;
+
+ public boolean isValid() {
+ return valid;
+ }
+
+ public void setValid(boolean valid) {
+ this.valid = valid;
+ }
+
+ public String getValid_after() {
+ return valid_after;
+ }
+
+ public void setValid_after(String valid_after) {
+ this.valid_after = valid_after;
+ }
+
+ public String getError() {
+ return error;
+ }
+
+ public void setError(String error) {
+ this.error = error;
+ }
+}
diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/senders/DomainInfoResponse.java b/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/senders/DomainInfoResponse.java
new file mode 100644
index 0000000..2c63e4b
--- /dev/null
+++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/senders/DomainInfoResponse.java
@@ -0,0 +1,71 @@
+package com.cribbstechnologies.clients.mandrill.model.response.senders;
+
+import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
+
+public class DomainInfoResponse extends BaseMandrillResponse {
+
+ protected String domain;
+ protected String created_at;
+ protected String last_tested_at;
+ protected AuthenticationInfo spf;
+ protected AuthenticationInfo dkim;
+ protected String verified_at;
+ protected boolean valid_signing;
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ public String getCreated_at() {
+ return created_at;
+ }
+
+ public void setCreated_at(String created_at) {
+ this.created_at = created_at;
+ }
+
+ public String getLast_tested_at() {
+ return last_tested_at;
+ }
+
+ public void setLast_tested_at(String last_tested_at) {
+ this.last_tested_at = last_tested_at;
+ }
+
+ public String getVerified_at() {
+ return verified_at;
+ }
+
+ public void setVerified_at(String verified_at) {
+ this.verified_at = verified_at;
+ }
+
+ public boolean isValid_signing() {
+ return valid_signing;
+ }
+
+ public void setValid_signing(boolean valid_signing) {
+ this.valid_signing = valid_signing;
+ }
+
+ public AuthenticationInfo getSpf() {
+ return spf;
+ }
+
+ public void setSpf(AuthenticationInfo spf) {
+ this.spf = spf;
+ }
+
+ public AuthenticationInfo getDkim() {
+ return dkim;
+ }
+
+ public void setDkim(AuthenticationInfo dkim) {
+ this.dkim = dkim;
+ }
+
+}
diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillSendersRequest.java b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillSendersRequest.java
new file mode 100644
index 0000000..45272a4
--- /dev/null
+++ b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillSendersRequest.java
@@ -0,0 +1,35 @@
+package com.cribbstechnologies.clients.mandrill.request;
+
+import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
+import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithDomain;
+import com.cribbstechnologies.clients.mandrill.model.ServiceMethods;
+import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
+import com.cribbstechnologies.clients.mandrill.model.response.senders.DomainInfoResponse;
+
+/**
+ *
+ * This class holds functions provided by the Mandrill Senders API
+ *
+ * @author Aleem Sunderji, aleem@bp-solutions.net
+ *
+ */
+public class MandrillSendersRequest {
+
+ protected MandrillRESTRequest request;
+
+ /**
+ * Return information about a specific sending domain
+ *
+ * @param domainRequest a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest
+ * @throws RequestFailedException
+ */
+ public DomainInfoResponse checkDomain(MandrillRequestWithDomain domainRequest) throws RequestFailedException {
+ BaseMandrillResponse response = request.postRequest(domainRequest, ServiceMethods.Senders.CHECK_DOMAIN, DomainInfoResponse.class);
+ return (DomainInfoResponse)response;
+ }
+
+ public void setRequest(MandrillRESTRequest request) {
+ this.request = request;
+ }
+
+}
diff --git a/src/test/java/com/cribbstechnologies/clients/mandrill/request/MandrillRESTRequestTest.java b/src/test/java/com/cribbstechnologies/clients/mandrill/request/MandrillRESTRequestTest.java
index 368668b..b6422d1 100644
--- a/src/test/java/com/cribbstechnologies/clients/mandrill/request/MandrillRESTRequestTest.java
+++ b/src/test/java/com/cribbstechnologies/clients/mandrill/request/MandrillRESTRequestTest.java
@@ -9,14 +9,23 @@
import static org.mockito.Mockito.doThrow;
import static org.mockito.MockitoAnnotations.initMocks;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.net.MalformedURLException;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.imageio.ImageIO;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Base64InputStream;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@@ -36,6 +45,7 @@
import org.mockito.Mockito;
import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
+import com.cribbstechnologies.clients.mandrill.model.Attachment;
import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
import com.cribbstechnologies.clients.mandrill.model.MandrillHtmlMessage;
import com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest;
@@ -243,6 +253,10 @@ public void testGetPostDataMandrillMessageRequest() throws Exception {
mutableMessage.setHeaders(headerMap);
+ List attachments = new ArrayList();
+ attachments.add(new Attachment("image/jpeg", "jose.png", sampleBase64Image()));
+ mutableMessage.setAttachments(attachments);
+
mutableMessageRequest.setMessage(mutableMessage);
// System.out.println(request.getPostData(mutableMessageRequest));
StringBuffer sb = new StringBuffer();
@@ -263,6 +277,7 @@ public void testGetPostDataMandrillMessageRequest() throws Exception {
sb.append(",\"google_analytics_campaign\":[]");
sb.append(",\"global_merge_vars\":null");
sb.append(",\"merge_vars\":null");
+ sb.append(",\"attachments\":[{\"type\":\"image/jpeg\",\"name\":\"jose.png\",\"content\":\"W3siZW1haWwiOiAiZXhhbXBsZSBlbWFpbCIsICJzdGF0dXMiOiAiZXhhbXBsZSBzdGF0dXMifSx7\\r\\nImVtYWlsIjogImV4YW1wbGUgZW1haWwyIiwgInN0YXR1cyI6ICJleGFtcGxlIHN0YXR1czIifV0=\\r\\n\"}]");
sb.append(",\"headers\":{\"headerName\":\"headerValue\"},");
sb.append("\"html\":\"Test html\"");
sb.append("}}");
@@ -271,6 +286,13 @@ public void testGetPostDataMandrillMessageRequest() throws Exception {
assertEquals(sb.toString(), output);
}
+ private String sampleBase64Image() throws IOException {
+ StringWriter sw = new StringWriter();
+ IOUtils.copy(new Base64InputStream(this.getClass().getClassLoader().getResourceAsStream("messages/sendMessageResponse.txt"), true), sw);
+
+ return sw.toString();
+ }
+
@Test
public void testPostRequest() throws ClientProtocolException, IOException {
request = new MandrillRESTRequest();
diff --git a/src/test/resources/messages/jose.jpeg b/src/test/resources/messages/jose.jpeg
new file mode 100644
index 0000000..40551fa
Binary files /dev/null and b/src/test/resources/messages/jose.jpeg differ