diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0e4507 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.classpath +.project +.settings +/target diff --git a/pom.xml b/pom.xml index 8bf23b5..fbc785d 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.cribbstechnologies.clients mandrillClient - 0.0.1-SNAPSHOT + 0.0.2-SNAPSHOT jar Java Mandrill Wrapper A Java wrapper for Mandrill @@ -64,4 +64,19 @@ - \ No newline at end of file + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.5 + 1.5 + + + + + diff --git a/src/it/java/com/cribbstechnologies/clients/mandrill/it/UsersTest.java b/src/it/java/com/cribbstechnologies/clients/mandrill/it/UsersTest.java index e67e503..4670343 100644 --- a/src/it/java/com/cribbstechnologies/clients/mandrill/it/UsersTest.java +++ b/src/it/java/com/cribbstechnologies/clients/mandrill/it/UsersTest.java @@ -19,6 +19,7 @@ import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail; import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillStringResponse; import com.cribbstechnologies.clients.mandrill.model.response.users.DisableResponse; +import com.cribbstechnologies.clients.mandrill.model.response.users.PingResponse; import com.cribbstechnologies.clients.mandrill.model.response.users.UsersInfoResponse; import com.cribbstechnologies.clients.mandrill.model.response.users.UsersSendersResponse; import com.cribbstechnologies.clients.mandrill.model.response.users.VerifyResponse; @@ -28,87 +29,99 @@ public class UsersTest { - private static MandrillRESTRequest request = new MandrillRESTRequest(); - private static MandrillConfiguration config = new MandrillConfiguration(); - private static MandrillUsersRequest usersRequest = new MandrillUsersRequest(); - private static HttpClient client; - private static ObjectMapper mapper = new ObjectMapper(); - private static Properties props = new Properties(); - - @BeforeClass - public static void beforeClass() { - try { - props.load(UsersTest.class.getClassLoader().getResourceAsStream("mandrill.properties")); - } catch (IOException e) { - fail ("properties file not loaded"); - } - config.setApiKey(props.getProperty("apiKey")); - config.setApiVersion("1.0"); - config.setBaseURL("https://mandrillapp.com/api"); - request.setConfig(config); - request.setObjectMapper(mapper); - usersRequest.setRequest(request); - } - - @Before - public void before() { - client = new DefaultHttpClient(); - request.setHttpClient(client); - } - - @Test - public void testPing() { - BaseMandrillRequest baseRequest = new BaseMandrillRequest(); - try { - BaseMandrillStringResponse response = usersRequest.performPing(baseRequest); - assertEquals("\"PONG!\"", response.getResponse()); - } catch (RequestFailedException e) { - fail(e.getMessage()); - } - } - - @Test - public void testGetInfo() { - BaseMandrillRequest baseRequest = new BaseMandrillRequest(); - try { - UsersInfoResponse response = usersRequest.getInfo(baseRequest); - } catch (RequestFailedException e) { - fail(e.getMessage()); - } - } - - @Test - public void testGetSenders() { - BaseMandrillRequest baseRequest = new BaseMandrillRequest(); - try { - UsersSendersResponse response = usersRequest.getSenders(baseRequest); - } catch (RequestFailedException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void testVerifySender() { - MandrillRequestWithEmail emailRequest = new MandrillRequestWithEmail(); - emailRequest.setEmail(props.getProperty("verify.email")); - try { - VerifyResponse response = usersRequest.verifySender(emailRequest); - } catch (RequestFailedException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void testDisableSender() { - MandrillRequestWithDomain domainRequest = new MandrillRequestWithDomain(); - domainRequest.setDomain("google.com"); - try { - DisableResponse response = usersRequest.disableSender(domainRequest); - } catch (RequestFailedException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } + private static MandrillRESTRequest request = new MandrillRESTRequest(); + private static MandrillConfiguration config = new MandrillConfiguration(); + private static MandrillUsersRequest usersRequest = new MandrillUsersRequest(); + private static HttpClient client; + private static ObjectMapper mapper = new ObjectMapper(); + private static Properties props = new Properties(); + + @BeforeClass + public static void beforeClass() { + try { + props.load(UsersTest.class.getClassLoader().getResourceAsStream("mandrill.properties")); + } catch (IOException e) { + fail("properties file not loaded"); + } + config.setApiKey(props.getProperty("apiKey")); + config.setApiVersion("1.0"); + config.setBaseURL("https://mandrillapp.com/api"); + request.setConfig(config); + request.setObjectMapper(mapper); + usersRequest.setRequest(request); + } + + @Before + public void before() { + client = new DefaultHttpClient(); + request.setHttpClient(client); + } + + @Test + public void testPing() { + BaseMandrillRequest baseRequest = new BaseMandrillRequest(); + try { + BaseMandrillStringResponse response = usersRequest.performPing(baseRequest); + assertEquals("\"PONG!\"", response.getResponse()); + } catch (RequestFailedException e) { + fail(e.getMessage()); + } + } + + @Test + public void testPing2() { + BaseMandrillRequest baseRequest = new BaseMandrillRequest(); + try { + PingResponse pingResponse = usersRequest.performPing2(baseRequest); + assertEquals("PONG!", pingResponse.getPingResponse()); + } catch (RequestFailedException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void testGetInfo() { + BaseMandrillRequest baseRequest = new BaseMandrillRequest(); + try { + UsersInfoResponse response = usersRequest.getInfo(baseRequest); + } catch (RequestFailedException e) { + fail(e.getMessage()); + } + } + + @Test + public void testGetSenders() { + BaseMandrillRequest baseRequest = new BaseMandrillRequest(); + try { + UsersSendersResponse response = usersRequest.getSenders(baseRequest); + } catch (RequestFailedException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void testVerifySender() { + MandrillRequestWithEmail emailRequest = new MandrillRequestWithEmail(); + emailRequest.setEmail(props.getProperty("verify.email")); + try { + VerifyResponse response = usersRequest.verifySender(emailRequest); + } catch (RequestFailedException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void testDisableSender() { + MandrillRequestWithDomain domainRequest = new MandrillRequestWithDomain(); + domainRequest.setDomain("google.com"); + try { + DisableResponse response = usersRequest.disableSender(domainRequest); + } catch (RequestFailedException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } } 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..bd5e5dc --- /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 { + + 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/BaseMandrillRequest.java b/src/main/java/com/cribbstechnologies/clients/mandrill/model/BaseMandrillRequest.java index 30c46f6..0633702 100644 --- a/src/main/java/com/cribbstechnologies/clients/mandrill/model/BaseMandrillRequest.java +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/BaseMandrillRequest.java @@ -2,18 +2,20 @@ public class BaseMandrillRequest { - /* - * It's not necessary to set this field manually as the MandrillRESTRequest pulls the property - * from the configuration and populates this object with it on every request. - */ - private String key; + private String key; - public String getKey() { - return key; - } + public String getKey() { + return key; + } - public void setKey(String key) { - this.key = key; - } + /** + * It's not necessary to set this field manually as the MandrillRESTRequest pulls the property from the configuration and + * populates this object with it on every request + * + * @param key + */ + public void setKey(String key) { + this.key = key; + } } 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..1852e92 100644 --- a/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessage.java +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessage.java @@ -19,6 +19,7 @@ public class MandrillMessage { private String[] google_analytics_campaign = new String[0]; private List global_merge_vars; List merge_vars; + private List attachments; private Map headers; @@ -142,4 +143,12 @@ 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; + } } diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillResponse.java b/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillResponse.java index 93beb01..6304ca8 100644 --- a/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillResponse.java +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillResponse.java @@ -1,24 +1,27 @@ package com.cribbstechnologies.clients.mandrill.model; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) public class MandrillResponse { - private String responseString; - private boolean success; - - public String getJsonResponse() { - return responseString; - } - - public void setResponseString(String jsonResponse) { - this.responseString = jsonResponse; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } - + private String responseString; + private boolean success; + + public String getJsonResponse() { + return responseString; + } + + public void setResponseString(String jsonResponse) { + this.responseString = jsonResponse; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + } 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 72f5d26..292ec94 100644 --- a/src/main/java/com/cribbstechnologies/clients/mandrill/model/ServiceMethods.java +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/ServiceMethods.java @@ -1,37 +1,100 @@ package com.cribbstechnologies.clients.mandrill.model; public class ServiceMethods { - - public class Users { - public static final String PING = "users/ping.json"; - public static final String INFO = "users/info.json"; - public static final String SENDERS = "users/senders.json"; - public static final String DISABLE_SENDER = "users/disable-sender.json"; - public static final String VERIFY_SENDER = "users/verify-sender.json"; - } - - public class Messages { + + public class Users { + + public static final String PING = "users/ping.json"; + public static final String INFO = "users/info.json"; + public static final String SENDERS = "users/senders.json"; + public static final String PING2 = "users/ping2.json"; + @Deprecated + public static final String DISABLE_SENDER = "users/disable-sender.json"; + @Deprecated + public static final String VERIFY_SENDER = "users/verify-sender.json"; + } + + public class Messages { + public static final String SEND = "messages/send.json"; public static final String SEND_TEMPLATE = "messages/send-template.json"; + public static final String SEARCH = "messages/search.json"; + public static final String PARSE = "messages/parse.json"; + public static final String SEND_RAW = "messages/send-raw.json"; + } + + public class Tags { + + public static final String LIST = "tags/list.json"; + public static final String DELETE = "tags/delete.json"; + public static final String INFO = "tags/info.json"; + public static final String TIME_SERIES = "tags/time-series.json"; + public static final String ALL_TIME_SERIES = "tags/all-time-series.json"; + } + + public class Rejects { + + public static final String ADD = "rejects/add.json"; + public static final String LIST = "rejects/list.json"; + public static final String DELETE = "rejects/delete.json"; + } + + public class Whitelists { + + public static final String ADD = "whitelists/add.json"; + public static final String LIST = "whitelists/list.json"; + public static final String DELETE = "whitelists/delete.json"; + } + + public class Senders { + + public static final String LIST = "senders/list.json"; + 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 class Urls { + + public static final String LIST = "urls/list.json"; + public static final String SEARCH = "urls/search.json"; + public static final String TIME_SERIES = "urls/time-series.json"; + } + + public class Templates { + + public static final String ADD = "templates/add.json"; + public static final String INFO = "templates/info.json"; + public static final String UPDATE = "templates/update.json"; + public static final String PUBLISH = "templates/publish.json"; + public static final String DELETE = "templates/delete.json"; + public static final String LIST = "templates/list.json"; + public static final String TIME_SERIES = "templates/time-series.json"; + public static final String RENDER = "templates/render.json"; + } + + public class Webhooks { + + public static final String LIST = "webhooks/list.json"; + public static final String ADD = "webhooks/add.json"; + public static final String INFO = "webhooks/info.json"; + public static final String UPDATE = "webhooks/update.json"; + public static final String DELETE = "webhooks/delete.json"; + } + + public class Inbound { + + public static final String DOMAINS = "inbound/domains.json"; + public static final String ROUTES = "inbound/routes.json"; + public static final String SEND_RAW = "inbound/send-raw.json"; + } + + public class Exports { + + public static final String INFO = "exports/info.json"; + public static final String LIST = "exports/list.json"; + public static final String REJECTS = "exports/rejects.json"; + public static final String WHITELIST = "exports/whitelist.json"; + public static final String ACTIVITY = "exports/activity.json"; } - - public class Tags { - public static final String LIST = "tags/list.json"; - public static final String TIME_SERIES = "tags/time-series.json"; - public static final String ALL_TIME_SERIES = "tags/all-time-series.json"; - } - - public class Urls { - public static final String LIST = "urls/list.json"; - public static final String SEARCH = "urls/search.json"; - public static final String TIME_SERIES = "urls/time-series.json"; - } - - public class Templates { - public static final String ADD = "templates/add.json"; - public static final String INFO = "templates/info.json"; - public static final String UPDATE = "templates/update.json"; - public static final String DELETE = "templates/delete.json"; - public static final String LIST = "templates/list.json"; - } } diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/message/MessageResponse.java b/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/message/MessageResponse.java index 0d237e4..91645ff 100644 --- a/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/message/MessageResponse.java +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/message/MessageResponse.java @@ -1,5 +1,7 @@ package com.cribbstechnologies.clients.mandrill.model.response.message; +import org.codehaus.jackson.annotate.JsonProperty; + import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse; public class MessageResponse extends BaseMandrillResponse { @@ -7,6 +9,7 @@ public class MessageResponse extends BaseMandrillResponse { String email; String status; String _id; + String rejectReason; public String getEmail() { return email; @@ -31,4 +34,13 @@ public String get_id() { public void set_id(String _id) { this._id = _id; } + + public String getRejectReason() { + return this.rejectReason; + } + + @JsonProperty("reject_reason") + public void setRejectReason(String rejectReason) { + this.rejectReason = rejectReason; + } } diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/users/PingResponse.java b/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/users/PingResponse.java new file mode 100644 index 0000000..1d05427 --- /dev/null +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/users/PingResponse.java @@ -0,0 +1,20 @@ +package com.cribbstechnologies.clients.mandrill.model.response.users; + +import org.codehaus.jackson.annotate.JsonProperty; + +import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse; + +public class PingResponse extends BaseMandrillResponse { + + @JsonProperty("PING") + public String pingResponse; + + public String getPingResponse() { + return pingResponse; + } + + public void setPingResponse(String pingResponse) { + this.pingResponse = pingResponse; + } + +} diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillMessagesRequest.java b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillMessagesRequest.java index f0b7d3d..98fdd6c 100644 --- a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillMessagesRequest.java +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillMessagesRequest.java @@ -14,33 +14,39 @@ /** * This class holds various functions for the Mandrill Messages API + * * @author Brian Cribbs - * + * */ public class MandrillMessagesRequest { - - MandrillRESTRequest request; - TypeReference> messageResponseListReference = new TypeReference>(){}; - - /** - * Send a new transactional message through Mandrill - * @param messageRequest a populated @see com.cribstechnologies.clients.mandrill.model.MandrillMessageRequest - * @throws RequestFailedException - */ - public SendMessageResponse sendMessage(MandrillMessageRequest messageRequest) throws RequestFailedException { - SendMessageResponse response = new SendMessageResponse(); - response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(messageRequest, ServiceMethods.Messages.SEND, SendMessageResponse.class, messageResponseListReference)).getList()); - return response; - } - - public SendMessageResponse sendTemplatedMessage(MandrillTemplatedMessageRequest templateMessage) throws RequestFailedException { - SendMessageResponse response = new SendMessageResponse(); - response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(templateMessage, ServiceMethods.Messages.SEND_TEMPLATE, SendMessageResponse.class, messageResponseListReference)).getList()); - return response; - } - - public void setRequest(MandrillRESTRequest request) { - this.request = request; - } - + + MandrillRESTRequest request; + TypeReference> messageResponseListReference = new TypeReference>() { + }; + + /** + * Send a new transactional message through Mandrill + * + * @param messageRequest + * a populated @see com.cribstechnologies.clients.mandrill.model.MandrillMessageRequest + * @throws RequestFailedException + */ + public SendMessageResponse sendMessage(MandrillMessageRequest messageRequest) throws RequestFailedException { + SendMessageResponse response = new SendMessageResponse(); + response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(messageRequest, ServiceMethods.Messages.SEND, SendMessageResponse.class, + messageResponseListReference)).getList()); + return response; + } + + public SendMessageResponse sendTemplatedMessage(MandrillTemplatedMessageRequest templateMessage) throws RequestFailedException { + SendMessageResponse response = new SendMessageResponse(); + response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(templateMessage, ServiceMethods.Messages.SEND_TEMPLATE, + SendMessageResponse.class, messageResponseListReference)).getList()); + return response; + } + + public void setRequest(MandrillRESTRequest request) { + this.request = request; + } + } diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillRESTRequest.java b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillRESTRequest.java index 5ff8f36..3b8e82d 100644 --- a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillRESTRequest.java +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillRESTRequest.java @@ -18,107 +18,113 @@ import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException; import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest; +import com.cribbstechnologies.clients.mandrill.model.ServiceMethods; import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse; import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse; import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillStringResponse; import com.cribbstechnologies.clients.mandrill.util.MandrillConfiguration; - + public class MandrillRESTRequest { - - private MandrillConfiguration config; - private HttpClient httpClient; - private ObjectMapper objectMapper; - - public BaseMandrillResponse postRequest(BaseMandrillRequest request, String serviceMethod, Object responseClass) throws RequestFailedException { - return performPostRequest(request, serviceMethod, responseClass, null); - } - - public BaseMandrillResponse postRequest(BaseMandrillRequest request, String serviceMethod, Object responseClass, TypeReference reference) throws RequestFailedException { - return performPostRequest(request, serviceMethod, responseClass, reference); - } - - private BaseMandrillResponse performPostRequest(BaseMandrillRequest request, String serviceMethod, Object responseClass, TypeReference reference) throws RequestFailedException { - try { - request.setKey(config.getApiKey()); - HttpPost postRequest = new HttpPost(config.getServiceUrl() + serviceMethod); - String postData = getPostData(request); - StringEntity input = new StringEntity(postData); - input.setContentType("application/json"); - postRequest.setEntity(input); - - HttpResponse response = httpClient.execute(postRequest); - - - BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); - - StringBuffer sb = new StringBuffer(); - String output; - //System.out.println("Output from Server .... \n"); - while ((output = br.readLine()) != null) { - sb.append(output); - //System.out.println(output); - } - - String responseString = sb.toString(); - if (response.getStatusLine().getStatusCode() != 200) { - throw new RequestFailedException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode() + " " + responseString); - } - - //for whatever reason the ping response isn't well-formed - if (responseString.indexOf("PONG!") > -1) { - return new BaseMandrillStringResponse(responseString); - } - - if (reference == null) { - return convertResponseData(responseString, responseClass); - } else { - return convertAnonymousListResponseData(responseString, responseClass, reference); - } - } catch (MalformedURLException mURLE) { - throw new RequestFailedException("Malformed url", mURLE); - } catch (JsonGenerationException jge) { - throw new RequestFailedException("Json Generation Exception", jge); - } catch (JsonMappingException jme) { - throw new RequestFailedException("Json Mapping Exception", jme); - } catch (IOException ioe) { - throw new RequestFailedException("IOException", ioe); - } - } - - /** - * This method will use the Jackson ObjectMapper to generate Mandrill API compatible JSON - * @param request one of @see com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest, @see com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail, @see com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithQuery, @see com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithTag, @see com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithUrl - * @return a JSON @see java.lang.String - * @throws IOException - * @throws JsonMappingException - * @throws JsonGenerationException - */ - protected String getPostData(BaseMandrillRequest request) throws JsonGenerationException, JsonMappingException, IOException { - return objectMapper.writeValueAsString(request); - } - - protected BaseMandrillResponse convertResponseData(String response, Object responseClass) throws JsonParseException, JsonMappingException, IOException { - return objectMapper.readValue(response, (Class)responseClass); - } - - protected BaseMandrillResponse convertAnonymousListResponseData(String json, Object responseClass, TypeReference reference) throws JsonParseException, JsonMappingException, IOException { - BaseMandrillAnonymousListResponse response = new BaseMandrillAnonymousListResponse(); - List objectList = objectMapper.readValue(json, reference); - response.setList(objectList); - return response; - } - - public void setConfig(MandrillConfiguration config) { - this.config = config; - } - - public void setHttpClient(HttpClient httpClient) { - this.httpClient = httpClient; - } - - public void setObjectMapper(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } - - + + private MandrillConfiguration config; + private HttpClient httpClient; + private ObjectMapper objectMapper; + + public BaseMandrillResponse postRequest(BaseMandrillRequest request, String serviceMethod, Object responseClass) throws RequestFailedException { + return performPostRequest(request, serviceMethod, responseClass, null); + } + + public BaseMandrillResponse postRequest(BaseMandrillRequest request, String serviceMethod, Object responseClass, TypeReference reference) throws RequestFailedException { + return performPostRequest(request, serviceMethod, responseClass, reference); + } + + private BaseMandrillResponse performPostRequest(BaseMandrillRequest request, String serviceMethod, Object responseClass, TypeReference reference) throws RequestFailedException { + try { + request.setKey(config.getApiKey()); + HttpPost postRequest = new HttpPost(config.getServiceUrl() + serviceMethod); + String postData = getPostData(request); + StringEntity input = new StringEntity(postData, "UTF-8"); + input.setContentType("application/json"); + postRequest.setEntity(input); + + HttpResponse response = httpClient.execute(postRequest); + + BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); + + StringBuffer sb = new StringBuffer(); + String output; + // System.out.println("Output from Server .... \n"); + while ((output = br.readLine()) != null) { + sb.append(output); + // System.out.println(output); + } + + String responseString = sb.toString(); + if (response.getStatusLine().getStatusCode() != 200) { + throw new RequestFailedException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode() + " " + responseString); + } + + // for whatever reason the ping response isn't well-formed + if (ServiceMethods.Users.PING.equals(serviceMethod) && responseString.indexOf("PONG!") > -1) { + return new BaseMandrillStringResponse(responseString); + } + + if (reference == null) { + return convertResponseData(responseString, responseClass); + } else { + return convertAnonymousListResponseData(responseString, responseClass, reference); + } + } catch (MalformedURLException mURLE) { + throw new RequestFailedException("Malformed url", mURLE); + } catch (JsonGenerationException jge) { + throw new RequestFailedException("Json Generation Exception", jge); + } catch (JsonMappingException jme) { + throw new RequestFailedException("Json Mapping Exception", jme); + } catch (IOException ioe) { + throw new RequestFailedException("IOException", ioe); + } + } + + /** + * This method will use the Jackson ObjectMapper to generate Mandrill API compatible JSON + * + * @param request + * one of @see com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest, @see + * com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail, @see + * com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithQuery, @see + * com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithTag, @see + * com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithUrl + * @return a JSON @see java.lang.String + * @throws IOException + * @throws JsonMappingException + * @throws JsonGenerationException + */ + protected String getPostData(BaseMandrillRequest request) throws JsonGenerationException, JsonMappingException, IOException { + return objectMapper.writeValueAsString(request); + } + + protected BaseMandrillResponse convertResponseData(String response, Object responseClass) throws JsonParseException, JsonMappingException, IOException { + return objectMapper.readValue(response, (Class) responseClass); + } + + protected BaseMandrillResponse convertAnonymousListResponseData(String json, Object responseClass, TypeReference reference) throws JsonParseException, JsonMappingException, + IOException { + BaseMandrillAnonymousListResponse response = new BaseMandrillAnonymousListResponse(); + List objectList = objectMapper.readValue(json, reference); + response.setList(objectList); + return response; + } + + public void setConfig(MandrillConfiguration config) { + this.config = config; + } + + public void setHttpClient(HttpClient httpClient) { + this.httpClient = httpClient; + } + + public void setObjectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + } diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillTagsRequest.java b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillTagsRequest.java index 0b3bd80..0a5d51f 100644 --- a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillTagsRequest.java +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillTagsRequest.java @@ -15,31 +15,36 @@ import com.cribbstechnologies.clients.mandrill.model.response.tags.TagWithTime; public class MandrillTagsRequest { - - MandrillRESTRequest request; - - TypeReference> timeTagReference = new TypeReference>(){}; - TypeReference> nameTagReference = new TypeReference>(){}; - - public TagListResponse getList(BaseMandrillRequest tagsRequest) throws RequestFailedException { - TagListResponse response = new TagListResponse(); - response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(tagsRequest, ServiceMethods.Tags.LIST, TagListResponse.class, nameTagReference)).getList()); - return response; - } - - public TagSeriesResponse getTimeSeries(MandrillRequestWithTag tagsRequest) throws RequestFailedException { - TagSeriesResponse response = new TagSeriesResponse(); - response.setList(((BaseMandrillAnonymousListResponse)request.postRequest(tagsRequest, ServiceMethods.Tags.TIME_SERIES, TagSeriesResponse.class, timeTagReference)).getList()); - return response; - } - - public TagSeriesResponse getAllTimeSeries(BaseMandrillRequest tagsRequest) throws RequestFailedException { - TagSeriesResponse response = new TagSeriesResponse(); - response.setList(((BaseMandrillAnonymousListResponse)request.postRequest(tagsRequest, ServiceMethods.Tags.ALL_TIME_SERIES, TagSeriesResponse.class, timeTagReference)).getList()); - return response; - } - - public void setRequest(MandrillRESTRequest request) { - this.request = request; - } + + MandrillRESTRequest request; + + TypeReference> timeTagReference = new TypeReference>() { + }; + TypeReference> nameTagReference = new TypeReference>() { + }; + + public TagListResponse getList(BaseMandrillRequest tagsRequest) throws RequestFailedException { + TagListResponse response = new TagListResponse(); + response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(tagsRequest, ServiceMethods.Tags.LIST, TagListResponse.class, nameTagReference)) + .getList()); + return response; + } + + public TagSeriesResponse getTimeSeries(MandrillRequestWithTag tagsRequest) throws RequestFailedException { + TagSeriesResponse response = new TagSeriesResponse(); + response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(tagsRequest, ServiceMethods.Tags.TIME_SERIES, TagSeriesResponse.class, + timeTagReference)).getList()); + return response; + } + + public TagSeriesResponse getAllTimeSeries(BaseMandrillRequest tagsRequest) throws RequestFailedException { + TagSeriesResponse response = new TagSeriesResponse(); + response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(tagsRequest, ServiceMethods.Tags.ALL_TIME_SERIES, TagSeriesResponse.class, + timeTagReference)).getList()); + return response; + } + + public void setRequest(MandrillRESTRequest request) { + this.request = request; + } } diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillTemplatesRequest.java b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillTemplatesRequest.java index 013171d..3a8bdcb 100644 --- a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillTemplatesRequest.java +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillTemplatesRequest.java @@ -14,35 +14,37 @@ import com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse; public class MandrillTemplatesRequest { - - MandrillRESTRequest request; - - TypeReference> templatesListReference = new TypeReference>(){}; - - public TemplateResponse addTemplate(MandrillRequestWithCode addRequest) throws RequestFailedException { - return (TemplateResponse) request.postRequest(addRequest, ServiceMethods.Templates.ADD, TemplateResponse.class); - } - - public TemplateResponse getTemplateInfo(MandrillRequestWithName infoRequest) throws RequestFailedException { - return (TemplateResponse) request.postRequest(infoRequest, ServiceMethods.Templates.INFO, TemplateResponse.class); - } - - public TemplateResponse updateTemplate(MandrillRequestWithCode updateRequest) throws RequestFailedException { - return (TemplateResponse) request.postRequest(updateRequest, ServiceMethods.Templates.UPDATE, TemplateResponse.class); - } - - public TemplateResponse deleteTemplate(MandrillRequestWithName deleteRequest) throws RequestFailedException { - return (TemplateResponse) request.postRequest(deleteRequest, ServiceMethods.Templates.DELETE, TemplateResponse.class); - } - - public TemplateListResponse getTemplates(BaseMandrillRequest listRequest) throws RequestFailedException { - TemplateListResponse response = new TemplateListResponse(); - response.setList(((BaseMandrillAnonymousListResponse)request.postRequest(listRequest, ServiceMethods.Templates.LIST, TemplateResponse.class, templatesListReference)).getList()); - return response; - } - - public void setRequest(MandrillRESTRequest request) { - this.request = request; - } + + MandrillRESTRequest request; + + TypeReference> templatesListReference = new TypeReference>() { + }; + + public TemplateResponse addTemplate(MandrillRequestWithCode addRequest) throws RequestFailedException { + return (TemplateResponse) request.postRequest(addRequest, ServiceMethods.Templates.ADD, TemplateResponse.class); + } + + public TemplateResponse getTemplateInfo(MandrillRequestWithName infoRequest) throws RequestFailedException { + return (TemplateResponse) request.postRequest(infoRequest, ServiceMethods.Templates.INFO, TemplateResponse.class); + } + + public TemplateResponse updateTemplate(MandrillRequestWithCode updateRequest) throws RequestFailedException { + return (TemplateResponse) request.postRequest(updateRequest, ServiceMethods.Templates.UPDATE, TemplateResponse.class); + } + + public TemplateResponse deleteTemplate(MandrillRequestWithName deleteRequest) throws RequestFailedException { + return (TemplateResponse) request.postRequest(deleteRequest, ServiceMethods.Templates.DELETE, TemplateResponse.class); + } + + public TemplateListResponse getTemplates(BaseMandrillRequest listRequest) throws RequestFailedException { + TemplateListResponse response = new TemplateListResponse(); + response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(listRequest, ServiceMethods.Templates.LIST, TemplateResponse.class, + templatesListReference)).getList()); + return response; + } + + public void setRequest(MandrillRESTRequest request) { + this.request = request; + } } diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillUrlsRequest.java b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillUrlsRequest.java index f218de3..f32306f 100644 --- a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillUrlsRequest.java +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillUrlsRequest.java @@ -15,30 +15,34 @@ public class MandrillUrlsRequest { - MandrillRESTRequest request; - - TypeReference> urlsListReference = new TypeReference>(){}; - - public UrlListResponse getList(BaseMandrillRequest listRequest) throws RequestFailedException { - UrlListResponse response = new UrlListResponse(); - response.setList(((BaseMandrillAnonymousListResponse)request.postRequest(listRequest, ServiceMethods.Urls.LIST, UrlListResponse.class, urlsListReference)).getList()); - return response; - } - - public UrlListResponse doSearch(MandrillRequestWithQuery searchRequest) throws RequestFailedException { - UrlListResponse response = new UrlListResponse(); - response.setList(((BaseMandrillAnonymousListResponse)request.postRequest(searchRequest, ServiceMethods.Urls.SEARCH, UrlListResponse.class, urlsListReference)).getList()); - return response; - } - - public UrlListResponse getTimeSeries(MandrillRequestWithUrl seriesRequest) throws RequestFailedException { - UrlListResponse response = new UrlListResponse(); - response.setList(((BaseMandrillAnonymousListResponse)request.postRequest(seriesRequest, ServiceMethods.Urls.TIME_SERIES, UrlListResponse.class, urlsListReference)).getList()); - return response; - } - - public void setRequest(MandrillRESTRequest request) { - this.request = request; - } - + MandrillRESTRequest request; + + TypeReference> urlsListReference = new TypeReference>() { + }; + + public UrlListResponse getList(BaseMandrillRequest listRequest) throws RequestFailedException { + UrlListResponse response = new UrlListResponse(); + response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(listRequest, ServiceMethods.Urls.LIST, UrlListResponse.class, urlsListReference)) + .getList()); + return response; + } + + public UrlListResponse doSearch(MandrillRequestWithQuery searchRequest) throws RequestFailedException { + UrlListResponse response = new UrlListResponse(); + response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(searchRequest, ServiceMethods.Urls.SEARCH, UrlListResponse.class, urlsListReference)) + .getList()); + return response; + } + + public UrlListResponse getTimeSeries(MandrillRequestWithUrl seriesRequest) throws RequestFailedException { + UrlListResponse response = new UrlListResponse(); + response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(seriesRequest, ServiceMethods.Urls.TIME_SERIES, UrlListResponse.class, + urlsListReference)).getList()); + return response; + } + + public void setRequest(MandrillRESTRequest request) { + this.request = request; + } + } diff --git a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillUsersRequest.java b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillUsersRequest.java index 977db39..a7e9abe 100644 --- a/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillUsersRequest.java +++ b/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillUsersRequest.java @@ -14,6 +14,7 @@ import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillStringResponse; import com.cribbstechnologies.clients.mandrill.model.response.users.DisableResponse; import com.cribbstechnologies.clients.mandrill.model.response.users.MandrillSender; +import com.cribbstechnologies.clients.mandrill.model.response.users.PingResponse; import com.cribbstechnologies.clients.mandrill.model.response.users.UsersInfoResponse; import com.cribbstechnologies.clients.mandrill.model.response.users.UsersSendersResponse; import com.cribbstechnologies.clients.mandrill.model.response.users.VerifyResponse; @@ -23,68 +24,95 @@ * This class holds various functions for the Mandrill Users API. * * @author Brian Cribbs, brian@cribbstechnologies.com - * + * */ public class MandrillUsersRequest { - - MandrillRESTRequest request; - TypeReference> usersListReference = new TypeReference>(){}; - /** - * Return the information about the API-connected user - * @param infoRequest a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest - * @throws RequestFailedException - */ - public UsersInfoResponse getInfo(BaseMandrillRequest infoRequest) throws RequestFailedException { - BaseMandrillResponse response = request.postRequest(infoRequest, ServiceMethods.Users.INFO, UsersInfoResponse.class); - return (UsersInfoResponse) response; - } - - /** - * Validate an API key and respond to a ping - * @param pingRequest a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest - * @throws RequestFailedException - */ - public BaseMandrillStringResponse performPing(BaseMandrillRequest pingRequest) throws RequestFailedException { - BaseMandrillStringResponse response = (BaseMandrillStringResponse) request.postRequest(pingRequest, ServiceMethods.Users.PING, null); - return response; - } - - /** - * Return the senders that have tried to use this account, both verified and unverified - * @param sendersRequest a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest - * @throws RequestFailedException - */ - public UsersSendersResponse getSenders(BaseMandrillRequest sendersRequest) throws RequestFailedException { - UsersSendersResponse response = new UsersSendersResponse(); - response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(sendersRequest, ServiceMethods.Users.SENDERS, UsersSendersResponse.class, usersListReference)).getList()); - return response; - } - - /** - * Disable a sender from being able to send - * @param disableRequest a populated @see com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail - * @throws RequestFailedException - */ - public DisableResponse disableSender(MandrillRequestWithDomain disableRequest) throws RequestFailedException { - return (DisableResponse) request.postRequest(disableRequest, ServiceMethods.Users.DISABLE_SENDER, DisableResponse.class); - } - - /** - * Send an email to the given address to verify that it is an accepted sender for your Mandrill account - * @param verifyRequest a populated @see com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail - * @throws RequestFailedException - */ - public VerifyResponse verifySender(MandrillRequestWithEmail verifyRequest) throws RequestFailedException { - return (VerifyResponse)request.postRequest(verifyRequest, ServiceMethods.Users.VERIFY_SENDER, VerifyResponse.class); - } + MandrillRESTRequest request; + + TypeReference> usersListReference = new TypeReference>() { + }; + + /** + * Return the information about the API-connected user + * + * @param infoRequest + * a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest + * @throws RequestFailedException + */ + public UsersInfoResponse getInfo(BaseMandrillRequest infoRequest) throws RequestFailedException { + BaseMandrillResponse response = request.postRequest(infoRequest, ServiceMethods.Users.INFO, UsersInfoResponse.class); + return (UsersInfoResponse) response; + } + + /** + * Validate an API key and respond to a ping + * + * @param pingRequest + * a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest + * @throws RequestFailedException + */ + public BaseMandrillStringResponse performPing(BaseMandrillRequest pingRequest) throws RequestFailedException { + BaseMandrillStringResponse response = (BaseMandrillStringResponse) request.postRequest(pingRequest, ServiceMethods.Users.PING, null); + return response; + } + + /** + * Validate an API key and respond to a ping, this uses actually formatted JSON response + * + * @param pingRequest + * a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest + * @throws RequestFailedException + */ + public PingResponse performPing2(BaseMandrillRequest pingRequest) throws RequestFailedException { + PingResponse response = (PingResponse) request.postRequest(pingRequest, ServiceMethods.Users.PING2, null); + return response; + } + + /** + * Return the senders that have tried to use this account, both verified and unverified + * + * @param sendersRequest + * a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest + * @throws RequestFailedException + */ + public UsersSendersResponse getSenders(BaseMandrillRequest sendersRequest) throws RequestFailedException { + UsersSendersResponse response = new UsersSendersResponse(); + response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(sendersRequest, ServiceMethods.Users.SENDERS, UsersSendersResponse.class, + usersListReference)).getList()); + return response; + } + + /** + * Disable a sender from being able to send + * + * @param disableRequest + * a populated @see com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail + * @throws RequestFailedException + */ + @Deprecated + public DisableResponse disableSender(MandrillRequestWithDomain disableRequest) throws RequestFailedException { + return (DisableResponse) request.postRequest(disableRequest, ServiceMethods.Users.DISABLE_SENDER, DisableResponse.class); + } + + /** + * Send an email to the given address to verify that it is an accepted sender for your Mandrill account + * + * @param verifyRequest + * a populated @see com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail + * @throws RequestFailedException + */ + @Deprecated + public VerifyResponse verifySender(MandrillRequestWithEmail verifyRequest) throws RequestFailedException { + return (VerifyResponse) request.postRequest(verifyRequest, ServiceMethods.Users.VERIFY_SENDER, VerifyResponse.class); + } + + public void setRequest(MandrillRESTRequest request) { + this.request = request; + } - public void setRequest(MandrillRESTRequest request) { - this.request = request; - } + public TypeReference> getUsersListReference() { + return usersListReference; + } - public TypeReference> getUsersListReference() { - return usersListReference; - } - } 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