├── .gitignore
├── README.txt
├── pom.xml
└── src
├── it
└── java
│ └── com
│ └── cribbstechnologies
│ └── clients
│ └── mandrill
│ └── it
│ ├── MessagesTest.java
│ ├── TagsTest.java
│ ├── TemplatesTest.java
│ ├── UrlsTest.java
│ └── UsersTest.java
├── main
├── java
│ └── com
│ │ └── cribbstechnologies
│ │ └── clients
│ │ └── mandrill
│ │ ├── exception
│ │ └── RequestFailedException.java
│ │ ├── model
│ │ ├── BaseMandrillRequest.java
│ │ ├── MandrillAttachment.java
│ │ ├── MandrillError.java
│ │ ├── MandrillHtmlMessage.java
│ │ ├── MandrillMessage.java
│ │ ├── MandrillMessageInfoRequest.java
│ │ ├── MandrillMessageRequest.java
│ │ ├── MandrillRecipient.java
│ │ ├── MandrillRequestWithCode.java
│ │ ├── MandrillRequestWithDomain.java
│ │ ├── MandrillRequestWithEmail.java
│ │ ├── MandrillRequestWithName.java
│ │ ├── MandrillRequestWithQuery.java
│ │ ├── MandrillRequestWithTag.java
│ │ ├── MandrillRequestWithUrl.java
│ │ ├── MandrillResponse.java
│ │ ├── MandrillTemplatedMessageRequest.java
│ │ ├── MergeVar.java
│ │ ├── MessageMergeVars.java
│ │ ├── ServiceMethods.java
│ │ ├── TemplateContent.java
│ │ └── response
│ │ │ ├── BaseMandrillAnonymousListResponse.java
│ │ │ ├── BaseMandrillResponse.java
│ │ │ ├── BaseMandrillStringResponse.java
│ │ │ ├── StatsResponse.java
│ │ │ ├── StatsResponseMap.java
│ │ │ ├── message
│ │ │ ├── MessageInfoClicksDetail.java
│ │ │ ├── MessageInfoOpensDetail.java
│ │ │ ├── MessageInfoResponse.java
│ │ │ ├── MessageInfoSmtpEvents.java
│ │ │ ├── MessageResponse.java
│ │ │ └── SendMessageResponse.java
│ │ │ ├── tags
│ │ │ ├── BaseTag.java
│ │ │ ├── TagListResponse.java
│ │ │ ├── TagSeriesResponse.java
│ │ │ └── TagWithTime.java
│ │ │ ├── templates
│ │ │ ├── TemplateListResponse.java
│ │ │ ├── TemplateRenderResponse.java
│ │ │ └── TemplateResponse.java
│ │ │ ├── urls
│ │ │ ├── BaseUrlResponse.java
│ │ │ ├── TimeUrlResponse.java
│ │ │ ├── UrlListResponse.java
│ │ │ ├── UrlResponse.java
│ │ │ └── UrlTimeResponse.java
│ │ │ └── users
│ │ │ ├── DisableResponse.java
│ │ │ ├── MandrillSender.java
│ │ │ ├── PingResponse.java
│ │ │ ├── UsersInfoResponse.java
│ │ │ ├── UsersSendersResponse.java
│ │ │ └── VerifyResponse.java
│ │ ├── request
│ │ ├── MandrillMessagesRequest.java
│ │ ├── MandrillRESTRequest.java
│ │ ├── MandrillTagsRequest.java
│ │ ├── MandrillTemplatesRequest.java
│ │ ├── MandrillUrlsRequest.java
│ │ └── MandrillUsersRequest.java
│ │ └── util
│ │ ├── MandrillConfiguration.java
│ │ └── MandrillSimpleDateFormat.java
└── resources
│ └── spring
│ └── mandrillConfig.xml
└── test
├── java
└── com
│ └── cribbstechnologies
│ └── clients
│ └── mandrill
│ ├── request
│ ├── MandrillRESTRequestTest.java
│ └── MandrillUsersRequestTest.java
│ └── util
│ ├── MandrillConfigurationTest.java
│ └── MandrillSimpleDateFormatTest.java
└── resources
├── mandrill.properties
├── messages
└── sendMessageResponse.txt
├── tags
├── allTimeSeriesResponse.txt
├── listResponse.txt
└── timeSeriesResponse.txt
├── templates
├── templateResponse.txt
└── templatesListResponse.txt
├── urls
├── urlList.txt
└── urlTimeResponse.txt
└── users
├── disableSenderResponse.txt
├── infoResponse.txt
├── pingResponse.txt
├── sendersResponse.txt
└── verifySenderResponse.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | # Eclipse
2 | .classpath
3 | .project
4 | .settings/
5 |
6 | # Intellij
7 | .idea/
8 | *.iml
9 | *.iws
10 |
11 | # Mac
12 | .DS_Store
13 |
14 | # Maven
15 | log/
16 | target/
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | For example usage, see the integration tests in src/it/java. You'll need to create a file called mandrill.properties
2 | and put it somewhere on the classpath. It'll need the following properties.
3 |
4 | apiKey=
5 | email.from=
6 | email.to.name1=
7 | email.to.address1=
8 | email.to.name2=
9 | email.to.address2=
10 | verify.email=
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 |
6 |
7 |
8 |
9 | com.cribbstechnologies.clients
10 | mandrillClient
11 | 1.0.2
12 | jar
13 | Java Mandrill Wrapper
14 | A Java wrapper for Mandrill
15 | https://github.com/cribbstechnologies/Java-Mandrill-Wrapper
16 |
17 |
18 |
19 | Brian Cribbs
20 | Cribbs Technologies
21 | http://www.cribbstechnologies.com/
22 | brian@cribbstechnologies.com
23 |
24 | Committer
25 |
26 |
27 |
28 |
29 |
30 | scm:git:git@github.com:cribbstechnologies/Java-Mandrill-Wrapper.git
31 | scm:git:git@github.com:cribbstechnologies/Java-Mandrill-Wrapper.git
32 | scm:git:git@github.com:cribbstechnologies/Java-Mandrill-Wrapper.git
33 |
34 |
35 |
36 |
37 |
38 | org.apache.httpcomponents
39 | httpclient
40 | 4.3
41 |
42 |
43 | junit
44 | junit
45 | 4.10
46 | test
47 |
48 |
49 |
50 |
51 |
52 | com.fasterxml.jackson.core
53 | jackson-core
54 | 2.2.3
55 |
56 |
57 |
58 | com.fasterxml.jackson.core
59 | jackson-annotations
60 | 2.2.3
61 |
62 |
63 |
64 | com.fasterxml.jackson.core
65 | jackson-databind
66 | 2.2.3
67 |
68 |
69 |
70 |
71 | org.mockito
72 | mockito-all
73 | 1.8.4
74 | test
75 |
76 |
77 | commons-io
78 | commons-io
79 | 2.0
80 | test
81 |
82 |
83 |
84 |
85 |
86 |
87 | org.sonatype.oss
88 | oss-parent
89 | 7
90 |
91 |
92 |
93 |
94 |
95 |
96 | org.apache.maven.plugins
97 | maven-compiler-plugin
98 | 2.3.2
99 |
100 | 1.5
101 | 1.5
102 |
103 |
104 |
105 | org.apache.maven.plugins
106 | maven-gpg-plugin
107 |
108 |
109 | sign-artifacts
110 | verify
111 |
112 | sign
113 |
114 |
115 |
116 |
117 |
118 | org.apache.maven.plugins
119 | maven-source-plugin
120 |
121 |
122 | attach-sources
123 |
124 | jar
125 |
126 |
127 |
128 |
129 |
130 | org.apache.maven.plugins
131 | maven-javadoc-plugin
132 |
133 |
134 | attach-javadocs
135 |
136 | jar
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 | Apache License, Version 2.0
147 | http://www.apache.org/licenses/LICENSE-2.0.txt
148 | repo
149 | A business-friendly OSS license
150 |
151 |
152 |
153 |
--------------------------------------------------------------------------------
/src/it/java/com/cribbstechnologies/clients/mandrill/it/MessagesTest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.it;
2 |
3 | import static org.junit.Assert.fail;
4 |
5 | import java.io.IOException;
6 | import java.util.ArrayList;
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.Properties;
11 |
12 | import org.apache.http.client.HttpClient;
13 | import org.apache.http.impl.client.DefaultHttpClient;
14 | import org.junit.Before;
15 | import org.junit.BeforeClass;
16 | import org.junit.Test;
17 |
18 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
19 | import com.cribbstechnologies.clients.mandrill.model.MandrillHtmlMessage;
20 | import com.cribbstechnologies.clients.mandrill.model.MandrillMessage;
21 | import com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest;
22 | import com.cribbstechnologies.clients.mandrill.model.MandrillRecipient;
23 | import com.cribbstechnologies.clients.mandrill.model.MandrillTemplatedMessageRequest;
24 | import com.cribbstechnologies.clients.mandrill.model.MergeVar;
25 | import com.cribbstechnologies.clients.mandrill.model.TemplateContent;
26 | import com.cribbstechnologies.clients.mandrill.model.response.message.SendMessageResponse;
27 | import com.cribbstechnologies.clients.mandrill.request.MandrillMessagesRequest;
28 | import com.cribbstechnologies.clients.mandrill.request.MandrillRESTRequest;
29 | import com.cribbstechnologies.clients.mandrill.util.MandrillConfiguration;
30 | import com.fasterxml.jackson.databind.ObjectMapper;
31 |
32 | public class MessagesTest {
33 |
34 | private static MandrillRESTRequest request = new MandrillRESTRequest();
35 | private static MandrillConfiguration config = new MandrillConfiguration();
36 | private static MandrillMessagesRequest messagesRequest = new MandrillMessagesRequest();
37 | private static HttpClient client;
38 | private static ObjectMapper mapper = new ObjectMapper();
39 | private static Properties props = new Properties();
40 |
41 | @BeforeClass
42 | public static void beforeClass() {
43 | try {
44 | props.load(MessagesTest.class.getClassLoader().getResourceAsStream("mandrill.properties"));
45 | } catch (IOException e) {
46 | fail ("properties file not loaded");
47 | }
48 | config.setApiKey(props.getProperty("apiKey"));
49 | config.setApiVersion("1.0");
50 | config.setBaseURL("https://mandrillapp.com/api");
51 | request.setConfig(config);
52 | request.setObjectMapper(mapper);
53 | messagesRequest.setRequest(request);
54 | }
55 |
56 | @Before
57 | public void before() {
58 | client = new DefaultHttpClient();
59 | request.setHttpClient(client);
60 | }
61 |
62 | @Test
63 | public void testSendMessage() {
64 | MandrillMessageRequest mmr = new MandrillMessageRequest();
65 | MandrillHtmlMessage message = new MandrillHtmlMessage();
66 | Map headers = new HashMap();
67 | message.setFrom_email(props.getProperty("email.from"));
68 | message.setFrom_name("Big Jimmy");
69 | message.setHeaders(headers);
70 | message.setHtml("Oh snap!
Guess what I saw?google");
71 | message.setSubject("This is the subject");
72 | MandrillRecipient[] recipients = new MandrillRecipient[]{new MandrillRecipient(props.getProperty("email.to.name1"), props.getProperty("email.to.address1")), new MandrillRecipient(props.getProperty("email.to.name2"), props.getProperty("email.to.address2"))};
73 | message.setTo(recipients);
74 | message.setTrack_clicks(true);
75 | message.setTrack_opens(true);
76 | String[] tags = new String[]{"tag1", "tag2", "tag3"};
77 | message.setTags(tags);
78 | mmr.setMessage(message);
79 |
80 | try {
81 | SendMessageResponse response = messagesRequest.sendMessage(mmr);
82 | } catch (RequestFailedException e) {
83 | e.printStackTrace();
84 | fail(e.getMessage());
85 | }
86 | }
87 |
88 | @Test
89 | public void testSendTemplatedMessage() {
90 | MandrillTemplatedMessageRequest request = new MandrillTemplatedMessageRequest();
91 | MandrillMessage message = new MandrillMessage();
92 | Map headers = new HashMap();
93 | message.setFrom_email(props.getProperty("email.from"));
94 | message.setFrom_name("Big Jimmy");
95 | message.setHeaders(headers);
96 | message.setSubject("This is the subject");
97 | MandrillRecipient[] recipients = new MandrillRecipient[]{new MandrillRecipient(props.getProperty("email.to.name1"), props.getProperty("email.to.address1")), new MandrillRecipient(props.getProperty("email.to.name2"), props.getProperty("email.to.address2"))};
98 | message.setTo(recipients);
99 | message.setTrack_clicks(true);
100 | message.setTrack_opens(true);
101 | String[] tags = new String[]{"tag1", "tag2", "tag3"};
102 | message.setTags(tags);
103 | request.setMessage(message);
104 | List content = new ArrayList();
105 | request.setTemplate_content(content);
106 | request.setTemplate_name("template2");
107 | List globalMergeVars = new ArrayList();
108 | globalMergeVars.add(new MergeVar("username", "bcribs"));
109 | globalMergeVars.add(new MergeVar("registration_url", "http://myserver.com/register?userid=bcribs"));
110 | message.setGlobal_merge_vars(globalMergeVars);
111 |
112 | try {
113 | messagesRequest.sendTemplatedMessage(request);
114 | } catch (RequestFailedException e) {
115 | e.printStackTrace();
116 | fail(e.getMessage());
117 | }
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/src/it/java/com/cribbstechnologies/clients/mandrill/it/TagsTest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.it;
2 |
3 | import static org.junit.Assert.fail;
4 |
5 | import java.io.IOException;
6 | import java.util.Properties;
7 |
8 | import org.apache.http.client.HttpClient;
9 | import org.apache.http.impl.client.DefaultHttpClient;
10 | import org.junit.Before;
11 | import org.junit.BeforeClass;
12 | import org.junit.Test;
13 |
14 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
15 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
16 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithTag;
17 | import com.cribbstechnologies.clients.mandrill.model.response.tags.TagListResponse;
18 | import com.cribbstechnologies.clients.mandrill.model.response.tags.TagSeriesResponse;
19 | import com.cribbstechnologies.clients.mandrill.request.MandrillRESTRequest;
20 | import com.cribbstechnologies.clients.mandrill.request.MandrillTagsRequest;
21 | import com.cribbstechnologies.clients.mandrill.util.MandrillConfiguration;
22 | import com.fasterxml.jackson.databind.ObjectMapper;
23 |
24 | public class TagsTest {
25 |
26 | private static MandrillRESTRequest request = new MandrillRESTRequest();
27 | private static MandrillConfiguration config = new MandrillConfiguration();
28 | private static MandrillTagsRequest tagsRequest = new MandrillTagsRequest();
29 | private static HttpClient client;
30 | private static ObjectMapper mapper = new ObjectMapper();
31 |
32 | @BeforeClass
33 | public static void beforeClass() {
34 | Properties props = new Properties();
35 | try {
36 | props.load(TagsTest.class.getClassLoader().getResourceAsStream("mandrill.properties"));
37 | } catch (IOException e) {
38 | fail ("properties file not loaded");
39 | }
40 | config.setApiKey(props.getProperty("apiKey"));
41 | config.setApiVersion("1.0");
42 | config.setBaseURL("https://mandrillapp.com/api");
43 | request.setConfig(config);
44 | request.setObjectMapper(mapper);
45 | tagsRequest.setRequest(request);
46 | }
47 |
48 | @Before
49 | public void before() {
50 | client = new DefaultHttpClient();
51 | request.setHttpClient(client);
52 | }
53 |
54 | @Test
55 | public void testGetList() {
56 | BaseMandrillRequest request = new BaseMandrillRequest();
57 | try {
58 | TagListResponse response = tagsRequest.getList(request);
59 | } catch (RequestFailedException e) {
60 | e.printStackTrace();
61 | fail(e.getMessage());
62 | }
63 | }
64 |
65 | @Test
66 | public void testGetAllTimeSeries() {
67 | BaseMandrillRequest request = new BaseMandrillRequest();
68 | try {
69 | TagSeriesResponse response = tagsRequest.getAllTimeSeries(request);
70 | } catch (RequestFailedException e) {
71 | e.printStackTrace();
72 | fail(e.getMessage());
73 | }
74 | }
75 |
76 | @Test
77 | public void testGetTimeSeries() {
78 | MandrillRequestWithTag request = new MandrillRequestWithTag();
79 | request.setTag("tag1");
80 | try {
81 | TagSeriesResponse response = tagsRequest.getTimeSeries(request);
82 | } catch (RequestFailedException e) {
83 | e.printStackTrace();
84 | fail(e.getMessage());
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/it/java/com/cribbstechnologies/clients/mandrill/it/TemplatesTest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.it;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.fail;
6 |
7 | import java.io.IOException;
8 | import java.util.Properties;
9 |
10 | import org.apache.http.client.HttpClient;
11 | import org.apache.http.impl.client.DefaultHttpClient;
12 | import org.junit.Before;
13 | import org.junit.BeforeClass;
14 | import org.junit.Test;
15 |
16 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
17 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
18 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithCode;
19 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithName;
20 | import com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse;
21 | import com.cribbstechnologies.clients.mandrill.request.MandrillRESTRequest;
22 | import com.cribbstechnologies.clients.mandrill.request.MandrillTemplatesRequest;
23 | import com.cribbstechnologies.clients.mandrill.util.MandrillConfiguration;
24 | import com.fasterxml.jackson.databind.ObjectMapper;
25 |
26 | public class TemplatesTest {
27 |
28 | private static MandrillRESTRequest request = new MandrillRESTRequest();
29 | private static MandrillConfiguration config = new MandrillConfiguration();
30 | private static MandrillTemplatesRequest templatesRequest = new MandrillTemplatesRequest();
31 | private static HttpClient client;
32 | private static ObjectMapper mapper = new ObjectMapper();
33 |
34 | @BeforeClass
35 | public static void beforeClass() {
36 | Properties props = new Properties();
37 | try {
38 | props.load(TemplatesTest.class.getClassLoader().getResourceAsStream("mandrill.properties"));
39 | } catch (IOException e) {
40 | fail ("properties file not loaded");
41 | }
42 | config.setApiKey(props.getProperty("apiKey"));
43 | config.setApiVersion("1.0");
44 | config.setBaseURL("https://mandrillapp.com/api");
45 | request.setConfig(config);
46 | request.setObjectMapper(mapper);
47 | templatesRequest.setRequest(request);
48 | }
49 |
50 | @Before
51 | public void before() {
52 | client = new DefaultHttpClient();
53 | request.setHttpClient(client);
54 | }
55 |
56 | @Test
57 | public void testGetList() {
58 | BaseMandrillRequest listRequest = new BaseMandrillRequest();
59 | try {
60 | templatesRequest.getTemplates(listRequest);
61 | } catch (RequestFailedException e) {
62 | e.printStackTrace();
63 | fail(e.getMessage());
64 | }
65 | }
66 |
67 | @Test
68 | public void testAddTemplate() {
69 | MandrillRequestWithCode request = new MandrillRequestWithCode();
70 | request.setCode("template");
71 | request.setName("template1");
72 | try {
73 | templatesRequest.addTemplate(request);
74 | } catch (RequestFailedException e) {
75 | e.printStackTrace();
76 | fail(e.getMessage());
77 | }
78 | }
79 |
80 | @Test
81 | public void testGetTemplateInfo() {
82 | MandrillRequestWithName request = new MandrillRequestWithName();
83 | request.setName("template1");
84 | try {
85 | templatesRequest.getTemplateInfo(request);
86 | } catch (RequestFailedException e) {
87 | e.printStackTrace();
88 | fail(e.getMessage());
89 | }
90 | }
91 |
92 | @Test
93 | public void testUpdateTemplate() {
94 | MandrillRequestWithCode request = new MandrillRequestWithCode();
95 | request.setName("template1");
96 | String newVal = "Not template";
97 | request.setCode(newVal);
98 | MandrillRequestWithName retrieve = new MandrillRequestWithName();
99 | retrieve.setName("template1");
100 |
101 | try {
102 | TemplateResponse response = templatesRequest.getTemplateInfo(retrieve);
103 | String oldVal = response.getCode();
104 | templatesRequest.updateTemplate(request);
105 | response = templatesRequest.getTemplateInfo(retrieve);
106 | assertFalse(oldVal.equals(newVal));
107 | assertEquals(newVal, response.getCode());
108 | } catch (RequestFailedException e) {
109 | e.printStackTrace();
110 | fail(e.getMessage());
111 | }
112 |
113 | }
114 |
115 | @Test
116 | public void deleteTemplate() {
117 | MandrillRequestWithName request = new MandrillRequestWithName();
118 | request.setName("template1");
119 | try {
120 | templatesRequest.deleteTemplate(request);
121 | } catch (RequestFailedException e) {
122 | e.printStackTrace();
123 | fail(e.getMessage());
124 | }
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/src/it/java/com/cribbstechnologies/clients/mandrill/it/UrlsTest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.it;
2 |
3 | import static org.junit.Assert.fail;
4 |
5 | import java.io.IOException;
6 | import java.util.Properties;
7 |
8 | import org.apache.http.client.HttpClient;
9 | import org.apache.http.impl.client.DefaultHttpClient;
10 | import org.junit.Before;
11 | import org.junit.BeforeClass;
12 | import org.junit.Test;
13 |
14 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
15 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
16 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithQuery;
17 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithUrl;
18 | import com.cribbstechnologies.clients.mandrill.model.response.urls.UrlListResponse;
19 | import com.cribbstechnologies.clients.mandrill.request.MandrillRESTRequest;
20 | import com.cribbstechnologies.clients.mandrill.request.MandrillUrlsRequest;
21 | import com.cribbstechnologies.clients.mandrill.util.MandrillConfiguration;
22 | import com.fasterxml.jackson.databind.ObjectMapper;
23 |
24 | public class UrlsTest {
25 |
26 | private static MandrillRESTRequest request = new MandrillRESTRequest();
27 | private static MandrillConfiguration config = new MandrillConfiguration();
28 | private static MandrillUrlsRequest urlsRequest = new MandrillUrlsRequest();
29 | private static HttpClient client;
30 | private static ObjectMapper mapper = new ObjectMapper();
31 |
32 | @BeforeClass
33 | public static void beforeClass() {
34 | Properties props = new Properties();
35 | try {
36 | props.load(UrlsTest.class.getClassLoader().getResourceAsStream("mandrill.properties"));
37 | } catch (IOException e) {
38 | fail ("properties file not loaded");
39 | }
40 | config.setApiKey(props.getProperty("apiKey"));
41 | config.setApiVersion("1.0");
42 | config.setBaseURL("https://mandrillapp.com/api");
43 | request.setConfig(config);
44 | request.setObjectMapper(mapper);
45 | urlsRequest.setRequest(request);
46 | }
47 |
48 | @Before
49 | public void before() {
50 | client = new DefaultHttpClient();
51 | request.setHttpClient(client);
52 | }
53 |
54 | @Test
55 | public void testGetList() {
56 | BaseMandrillRequest request = new BaseMandrillRequest();
57 | try {
58 | UrlListResponse response = urlsRequest.getList(request);
59 | } catch (RequestFailedException e) {
60 | e.printStackTrace();
61 | fail(e.getMessage());
62 | }
63 | }
64 |
65 | @Test
66 | public void testQuery() {
67 | MandrillRequestWithQuery request = new MandrillRequestWithQuery();
68 | request.setQ("http://www.google.com");
69 | try {
70 | UrlListResponse response = urlsRequest.doSearch(request);
71 | } catch (RequestFailedException e) {
72 | e.printStackTrace();
73 | fail(e.getMessage());
74 | }
75 | }
76 |
77 | @Test
78 | public void testGetTimeSeries() {
79 | MandrillRequestWithUrl request = new MandrillRequestWithUrl();
80 | request.setUrl("http://www.google.com");
81 | try {
82 | UrlListResponse response = urlsRequest.getTimeSeries(request);
83 | } catch (RequestFailedException e) {
84 | e.printStackTrace();
85 | fail(e.getMessage());
86 | }
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/it/java/com/cribbstechnologies/clients/mandrill/it/UsersTest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.it;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.fail;
5 |
6 | import java.io.IOException;
7 | import java.util.Properties;
8 |
9 | import org.apache.http.client.HttpClient;
10 | import org.apache.http.impl.client.DefaultHttpClient;
11 | import org.junit.Before;
12 | import org.junit.BeforeClass;
13 | import org.junit.Test;
14 |
15 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
16 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
17 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithDomain;
18 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail;
19 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillStringResponse;
20 | import com.cribbstechnologies.clients.mandrill.model.response.users.DisableResponse;
21 | import com.cribbstechnologies.clients.mandrill.model.response.users.PingResponse;
22 | import com.cribbstechnologies.clients.mandrill.model.response.users.UsersInfoResponse;
23 | import com.cribbstechnologies.clients.mandrill.model.response.users.UsersSendersResponse;
24 | import com.cribbstechnologies.clients.mandrill.model.response.users.VerifyResponse;
25 | import com.cribbstechnologies.clients.mandrill.request.MandrillRESTRequest;
26 | import com.cribbstechnologies.clients.mandrill.request.MandrillUsersRequest;
27 | import com.cribbstechnologies.clients.mandrill.util.MandrillConfiguration;
28 | import com.fasterxml.jackson.databind.ObjectMapper;
29 |
30 | public class UsersTest {
31 |
32 | private static MandrillRESTRequest request = new MandrillRESTRequest();
33 | private static MandrillConfiguration config = new MandrillConfiguration();
34 | private static MandrillUsersRequest usersRequest = new MandrillUsersRequest();
35 | private static HttpClient client;
36 | private static ObjectMapper mapper = new ObjectMapper();
37 | private static Properties props = new Properties();
38 |
39 | @BeforeClass
40 | public static void beforeClass() {
41 | try {
42 | props.load(UsersTest.class.getClassLoader().getResourceAsStream("mandrill.properties"));
43 | } catch (IOException e) {
44 | fail("properties file not loaded");
45 | }
46 | config.setApiKey(props.getProperty("apiKey"));
47 | config.setApiVersion("1.0");
48 | config.setBaseURL("https://mandrillapp.com/api");
49 | request.setConfig(config);
50 | request.setObjectMapper(mapper);
51 | usersRequest.setRequest(request);
52 | }
53 |
54 | @Before
55 | public void before() {
56 | client = new DefaultHttpClient();
57 | request.setHttpClient(client);
58 | }
59 |
60 | @Test
61 | public void testPing() {
62 | BaseMandrillRequest baseRequest = new BaseMandrillRequest();
63 | try {
64 | BaseMandrillStringResponse response = usersRequest.performPing(baseRequest);
65 | assertEquals("\"PONG!\"", response.getResponse());
66 | } catch (RequestFailedException e) {
67 | fail(e.getMessage());
68 | }
69 | }
70 |
71 | @Test
72 | public void testPing2() {
73 | BaseMandrillRequest baseRequest = new BaseMandrillRequest();
74 | try {
75 | PingResponse pingResponse = usersRequest.performPing2(baseRequest);
76 | assertEquals("PONG!", pingResponse.getPingResponse());
77 | } catch (RequestFailedException e) {
78 | e.printStackTrace();
79 | fail(e.getMessage());
80 | }
81 | }
82 |
83 | @Test
84 | public void testGetInfo() {
85 | BaseMandrillRequest baseRequest = new BaseMandrillRequest();
86 | try {
87 | UsersInfoResponse response = usersRequest.getInfo(baseRequest);
88 | } catch (RequestFailedException e) {
89 | fail(e.getMessage());
90 | }
91 | }
92 |
93 | @Test
94 | public void testGetSenders() {
95 | BaseMandrillRequest baseRequest = new BaseMandrillRequest();
96 | try {
97 | UsersSendersResponse response = usersRequest.getSenders(baseRequest);
98 | } catch (RequestFailedException e) {
99 | e.printStackTrace();
100 | fail(e.getMessage());
101 | }
102 | }
103 |
104 | @Test
105 | public void testVerifySender() {
106 | MandrillRequestWithEmail emailRequest = new MandrillRequestWithEmail();
107 | emailRequest.setEmail(props.getProperty("verify.email"));
108 | try {
109 | VerifyResponse response = usersRequest.verifySender(emailRequest);
110 | } catch (RequestFailedException e) {
111 | e.printStackTrace();
112 | fail(e.getMessage());
113 | }
114 | }
115 |
116 | @Test
117 | public void testDisableSender() {
118 | MandrillRequestWithDomain domainRequest = new MandrillRequestWithDomain();
119 | domainRequest.setDomain("google.com");
120 | try {
121 | DisableResponse response = usersRequest.disableSender(domainRequest);
122 | } catch (RequestFailedException e) {
123 | e.printStackTrace();
124 | fail(e.getMessage());
125 | }
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/exception/RequestFailedException.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.exception;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.MandrillError;
4 |
5 | public class RequestFailedException extends Throwable {
6 |
7 | private static final long serialVersionUID = 1L;
8 | private MandrillError error;
9 |
10 | public RequestFailedException(String message, Throwable t) {
11 | super(message, t);
12 | }
13 |
14 | public RequestFailedException(String message) {
15 | super(message);
16 | }
17 |
18 | public RequestFailedException(String message, MandrillError error) {
19 | super(message);
20 | this.error = error;
21 | }
22 |
23 | public MandrillError getError() {
24 | return error;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/BaseMandrillRequest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class BaseMandrillRequest {
4 |
5 | private String key;
6 |
7 | public String getKey() {
8 | return key;
9 | }
10 |
11 | /**
12 | * It's not necessary to set this field manually as the MandrillRESTRequest pulls the property from the configuration and
13 | * populates this object with it on every request
14 | *
15 | * @param key
16 | */
17 | public void setKey(String key) {
18 | this.key = key;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillAttachment.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class MandrillAttachment {
4 |
5 | String type;
6 | String name;
7 | String content;
8 |
9 | public MandrillAttachment(String type, String name, String content) {
10 | this.type = type;
11 | this.name = name;
12 | this.content = content;
13 | }
14 |
15 | public String getContent() {
16 | return this.content;
17 | }
18 |
19 | public String getName() {
20 | return this.name;
21 | }
22 |
23 | public String getType() {
24 | return this.type;
25 | }
26 |
27 | /**
28 | * The attachment is represented by a base-64-encoded string
29 | *
30 | * @param content
31 | */
32 | public void setContent(String content) {
33 | this.content = content;
34 | }
35 |
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 |
40 | public void setType(String type) {
41 | this.type = type;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 emontoro.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.cribbstechnologies.clients.mandrill.model;
18 |
19 | /**
20 | *
21 | * @author emontoro
22 | */
23 | public class MandrillError {
24 |
25 | private String status;
26 | private Integer code;
27 | private String name;
28 | private String message;
29 |
30 | public MandrillError(String status, Integer code, String name, String message) {
31 | this.status = status;
32 | this.code = code;
33 | this.name = name;
34 | this.message = message;
35 | }
36 |
37 | public MandrillError() {
38 | status = null;
39 | code = null;
40 | name = null;
41 | message = null ;
42 | }
43 |
44 | public String getStatus() {
45 | return status;
46 | }
47 |
48 | public void setStatus(String status) {
49 | this.status = status;
50 | }
51 |
52 | public Integer getCode() {
53 | return code;
54 | }
55 |
56 | public void setCode(Integer code) {
57 | this.code = code;
58 | }
59 |
60 | public String getName() {
61 | return name;
62 | }
63 |
64 | public void setName(String name) {
65 | this.name = name;
66 | }
67 |
68 | public String getMessage() {
69 | return message;
70 | }
71 |
72 | public void setMessage(String message) {
73 | this.message = message;
74 | }
75 |
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillHtmlMessage.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class MandrillHtmlMessage extends MandrillMessage {
4 |
5 | private String html;
6 |
7 | public String getHtml() {
8 | return html;
9 | }
10 |
11 | public void setHtml(String html) {
12 | this.html = html;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessage.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | public class MandrillMessage {
7 |
8 | private String text;
9 | private String subject;
10 | private String from_email;
11 | private String from_name;
12 | private String subaccount;
13 | private MandrillRecipient[] to;
14 | private String bcc_address;
15 | private boolean track_opens=false;
16 | private boolean track_clicks=false;
17 | private boolean auto_text=false;
18 | private boolean url_strip_qs=false;
19 | private boolean preserve_recipients = false;
20 | private String[] tags = new String[0];
21 | private String[] google_analytics_domains = new String[0];
22 | private String[] google_analytics_campaign = new String[0];
23 | private List global_merge_vars;
24 | List merge_vars;
25 | List attachments;
26 | private boolean important;
27 | private boolean auto_html;
28 | private boolean inline_css;
29 | private boolean merge;
30 | private String merge_language;
31 | private Map metadata;
32 | private Map recipient_metadata;
33 |
34 | private Map headers;
35 |
36 | public List getAttachments() {
37 | return this.attachments;
38 | }
39 |
40 | public String getFrom_email() {
41 | return this.from_email;
42 | }
43 |
44 | public String getFrom_name() {
45 | return this.from_name;
46 | }
47 |
48 | public List getGlobal_merge_vars() {
49 | return this.global_merge_vars;
50 | }
51 |
52 | public String[] getGoogle_analytics_campaign() {
53 | return this.google_analytics_campaign;
54 | }
55 |
56 | public String[] getGoogle_analytics_domains() {
57 | return this.google_analytics_domains;
58 | }
59 |
60 | public Map getHeaders() {
61 | return this.headers;
62 | }
63 |
64 | public List getMerge_vars() {
65 | return this.merge_vars;
66 | }
67 |
68 | public String getSubject() {
69 | return this.subject;
70 | }
71 |
72 | public String[] getTags() {
73 | return this.tags;
74 | }
75 |
76 | public String getText() {
77 | return this.text;
78 | }
79 |
80 | public MandrillRecipient[] getTo() {
81 | return this.to;
82 | }
83 |
84 | public String getBcc_address() {
85 | return bcc_address;
86 | }
87 |
88 | public boolean isAuto_text() {
89 | return this.auto_text;
90 | }
91 |
92 | public boolean isTrack_clicks() {
93 | return this.track_clicks;
94 | }
95 |
96 | public boolean isTrack_opens() {
97 | return this.track_opens;
98 | }
99 |
100 | public boolean isUrl_strip_qs() {
101 | return this.url_strip_qs;
102 | }
103 |
104 | public void setAttachments(List attachments) {
105 | this.attachments = attachments;
106 | }
107 |
108 | public void setAuto_text(boolean auto_text) {
109 | this.auto_text = auto_text;
110 | }
111 |
112 | public void setFrom_email(String from_email) {
113 | this.from_email = from_email;
114 | }
115 |
116 | public void setFrom_name(String from_name) {
117 | this.from_name = from_name;
118 | }
119 |
120 | public void setGlobal_merge_vars(List global_merge_vars) {
121 | this.global_merge_vars = global_merge_vars;
122 | }
123 |
124 | public void setGoogle_analytics_campaign(String[] google_analytics_campaign) {
125 | this.google_analytics_campaign = google_analytics_campaign;
126 | }
127 |
128 | public void setGoogle_analytics_domains(String[] google_analytics_domains) {
129 | this.google_analytics_domains = google_analytics_domains;
130 | }
131 |
132 | public void setHeaders(Map struct) {
133 | this.headers = struct;
134 | }
135 |
136 | public void setMerge_vars(List merge_vars) {
137 | this.merge_vars = merge_vars;
138 | }
139 |
140 | public void setSubject(String subject) {
141 | this.subject = subject;
142 | }
143 |
144 | public void setTags(String[] tags) {
145 | this.tags = tags;
146 | }
147 |
148 | public void setText(String text) {
149 | this.text = text;
150 | }
151 |
152 | public void setTo(MandrillRecipient[] to) {
153 | this.to = to;
154 | }
155 |
156 | public void setBcc_address(String bcc) {
157 | this.bcc_address = bcc;
158 | }
159 |
160 | public void setTrack_clicks(boolean track_clicks) {
161 | this.track_clicks = track_clicks;
162 | }
163 |
164 | public void setTrack_opens(boolean track_opens) {
165 | this.track_opens = track_opens;
166 | }
167 |
168 | public void setUrl_strip_qs(boolean url_strip_qs) {
169 | this.url_strip_qs = url_strip_qs;
170 | }
171 |
172 | public final boolean isPreserve_recipients() {
173 | return preserve_recipients;
174 | }
175 |
176 | public final void setPreserve_recipients(boolean preserve_recipients) {
177 | this.preserve_recipients = preserve_recipients;
178 | }
179 |
180 | public final String getSubaccount() {
181 | return subaccount;
182 | }
183 |
184 | public final void setSubaccount(String subaccount) {
185 | this.subaccount = subaccount;
186 | }
187 |
188 | public boolean isAuto_html() {
189 | return auto_html;
190 | }
191 |
192 | public void setAuto_html(boolean auto_html) {
193 | this.auto_html = auto_html;
194 | }
195 |
196 | public boolean isImportant() {
197 | return important;
198 | }
199 |
200 | public void setImportant(boolean important) {
201 | this.important = important;
202 | }
203 |
204 | public boolean isInline_css() {
205 | return inline_css;
206 | }
207 |
208 | public void setInline_css(boolean inline_css) {
209 | this.inline_css = inline_css;
210 | }
211 |
212 | public boolean isMerge() {
213 | return merge;
214 | }
215 |
216 | public void setMerge(boolean merge) {
217 | this.merge = merge;
218 | }
219 |
220 | public String getMerge_language() {
221 | return merge_language;
222 | }
223 |
224 | public void setMerge_language(String merge_language) {
225 | this.merge_language = merge_language;
226 | }
227 |
228 | public Map getMetadata() {
229 | return metadata;
230 | }
231 |
232 | public void setMetadata(Map metadata) {
233 | this.metadata = metadata;
234 | }
235 |
236 | public Map getRecipient_metadata() {
237 | return recipient_metadata;
238 | }
239 |
240 | public void setRecipient_metadata(Map recipient_metadata) {
241 | this.recipient_metadata = recipient_metadata;
242 | }
243 | }
244 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessageInfoRequest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
4 |
5 | /**
6 | * User: telrod
7 | * Date: 4/10/14
8 | */
9 | public class MandrillMessageInfoRequest extends BaseMandrillRequest {
10 |
11 | String id;
12 |
13 | public String getId() {
14 | return id;
15 | }
16 |
17 | public void setId(String id) {
18 | this.id = id;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillMessageRequest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class MandrillMessageRequest extends BaseMandrillRequest {
4 |
5 | private MandrillHtmlMessage message;
6 |
7 | public MandrillMessage getMessage() {
8 | return message;
9 | }
10 |
11 | public void setMessage(MandrillHtmlMessage message) {
12 | this.message = message;
13 | }
14 |
15 |
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRecipient.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonInclude;
4 | import com.fasterxml.jackson.annotation.JsonInclude.Include;
5 |
6 | @JsonInclude(Include.NON_NULL)
7 | public class MandrillRecipient {
8 |
9 | String email;
10 | String name;
11 | String type;
12 |
13 | public MandrillRecipient(String name, String email) {
14 | this.email = email;
15 | this.name = name;
16 | }
17 |
18 | /**
19 | *
20 | * @param name
21 | * @param email
22 | * @param type
23 | * - one of "to", "cc", "bcc". defaults to "to" if not provided
24 | */
25 | public MandrillRecipient(String name, String email, String type) {
26 | this.email = email;
27 | this.name = name;
28 | this.type = type;
29 | }
30 |
31 | public String getEmail() {
32 | return email;
33 | }
34 |
35 | public void setEmail(String email) {
36 | this.email = email;
37 | }
38 |
39 | public String getName() {
40 | return name;
41 | }
42 |
43 | public void setName(String name) {
44 | this.name = name;
45 | }
46 |
47 | public final String getType() {
48 | return type;
49 | }
50 |
51 | public final void setType(String type) {
52 | this.type = type;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRequestWithCode.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class MandrillRequestWithCode extends MandrillRequestWithName {
4 |
5 | String code;
6 |
7 | public String getCode() {
8 | return code;
9 | }
10 |
11 | public void setCode(String code) {
12 | this.code = code;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRequestWithDomain.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class MandrillRequestWithDomain extends BaseMandrillRequest {
4 |
5 | private String domain;
6 |
7 | public String getDomain() {
8 | return domain;
9 | }
10 |
11 | public void setDomain(String domain) {
12 | this.domain = domain;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRequestWithEmail.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class MandrillRequestWithEmail extends BaseMandrillRequest {
4 |
5 | String email;
6 |
7 | public String getEmail() {
8 | return email;
9 | }
10 |
11 | public void setEmail(String email) {
12 | this.email = email;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRequestWithName.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class MandrillRequestWithName extends BaseMandrillRequest {
4 |
5 | String name;
6 |
7 | public String getName() {
8 | return name;
9 | }
10 |
11 | public void setName(String name) {
12 | this.name = name;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRequestWithQuery.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class MandrillRequestWithQuery extends BaseMandrillRequest {
4 |
5 | private String q;
6 |
7 | public String getQ() {
8 | return q;
9 | }
10 |
11 | public void setQ(String q) {
12 | this.q = q;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRequestWithTag.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class MandrillRequestWithTag extends BaseMandrillRequest {
4 |
5 | private String tag;
6 |
7 | public String getTag() {
8 | return tag;
9 | }
10 |
11 | public void setTag(String tag) {
12 | this.tag = tag;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillRequestWithUrl.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class MandrillRequestWithUrl extends BaseMandrillRequest {
4 |
5 | private String url;
6 |
7 | public String getUrl() {
8 | return url;
9 | }
10 |
11 | public void setUrl(String url) {
12 | this.url = url;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | @JsonIgnoreProperties(ignoreUnknown = true)
6 | public class MandrillResponse {
7 |
8 | private String responseString;
9 | private boolean success;
10 |
11 | public String getJsonResponse() {
12 | return responseString;
13 | }
14 |
15 | public void setResponseString(String jsonResponse) {
16 | this.responseString = jsonResponse;
17 | }
18 |
19 | public boolean isSuccess() {
20 | return success;
21 | }
22 |
23 | public void setSuccess(boolean success) {
24 | this.success = success;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MandrillTemplatedMessageRequest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | import java.util.List;
4 |
5 | public class MandrillTemplatedMessageRequest extends BaseMandrillRequest {
6 |
7 | String template_name;
8 | Listtemplate_content;
9 | List merge_vars;
10 | MandrillMessage message;
11 |
12 | public String getTemplate_name() {
13 | return template_name;
14 | }
15 |
16 | public void setTemplate_name(String template_name) {
17 | this.template_name = template_name;
18 | }
19 |
20 | public List getTemplate_content() {
21 | return template_content;
22 | }
23 |
24 | public void setTemplate_content(List template_content) {
25 | this.template_content = template_content;
26 | }
27 |
28 | public MandrillMessage getMessage() {
29 | return message;
30 | }
31 |
32 | public void setMessage(MandrillMessage message) {
33 | this.message = message;
34 | }
35 |
36 | public List getMerge_vars() {
37 | return merge_vars;
38 | }public void setMerge_vars(List merge_vars) {
39 | this.merge_vars = merge_vars;
40 | }}
41 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MergeVar.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | /**
4 | * Created with IntelliJ IDEA.
5 | * User: azuercher
6 | * Date: 6/27/12
7 | * Time: 5:23 PM
8 | * To change this template use File | Settings | File Templates.
9 | */
10 | public class MergeVar {
11 | private String name;
12 | private Object content;
13 | public MergeVar(String name, Object content) {
14 | this.name = name;
15 | this.content = content;
16 | }
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public void setName(String name) {
22 | this.name = name;
23 | }
24 |
25 | public Object getContent() {
26 | return content;
27 | }
28 |
29 | public void setContent(Object content) {
30 | this.content = content;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/MessageMergeVars.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | import java.util.List;
4 |
5 | public class MessageMergeVars {
6 | private String rcpt;
7 | private List vars;
8 |
9 | public String getRcpt() {
10 | return rcpt;
11 | }
12 |
13 | public void setRcpt(String rcpt) {
14 | this.rcpt = rcpt;
15 | }
16 |
17 | public List getVars() {
18 | return vars;
19 | }
20 |
21 | public void setVars(List vars) {
22 | this.vars = vars;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/ServiceMethods.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class ServiceMethods {
4 |
5 | public class Users {
6 |
7 | public static final String PING = "users/ping.json";
8 | public static final String INFO = "users/info.json";
9 | public static final String SENDERS = "users/senders.json";
10 | public static final String PING2 = "users/ping2.json";
11 | @Deprecated
12 | public static final String DISABLE_SENDER = "users/disable-sender.json";
13 | @Deprecated
14 | public static final String VERIFY_SENDER = "users/verify-sender.json";
15 | }
16 |
17 | public class Messages {
18 |
19 | public static final String SEND = "messages/send.json";
20 | public static final String SEND_TEMPLATE = "messages/send-template.json";
21 | public static final String SEARCH = "messages/search.json";
22 | public static final String PARSE = "messages/parse.json";
23 | public static final String SEND_RAW = "messages/send-raw.json";
24 | public static final String INFO = "messages/info.json";
25 | }
26 |
27 | public class Tags {
28 |
29 | public static final String LIST = "tags/list.json";
30 | public static final String DELETE = "tags/delete.json";
31 | public static final String INFO = "tags/info.json";
32 | public static final String TIME_SERIES = "tags/time-series.json";
33 | public static final String ALL_TIME_SERIES = "tags/all-time-series.json";
34 | }
35 |
36 | public class Rejects {
37 |
38 | public static final String ADD = "rejects/add.json";
39 | public static final String LIST = "rejects/list.json";
40 | public static final String DELETE = "rejects/delete.json";
41 | }
42 |
43 | public class Whitelists {
44 |
45 | public static final String ADD = "whitelists/add.json";
46 | public static final String LIST = "whitelists/list.json";
47 | public static final String DELETE = "whitelists/delete.json";
48 | }
49 |
50 | public class Senders {
51 |
52 | public static final String LIST = "senders/list.json";
53 | public static final String DOMAINS = "senders/domain.json";
54 | public static final String INFO = "senders/info.json";
55 | public static final String TIME_SERIES = "senders/time-series.json";
56 | }
57 |
58 | public class Urls {
59 |
60 | public static final String LIST = "urls/list.json";
61 | public static final String SEARCH = "urls/search.json";
62 | public static final String TIME_SERIES = "urls/time-series.json";
63 | }
64 |
65 | public class Templates {
66 |
67 | public static final String ADD = "templates/add.json";
68 | public static final String INFO = "templates/info.json";
69 | public static final String UPDATE = "templates/update.json";
70 | public static final String PUBLISH = "templates/publish.json";
71 | public static final String DELETE = "templates/delete.json";
72 | public static final String LIST = "templates/list.json";
73 | public static final String TIME_SERIES = "templates/time-series.json";
74 | public static final String RENDER = "templates/render.json";
75 | }
76 |
77 | public class Webhooks {
78 |
79 | public static final String LIST = "webhooks/list.json";
80 | public static final String ADD = "webhooks/add.json";
81 | public static final String INFO = "webhooks/info.json";
82 | public static final String UPDATE = "webhooks/update.json";
83 | public static final String DELETE = "webhooks/delete.json";
84 | }
85 |
86 | public class Inbound {
87 |
88 | public static final String DOMAINS = "inbound/domains.json";
89 | public static final String ROUTES = "inbound/routes.json";
90 | public static final String SEND_RAW = "inbound/send-raw.json";
91 | }
92 |
93 | public class Exports {
94 |
95 | public static final String INFO = "exports/info.json";
96 | public static final String LIST = "exports/list.json";
97 | public static final String REJECTS = "exports/rejects.json";
98 | public static final String WHITELIST = "exports/whitelist.json";
99 | public static final String ACTIVITY = "exports/activity.json";
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/TemplateContent.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model;
2 |
3 | public class TemplateContent {
4 |
5 | String name;
6 | String content;
7 |
8 | public String getName() {
9 | return name;
10 | }
11 |
12 | public void setName(String name) {
13 | this.name = name;
14 | }
15 |
16 | public String getContent() {
17 | return content;
18 | }
19 |
20 | public void setContent(String content) {
21 | this.content = content;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/BaseMandrillAnonymousListResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response;
2 |
3 | import java.util.List;
4 |
5 | public class BaseMandrillAnonymousListResponse extends BaseMandrillResponse {
6 |
7 | private List list;
8 |
9 | public List getList() {
10 | return list;
11 | }
12 |
13 | public void setList(List list) {
14 | this.list = list;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/BaseMandrillResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response;
2 |
3 | public class BaseMandrillResponse {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/BaseMandrillStringResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response;
2 |
3 | public class BaseMandrillStringResponse extends BaseMandrillResponse {
4 |
5 | private String response;
6 |
7 | public BaseMandrillStringResponse() {
8 |
9 | }
10 |
11 | public BaseMandrillStringResponse(String response) {
12 | this.response = response;
13 | }
14 |
15 | public String getResponse() {
16 | return response;
17 | }
18 |
19 | public void setResponse(String response) {
20 | this.response = response;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/StatsResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response;
2 |
3 | public class StatsResponse extends BaseMandrillResponse {
4 |
5 | int sent;
6 | int hard_bounces;
7 | int soft_bounces;
8 | int rejects;
9 | int complaints;
10 | int unsubs;
11 | int opens;
12 | int unique_opens;
13 | int clicks;
14 | int unique_clicks;
15 |
16 | public int getSent() {
17 | return sent;
18 | }
19 |
20 | public void setSent(int sent) {
21 | this.sent = sent;
22 | }
23 |
24 | public int getHard_bounces() {
25 | return hard_bounces;
26 | }
27 |
28 | public void setHard_bounces(int hard_bounces) {
29 | this.hard_bounces = hard_bounces;
30 | }
31 |
32 | public int getSoft_bounces() {
33 | return soft_bounces;
34 | }
35 |
36 | public void setSoft_bounces(int soft_bounces) {
37 | this.soft_bounces = soft_bounces;
38 | }
39 |
40 | public int getRejects() {
41 | return rejects;
42 | }
43 |
44 | public void setRejects(int rejects) {
45 | this.rejects = rejects;
46 | }
47 |
48 | public int getComplaints() {
49 | return complaints;
50 | }
51 |
52 | public void setComplaints(int complaints) {
53 | this.complaints = complaints;
54 | }
55 |
56 | public int getUnsubs() {
57 | return unsubs;
58 | }
59 |
60 | public void setUnsubs(int unsubs) {
61 | this.unsubs = unsubs;
62 | }
63 |
64 | public int getOpens() {
65 | return opens;
66 | }
67 |
68 | public void setOpens(int opens) {
69 | this.opens = opens;
70 | }
71 |
72 | public int getUnique_opens() {
73 | return unique_opens;
74 | }
75 |
76 | public void setUnique_opens(int unique_opens) {
77 | this.unique_opens = unique_opens;
78 | }
79 |
80 | public int getClicks() {
81 | return clicks;
82 | }
83 |
84 | public void setClicks(int clicks) {
85 | this.clicks = clicks;
86 | }
87 |
88 | public int getUnique_clicks() {
89 | return unique_clicks;
90 | }
91 |
92 | public void setUnique_clicks(int unique_clicks) {
93 | this.unique_clicks = unique_clicks;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/StatsResponseMap.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response;
2 |
3 | public class StatsResponseMap {
4 |
5 | StatsResponse today;
6 | StatsResponse last_7_days;
7 | StatsResponse last_30_days;
8 | StatsResponse last_60_days;
9 | StatsResponse last_90_days;
10 | StatsResponse all_time;
11 |
12 | public StatsResponse getToday() {
13 | return today;
14 | }
15 |
16 | public void setToday(StatsResponse today) {
17 | this.today = today;
18 | }
19 |
20 | public StatsResponse getLast_7_days() {
21 | return last_7_days;
22 | }
23 |
24 | public void setLast_7_days(StatsResponse last_7_days) {
25 | this.last_7_days = last_7_days;
26 | }
27 |
28 | public StatsResponse getLast_30_days() {
29 | return last_30_days;
30 | }
31 |
32 | public void setLast_30_days(StatsResponse last_30_days) {
33 | this.last_30_days = last_30_days;
34 | }
35 |
36 | public StatsResponse getLast_60_days() {
37 | return last_60_days;
38 | }
39 |
40 | public void setLast_60_days(StatsResponse last_60_days) {
41 | this.last_60_days = last_60_days;
42 | }
43 |
44 | public StatsResponse getLast_90_days() {
45 | return last_90_days;
46 | }
47 |
48 | public void setLast_90_days(StatsResponse last_90_days) {
49 | this.last_90_days = last_90_days;
50 | }
51 |
52 | public StatsResponse getAll_time() {
53 | return all_time;
54 | }
55 |
56 | public void setAll_time(StatsResponse all_time) {
57 | this.all_time = all_time;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/message/MessageInfoClicksDetail.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.message;
2 |
3 | /**
4 | * User: telrod
5 | * Date: 4/11/14
6 | */
7 | public class MessageInfoClicksDetail {
8 | Integer ts;
9 | String ip;
10 | String location;
11 | String ua;
12 | String url;
13 |
14 | public Integer getTs() {
15 | return ts;
16 | }
17 |
18 | public void setTs(Integer ts) {
19 | this.ts = ts;
20 | }
21 |
22 | public String getIp() {
23 | return ip;
24 | }
25 |
26 | public void setIp(String ip) {
27 | this.ip = ip;
28 | }
29 |
30 | public String getLocation() {
31 | return location;
32 | }
33 |
34 | public void setLocation(String location) {
35 | this.location = location;
36 | }
37 |
38 | public String getUa() {
39 | return ua;
40 | }
41 |
42 | public void setUa(String ua) {
43 | this.ua = ua;
44 | }
45 |
46 | public String getUrl() {
47 | return url;
48 | }
49 |
50 | public void setUrl(String url) {
51 | this.url = url;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return "MessageInfoClicksDetail{" +
57 | "ts=" + ts +
58 | ", ip='" + ip + '\'' +
59 | ", location='" + location + '\'' +
60 | ", ua='" + ua + '\'' +
61 | ", url='" + url + '\'' +
62 | '}';
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/message/MessageInfoOpensDetail.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.message;
2 |
3 | /**
4 | * User: telrod
5 | * Date: 4/11/14
6 | */
7 | public class MessageInfoOpensDetail {
8 | Integer ts;
9 | String ip;
10 | String location;
11 | String ua;
12 |
13 | public Integer getTs() {
14 | return ts;
15 | }
16 |
17 | public void setTs(Integer ts) {
18 | this.ts = ts;
19 | }
20 |
21 | public String getIp() {
22 | return ip;
23 | }
24 |
25 | public void setIp(String ip) {
26 | this.ip = ip;
27 | }
28 |
29 | public String getLocation() {
30 | return location;
31 | }
32 |
33 | public void setLocation(String location) {
34 | this.location = location;
35 | }
36 |
37 | public String getUa() {
38 | return ua;
39 | }
40 |
41 | public void setUa(String ua) {
42 | this.ua = ua;
43 | }
44 |
45 | @Override
46 | public String toString() {
47 | return "MessageInfoOpensDetail{" +
48 | "ts=" + ts +
49 | ", ip='" + ip + '\'' +
50 | ", location='" + location + '\'' +
51 | ", ua='" + ua + '\'' +
52 | '}';
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/message/MessageInfoResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.message;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * User: telrod
9 | * Date: 4/10/14
10 | */
11 | public class MessageInfoResponse extends BaseMandrillResponse {
12 |
13 | Integer ts;
14 | String _id;
15 | String sender;
16 | String template;
17 | String subject;
18 | String email;
19 | Integer opens;
20 | Integer clicks;
21 | String state;
22 | List tags;
23 | List smtp_events;
24 | List opens_detail;
25 | List clicks_detail;
26 | List resends;
27 | String bgtools_code;
28 | String diag;
29 | String bounce_description;
30 |
31 | public List getResends() {
32 | return resends;
33 | }
34 |
35 | public void setResends(List resends) {
36 | this.resends = resends;
37 | }
38 |
39 | public List getSmtp_events() {
40 | return smtp_events;
41 | }
42 |
43 | public void setSmtp_events(List smtp_events) {
44 | this.smtp_events = smtp_events;
45 | }
46 |
47 | public Integer getTs() {
48 | return ts;
49 | }
50 |
51 | public void setTs(Integer ts) {
52 | this.ts = ts;
53 | }
54 |
55 | public String get_id() {
56 | return _id;
57 | }
58 |
59 | public void set_id(String _id) {
60 | this._id = _id;
61 | }
62 |
63 | public String getSender() {
64 | return sender;
65 | }
66 |
67 | public void setSender(String sender) {
68 | this.sender = sender;
69 | }
70 |
71 | public String getTemplate() {
72 | return template;
73 | }
74 |
75 | public void setTemplate(String template) {
76 | this.template = template;
77 | }
78 |
79 | public String getSubject() {
80 | return subject;
81 | }
82 |
83 | public void setSubject(String subject) {
84 | this.subject = subject;
85 | }
86 |
87 | public String getEmail() {
88 | return email;
89 | }
90 |
91 | public void setEmail(String email) {
92 | this.email = email;
93 | }
94 |
95 | public Integer getOpens() {
96 | return opens;
97 | }
98 |
99 | public void setOpens(Integer opens) {
100 | this.opens = opens;
101 | }
102 |
103 | public Integer getClicks() {
104 | return clicks;
105 | }
106 |
107 | public void setClicks(Integer clicks) {
108 | this.clicks = clicks;
109 | }
110 |
111 | public String getState() {
112 | return state;
113 | }
114 |
115 | public void setState(String state) {
116 | this.state = state;
117 | }
118 |
119 | public List getTags() {
120 | return tags;
121 | }
122 |
123 | public void setTags(List tags) {
124 | this.tags = tags;
125 | }
126 |
127 | public List getOpens_detail() {
128 | return opens_detail;
129 | }
130 |
131 | public void setOpens_detail(List opens_detail) {
132 | this.opens_detail = opens_detail;
133 | }
134 |
135 | public List getClicks_detail() {
136 | return clicks_detail;
137 | }
138 |
139 | public void setClicks_detail(List clicks_detail) {
140 | this.clicks_detail = clicks_detail;
141 | }
142 |
143 | public String getBgtools_code() {
144 | return bgtools_code;
145 | }
146 |
147 | public String getDiag() {
148 | return diag;
149 | }
150 |
151 | public void setDiag(String diag) {
152 | this.diag = diag;
153 | }
154 |
155 | public String getBounce_description() {
156 | return bounce_description;
157 | }
158 |
159 | public void setBounce_description(String bounce_description) {
160 | this.bounce_description = bounce_description;
161 | }
162 |
163 | public void setBgtools_code(String bgtools_code) {
164 | this.bgtools_code = bgtools_code;
165 |
166 |
167 | }
168 |
169 | @Override
170 | public String toString() {
171 | return "MessageInfoResponse{" +
172 | "ts=" + ts +
173 | ", _id='" + _id + '\'' +
174 | ", sender='" + sender + '\'' +
175 | ", template='" + template + '\'' +
176 | ", subject='" + subject + '\'' +
177 | ", email='" + email + '\'' +
178 | ", opens=" + opens +
179 | ", clicks=" + clicks +
180 | ", state='" + state + '\'' +
181 | ", tags=" + tags +
182 | ", smtp_events=" + smtp_events +
183 | ", opens_detail=" + opens_detail +
184 | ", clicks_detail=" + clicks_detail +
185 | ", resends=" + resends +
186 | '}';
187 | }
188 |
189 | }
190 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/message/MessageInfoSmtpEvents.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.message;
2 |
3 | /**
4 | * User: telrod
5 | * Date: 4/11/14
6 | */
7 | public class MessageInfoSmtpEvents {
8 | Integer ts;
9 | String type;
10 | String diag;
11 | String source_ip;
12 | String destination_ip;
13 | Integer size;
14 |
15 | public Integer getTs() {
16 | return ts;
17 | }
18 |
19 | public void setTs(Integer ts) {
20 | this.ts = ts;
21 | }
22 |
23 | public String getType() {
24 | return type;
25 | }
26 |
27 | public void setType(String type) {
28 | this.type = type;
29 | }
30 |
31 | public String getDiag() {
32 | return diag;
33 | }
34 |
35 | public void setDiag(String diag) {
36 | this.diag = diag;
37 | }
38 |
39 | public String getSource_ip() {
40 | return source_ip;
41 | }
42 |
43 | public void setSource_ip(String source_ip) {
44 | this.source_ip = source_ip;
45 | }
46 |
47 | public String getDestination_ip() {
48 | return destination_ip;
49 | }
50 |
51 | public void setDestination_ip(String destination_ip) {
52 | this.destination_ip = destination_ip;
53 | }
54 |
55 | public Integer getSize() {
56 | return size;
57 | }
58 |
59 | public void setSize(Integer size) {
60 | this.size = size;
61 | }
62 |
63 | @Override
64 | public String toString() {
65 | return "MessageInfoSmtpEvents{" +
66 | "ts=" + ts +
67 | ", type='" + type + '\'' +
68 | ", diag='" + diag + '\'' +
69 | ", source_ip='" + source_ip + '\'' +
70 | ", destination_ip='" + destination_ip + '\'' +
71 | ", size=" + size +
72 | '}';
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/message/MessageResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.message;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 |
6 | public class MessageResponse extends BaseMandrillResponse {
7 |
8 | String email;
9 | String status;
10 | String _id;
11 | String rejectReason;
12 |
13 | public String getEmail() {
14 | return email;
15 | }
16 |
17 | public void setEmail(String email) {
18 | this.email = email;
19 | }
20 |
21 | public String getStatus() {
22 | return status;
23 | }
24 |
25 | public void setStatus(String status) {
26 | this.status = status;
27 | }
28 |
29 | public String get_id() {
30 | return _id;
31 | }
32 |
33 | public void set_id(String _id) {
34 | this._id = _id;
35 | }
36 |
37 | public String getRejectReason() {
38 | return this.rejectReason;
39 | }
40 |
41 | @JsonProperty("reject_reason")
42 | public void setRejectReason(String rejectReason) {
43 | this.rejectReason = rejectReason;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/message/SendMessageResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.message;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
4 |
5 | public class SendMessageResponse extends BaseMandrillAnonymousListResponse {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/tags/BaseTag.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.tags;
2 |
3 | public class BaseTag {
4 |
5 | int sent;
6 | int hard_bounces;
7 | int soft_bounces;
8 | int rejects;
9 | int complaints;
10 | int opens;
11 | int clicks;
12 | String tag;
13 | int unique_opens;
14 | int unique_clicks;
15 | int unsubs;
16 |
17 | public int getSent() {
18 | return sent;
19 | }
20 |
21 | public void setSent(int sent) {
22 | this.sent = sent;
23 | }
24 |
25 | public int getHard_bounces() {
26 | return hard_bounces;
27 | }
28 |
29 | public void setHard_bounces(int hard_bounces) {
30 | this.hard_bounces = hard_bounces;
31 | }
32 |
33 | public int getSoft_bounces() {
34 | return soft_bounces;
35 | }
36 |
37 | public void setSoft_bounces(int soft_bounces) {
38 | this.soft_bounces = soft_bounces;
39 | }
40 |
41 | public int getRejects() {
42 | return rejects;
43 | }
44 |
45 | public void setRejects(int rejects) {
46 | this.rejects = rejects;
47 | }
48 |
49 | public int getComplaints() {
50 | return complaints;
51 | }
52 |
53 | public void setComplaints(int complaints) {
54 | this.complaints = complaints;
55 | }
56 |
57 | public int getOpens() {
58 | return opens;
59 | }
60 |
61 | public void setOpens(int opens) {
62 | this.opens = opens;
63 | }
64 |
65 | public int getClicks() {
66 | return clicks;
67 | }
68 |
69 | public void setClicks(int clicks) {
70 | this.clicks = clicks;
71 | }
72 |
73 | public String getTag() {
74 | return tag;
75 | }
76 |
77 | public void setTag(String tag) {
78 | this.tag = tag;
79 | }
80 |
81 | public int getUnique_opens() {
82 | return unique_opens;
83 | }
84 |
85 | public void setUnique_opens(int unique_opens) {
86 | this.unique_opens = unique_opens;
87 | }
88 |
89 | public int getUnique_clicks() {
90 | return unique_clicks;
91 | }
92 |
93 | public void setUnique_clicks(int unique_clicks) {
94 | this.unique_clicks = unique_clicks;
95 | }
96 |
97 | public int getUnsubs() {
98 | return unsubs;
99 | }
100 |
101 | public void setUnsubs(int unsubs) {
102 | this.unsubs = unsubs;
103 | }
104 |
105 |
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/tags/TagListResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.tags;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
4 |
5 | public class TagListResponse extends BaseMandrillAnonymousListResponse {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/tags/TagSeriesResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.tags;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
4 |
5 | public class TagSeriesResponse extends BaseMandrillAnonymousListResponse {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/tags/TagWithTime.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.tags;
2 |
3 | public class TagWithTime extends BaseTag {
4 |
5 | String time;
6 |
7 | public String getTime() {
8 | return time;
9 | }
10 |
11 | public void setTime(String time) {
12 | this.time = time;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/templates/TemplateListResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.templates;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
4 |
5 | public class TemplateListResponse extends BaseMandrillAnonymousListResponse {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/templates/TemplateRenderResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.templates;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse; /**
4 | * User: telrod
5 | * Date: 4/23/14
6 | */
7 | public class TemplateRenderResponse extends BaseMandrillResponse {
8 | private String html;
9 |
10 | public String getHtml() {
11 | return html;
12 | }public void setHtml(String html) {
13 | this.html = html;
14 | }}
15 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/templates/TemplateResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.templates;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5 |
6 | @JsonIgnoreProperties(ignoreUnknown=true)
7 | public class TemplateResponse extends BaseMandrillResponse {
8 |
9 | String id;
10 | String name;
11 | String code;
12 | String created_at;
13 | String updated_at;
14 |
15 | public String getName() {
16 | return name;
17 | }
18 |
19 | public void setName(String name) {
20 | this.name = name;
21 | }
22 |
23 | public String getCode() {
24 | return code;
25 | }
26 |
27 | public void setCode(String code) {
28 | this.code = code;
29 | }
30 |
31 | public String getCreated_at() {
32 | return created_at;
33 | }
34 |
35 | public void setCreated_at(String created_at) {
36 | this.created_at = created_at;
37 | }
38 |
39 | public String getUpdated_at() {
40 | return updated_at;
41 | }
42 |
43 | public void setUpdated_at(String updated_at) {
44 | this.updated_at = updated_at;
45 | }
46 |
47 | public String getId() {
48 | return id;
49 | }
50 |
51 | public void setId(String id) {
52 | this.id = id;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/urls/BaseUrlResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.urls;
2 |
3 | public class BaseUrlResponse {
4 |
5 | String id;
6 | int sent;
7 | int clicks;
8 | int unique_clicks;
9 |
10 | public int getSent() {
11 | return sent;
12 | }
13 |
14 | public void setSent(int sent) {
15 | this.sent = sent;
16 | }
17 |
18 | public int getClicks() {
19 | return clicks;
20 | }
21 |
22 | public void setClicks(int clicks) {
23 | this.clicks = clicks;
24 | }
25 |
26 | public int getUnique_clicks() {
27 | return unique_clicks;
28 | }
29 |
30 | public void setUnique_clicks(int unique_clicks) {
31 | this.unique_clicks = unique_clicks;
32 | }
33 |
34 | public String getId() {
35 | return id;
36 | }
37 |
38 | public void setId(String id) {
39 | this.id = id;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/urls/TimeUrlResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.urls;
2 |
3 | public class TimeUrlResponse extends BaseUrlResponse {
4 |
5 | String time;
6 |
7 | public String getTime() {
8 | return time;
9 | }
10 |
11 | public void setTime(String time) {
12 | this.time = time;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/urls/UrlListResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.urls;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
4 |
5 | public class UrlListResponse extends BaseMandrillAnonymousListResponse {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/urls/UrlResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.urls;
2 |
3 | public class UrlResponse extends BaseUrlResponse {
4 |
5 | String url;
6 | String time;
7 |
8 | public String getUrl() {
9 | return url;
10 | }
11 |
12 | public void setUrl(String url) {
13 | this.url = url;
14 | }
15 |
16 | public String getTime() {
17 | return time;
18 | }
19 |
20 | public void setTime(String time) {
21 | this.time = time;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/urls/UrlTimeResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.urls;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
4 |
5 | public class UrlTimeResponse extends BaseMandrillAnonymousListResponse {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/users/DisableResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.users;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
4 |
5 | public class DisableResponse extends BaseMandrillResponse {
6 |
7 | String domain;
8 | String created_at;
9 | String approved_at;
10 | boolean is_enabled;
11 |
12 | public String getDomain() {
13 | return domain;
14 | }
15 |
16 | public void setDomain(String domain) {
17 | this.domain = domain;
18 | }
19 |
20 | public String getCreated_at() {
21 | return created_at;
22 | }
23 |
24 | public void setCreated_at(String created_at) {
25 | this.created_at = created_at;
26 | }
27 |
28 | public String getApproved_at() {
29 | return approved_at;
30 | }
31 |
32 | public void setApproved_at(String approved_at) {
33 | this.approved_at = approved_at;
34 | }
35 |
36 | public boolean isIs_enabled() {
37 | return is_enabled;
38 | }
39 |
40 | public void setIs_enabled(boolean is_enabled) {
41 | this.is_enabled = is_enabled;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/users/MandrillSender.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.users;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.StatsResponse;
4 |
5 | public class MandrillSender extends StatsResponse {
6 |
7 | //{"address":"federico@mailchimp.com","created_at":"2012-01-09 15:29:19","is_enabled":true}
8 | String address;
9 | String created_at;
10 | boolean is_enabled;
11 |
12 | public String getAddress() {
13 | return address;
14 | }
15 |
16 | public void setAddress(String address) {
17 | this.address = address;
18 | }
19 |
20 | public String getCreated_at() {
21 | return created_at;
22 | }
23 |
24 | public void setCreated_at(String created_at) {
25 | this.created_at = created_at;
26 | }
27 |
28 | public boolean getIs_enabled() {
29 | return is_enabled;
30 | }
31 |
32 | public void setIs_enabled(boolean is_enabled) {
33 | this.is_enabled = is_enabled;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/users/PingResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.users;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 |
6 | public class PingResponse extends BaseMandrillResponse {
7 |
8 | @JsonProperty("PING")
9 | public String pingResponse;
10 |
11 | public String getPingResponse() {
12 | return pingResponse;
13 | }
14 |
15 | public void setPingResponse(String pingResponse) {
16 | this.pingResponse = pingResponse;
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/users/UsersInfoResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.users;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
4 | import com.cribbstechnologies.clients.mandrill.model.response.StatsResponseMap;
5 |
6 | public class UsersInfoResponse extends BaseMandrillResponse {
7 |
8 | String username;
9 | String created_at;
10 | int reputation;
11 | int hourly_quota;
12 | int backlog;
13 |
14 | StatsResponseMap stats;
15 |
16 | public String getUsername() {
17 | return username;
18 | }
19 |
20 | public void setUsername(String username) {
21 | this.username = username;
22 | }
23 |
24 | public String getCreated_at() {
25 | return created_at;
26 | }
27 |
28 | public void setCreated_at(String created_at) {
29 | this.created_at = created_at;
30 | }
31 |
32 | public int getReputation() {
33 | return reputation;
34 | }
35 |
36 | public void setReputation(int reputation) {
37 | this.reputation = reputation;
38 | }
39 |
40 | public int getHourly_quota() {
41 | return hourly_quota;
42 | }
43 |
44 | public void setHourly_quota(int hourly_quota) {
45 | this.hourly_quota = hourly_quota;
46 | }
47 |
48 | public StatsResponseMap getStats() {
49 | return stats;
50 | }
51 |
52 | public void setStats(StatsResponseMap stats) {
53 | this.stats = stats;
54 | }
55 |
56 | public int getBacklog() {
57 | return backlog;
58 | }
59 |
60 | public void setBacklog(int backlog) {
61 | this.backlog = backlog;
62 | }
63 |
64 |
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/users/UsersSendersResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.users;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
4 |
5 | public class UsersSendersResponse extends BaseMandrillAnonymousListResponse {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/model/response/users/VerifyResponse.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.model.response.users;
2 |
3 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
4 |
5 | public class VerifyResponse extends BaseMandrillResponse {
6 |
7 | String domain;
8 | String created_at;
9 | String approved_at;
10 | boolean is_enabled;
11 |
12 | public String getDomain() {
13 | return domain;
14 | }
15 |
16 | public void setDomain(String domain) {
17 | this.domain = domain;
18 | }
19 |
20 | public String getCreated_at() {
21 | return created_at;
22 | }
23 |
24 | public void setCreated_at(String created_at) {
25 | this.created_at = created_at;
26 | }
27 |
28 | public String getApproved_at() {
29 | return approved_at;
30 | }
31 |
32 | public void setApproved_at(String approved_at) {
33 | this.approved_at = approved_at;
34 | }
35 |
36 | public boolean isIs_enabled() {
37 | return is_enabled;
38 | }
39 |
40 | public void setIs_enabled(boolean is_enabled) {
41 | this.is_enabled = is_enabled;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillMessagesRequest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.request;
2 |
3 | import java.util.List;
4 |
5 | import com.cribbstechnologies.clients.mandrill.model.MandrillMessageInfoRequest;
6 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
7 | import com.cribbstechnologies.clients.mandrill.model.response.message.MessageInfoResponse;
8 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
9 | import com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest;
10 | import com.cribbstechnologies.clients.mandrill.model.MandrillTemplatedMessageRequest;
11 | import com.cribbstechnologies.clients.mandrill.model.ServiceMethods;
12 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
13 | import com.cribbstechnologies.clients.mandrill.model.response.message.MessageResponse;
14 | import com.cribbstechnologies.clients.mandrill.model.response.message.SendMessageResponse;
15 | import com.fasterxml.jackson.core.type.TypeReference;
16 |
17 | /**
18 | * This class holds various functions for the Mandrill Messages API
19 | *
20 | * @author Brian Cribbs
21 | *
22 | */
23 | public class MandrillMessagesRequest {
24 |
25 | MandrillRESTRequest request;
26 | TypeReference> messageResponseListReference = new TypeReference>() {
27 | };
28 |
29 | /**
30 | * Send a new transactional message through Mandrill
31 | *
32 | * @param messageRequest
33 | * a populated @see com.cribstechnologies.clients.mandrill.model.MandrillMessageRequest
34 | * @throws RequestFailedException
35 | */
36 | public SendMessageResponse sendMessage(MandrillMessageRequest messageRequest) throws RequestFailedException {
37 | SendMessageResponse response = new SendMessageResponse();
38 | response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(messageRequest, ServiceMethods.Messages.SEND, SendMessageResponse.class,
39 | messageResponseListReference)).getList());
40 | return response;
41 | }
42 |
43 | public SendMessageResponse sendTemplatedMessage(MandrillTemplatedMessageRequest templateMessage) throws RequestFailedException {
44 | SendMessageResponse response = new SendMessageResponse();
45 | response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(templateMessage, ServiceMethods.Messages.SEND_TEMPLATE,
46 | SendMessageResponse.class, messageResponseListReference)).getList());
47 | return response;
48 | }
49 |
50 | public MessageInfoResponse getMessageInfo(MandrillMessageInfoRequest messageInfoRequest) throws RequestFailedException {
51 | MessageInfoResponse response = (MessageInfoResponse)request.postRequest(messageInfoRequest, ServiceMethods.Messages.INFO, MessageInfoResponse.class);
52 | return response;
53 | }
54 |
55 | public void setRequest(MandrillRESTRequest request) {
56 | this.request = request;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillRESTRequest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.request;
2 |
3 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
4 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
5 | import com.cribbstechnologies.clients.mandrill.model.MandrillError;
6 | import com.cribbstechnologies.clients.mandrill.model.ServiceMethods;
7 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
8 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
9 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillStringResponse;
10 | import com.cribbstechnologies.clients.mandrill.util.MandrillConfiguration;
11 | import com.fasterxml.jackson.core.JsonGenerationException;
12 | import com.fasterxml.jackson.core.JsonParseException;
13 | import com.fasterxml.jackson.core.type.TypeReference;
14 | import com.fasterxml.jackson.databind.JsonMappingException;
15 | import com.fasterxml.jackson.databind.ObjectMapper;
16 | import java.io.BufferedReader;
17 | import java.io.IOException;
18 | import java.io.InputStreamReader;
19 | import java.net.MalformedURLException;
20 | import java.util.List;
21 | import org.apache.http.HttpResponse;
22 | import org.apache.http.client.HttpClient;
23 | import org.apache.http.client.methods.HttpPost;
24 | import org.apache.http.entity.StringEntity;
25 | import org.apache.http.util.EntityUtils;
26 |
27 | public class MandrillRESTRequest {
28 |
29 | private MandrillConfiguration config;
30 | private HttpClient httpClient;
31 | private ObjectMapper objectMapper;
32 |
33 | public BaseMandrillResponse postRequest(BaseMandrillRequest request, String serviceMethod, Object responseClass) throws RequestFailedException {
34 | return performPostRequest(request, serviceMethod, responseClass, null);
35 | }
36 |
37 | public BaseMandrillResponse postRequest(BaseMandrillRequest request, String serviceMethod, Object responseClass, TypeReference reference) throws RequestFailedException {
38 | return performPostRequest(request, serviceMethod, responseClass, reference);
39 | }
40 |
41 | private BaseMandrillResponse performPostRequest(BaseMandrillRequest request, String serviceMethod, Object responseClass, TypeReference reference) throws RequestFailedException {
42 | try {
43 | request.setKey(config.getApiKey());
44 | HttpPost postRequest = new HttpPost(config.getServiceUrl() + serviceMethod);
45 | String postData = getPostData(request);
46 | StringEntity input = new StringEntity(postData, "UTF-8");
47 | input.setContentType("application/json");
48 | postRequest.setEntity(input);
49 |
50 | HttpResponse response = httpClient.execute(postRequest);
51 |
52 |
53 | BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
54 |
55 | StringBuffer sb = new StringBuffer();
56 | String output;
57 | // System.out.println("Output from Server .... \n");
58 | while ((output = br.readLine()) != null) {
59 | sb.append(output);
60 | // System.out.println(output);
61 | }
62 |
63 | String responseString = sb.toString();
64 | EntityUtils.consume(response.getEntity());
65 | if (response.getStatusLine().getStatusCode() != 200) {
66 | //throw new RequestFailedException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode() + " " + responseString);
67 | throw new RequestFailedException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode() + " " + responseString, objectMapper.readValue(responseString, MandrillError.class));
68 | }
69 |
70 | // for whatever reason the ping response isn't well-formed
71 | if (ServiceMethods.Users.PING.equals(serviceMethod) && responseString.indexOf("PONG!") > -1) {
72 | return new BaseMandrillStringResponse(responseString);
73 | }
74 |
75 | if (reference == null) {
76 | return convertResponseData(responseString, responseClass);
77 | } else {
78 | return convertAnonymousListResponseData(responseString, responseClass, reference);
79 | }
80 | } catch (MalformedURLException mURLE) {
81 | throw new RequestFailedException("Malformed url", mURLE);
82 | } catch (JsonGenerationException jge) {
83 | throw new RequestFailedException("Json Generation Exception", jge);
84 | } catch (JsonMappingException jme) {
85 | throw new RequestFailedException("Json Mapping Exception", jme);
86 | } catch (IOException ioe) {
87 | throw new RequestFailedException("IOException", ioe);
88 | }
89 | }
90 |
91 | /**
92 | * This method will use the Jackson ObjectMapper to generate Mandrill API compatible JSON
93 | *
94 | * @param request
95 | * one of @see com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest, @see
96 | * com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail, @see
97 | * com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithQuery, @see
98 | * com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithTag, @see
99 | * com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithUrl
100 | * @return a JSON @see java.lang.String
101 | * @throws IOException
102 | * @throws JsonMappingException
103 | * @throws JsonGenerationException
104 | */
105 | protected String getPostData(BaseMandrillRequest request) throws JsonGenerationException, JsonMappingException, IOException {
106 | return objectMapper.writeValueAsString(request);
107 | }
108 |
109 | protected BaseMandrillResponse convertResponseData(String response, Object responseClass) throws JsonParseException, JsonMappingException, IOException {
110 | return objectMapper.readValue(response, (Class) responseClass);
111 | }
112 |
113 | protected BaseMandrillResponse convertAnonymousListResponseData(String json, Object responseClass, TypeReference reference) throws JsonParseException, JsonMappingException,
114 | IOException {
115 | BaseMandrillAnonymousListResponse response = new BaseMandrillAnonymousListResponse();
116 | List objectList = objectMapper.readValue(json, reference);
117 | response.setList(objectList);
118 | return response;
119 | }
120 |
121 | public void setConfig(MandrillConfiguration config) {
122 | this.config = config;
123 | }
124 |
125 | public void setHttpClient(HttpClient httpClient) {
126 | this.httpClient = httpClient;
127 | }
128 |
129 | public void setObjectMapper(ObjectMapper objectMapper) {
130 | this.objectMapper = objectMapper;
131 | }
132 |
133 | }
134 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillTagsRequest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.request;
2 |
3 | import java.util.List;
4 |
5 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
6 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
7 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithTag;
8 | import com.cribbstechnologies.clients.mandrill.model.ServiceMethods;
9 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
10 | import com.cribbstechnologies.clients.mandrill.model.response.tags.BaseTag;
11 | import com.cribbstechnologies.clients.mandrill.model.response.tags.TagListResponse;
12 | import com.cribbstechnologies.clients.mandrill.model.response.tags.TagSeriesResponse;
13 | import com.cribbstechnologies.clients.mandrill.model.response.tags.TagWithTime;
14 | import com.fasterxml.jackson.core.type.TypeReference;
15 |
16 | public class MandrillTagsRequest {
17 |
18 | MandrillRESTRequest request;
19 |
20 | TypeReference> timeTagReference = new TypeReference>() {
21 | };
22 | TypeReference> nameTagReference = new TypeReference>() {
23 | };
24 |
25 | public TagListResponse getList(BaseMandrillRequest tagsRequest) throws RequestFailedException {
26 | TagListResponse response = new TagListResponse();
27 | response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(tagsRequest, ServiceMethods.Tags.LIST, TagListResponse.class, nameTagReference))
28 | .getList());
29 | return response;
30 | }
31 |
32 | public TagSeriesResponse getTimeSeries(MandrillRequestWithTag tagsRequest) throws RequestFailedException {
33 | TagSeriesResponse response = new TagSeriesResponse();
34 | response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(tagsRequest, ServiceMethods.Tags.TIME_SERIES, TagSeriesResponse.class,
35 | timeTagReference)).getList());
36 | return response;
37 | }
38 |
39 | public TagSeriesResponse getAllTimeSeries(BaseMandrillRequest tagsRequest) throws RequestFailedException {
40 | TagSeriesResponse response = new TagSeriesResponse();
41 | response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(tagsRequest, ServiceMethods.Tags.ALL_TIME_SERIES, TagSeriesResponse.class,
42 | timeTagReference)).getList());
43 | return response;
44 | }
45 |
46 | public void setRequest(MandrillRESTRequest request) {
47 | this.request = request;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillTemplatesRequest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.request;
2 |
3 | import java.util.List;
4 |
5 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
6 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
7 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithCode;
8 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithName;
9 | import com.cribbstechnologies.clients.mandrill.model.MandrillTemplatedMessageRequest;
10 | import com.cribbstechnologies.clients.mandrill.model.ServiceMethods;
11 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
12 | import com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateListResponse;
13 | import com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateRenderResponse;
14 | import com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse;
15 | import com.fasterxml.jackson.core.type.TypeReference;
16 |
17 | public class MandrillTemplatesRequest {
18 |
19 | MandrillRESTRequest request;
20 |
21 | TypeReference> templatesListReference = new TypeReference>() {
22 | };
23 |
24 | public TemplateResponse addTemplate(MandrillRequestWithCode addRequest) throws RequestFailedException {
25 | return (TemplateResponse) request.postRequest(addRequest, ServiceMethods.Templates.ADD, TemplateResponse.class);
26 | }
27 |
28 | public TemplateResponse getTemplateInfo(MandrillRequestWithName infoRequest) throws RequestFailedException {
29 | return (TemplateResponse) request.postRequest(infoRequest, ServiceMethods.Templates.INFO, TemplateResponse.class);
30 | }
31 |
32 | public TemplateResponse updateTemplate(MandrillRequestWithCode updateRequest) throws RequestFailedException {
33 | return (TemplateResponse) request.postRequest(updateRequest, ServiceMethods.Templates.UPDATE, TemplateResponse.class);
34 | }
35 |
36 | public TemplateResponse deleteTemplate(MandrillRequestWithName deleteRequest) throws RequestFailedException {
37 | return (TemplateResponse) request.postRequest(deleteRequest, ServiceMethods.Templates.DELETE, TemplateResponse.class);
38 | }
39 |
40 | public TemplateListResponse getTemplates(BaseMandrillRequest listRequest) throws RequestFailedException {
41 | TemplateListResponse response = new TemplateListResponse();
42 | response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(listRequest, ServiceMethods.Templates.LIST, TemplateResponse.class,
43 | templatesListReference)).getList());
44 | return response;
45 | }
46 |
47 | public TemplateRenderResponse renderTemplate(MandrillTemplatedMessageRequest templatedMessageRequest) throws RequestFailedException {
48 | return (TemplateRenderResponse) request.postRequest(templatedMessageRequest, ServiceMethods.Templates.RENDER, TemplateRenderResponse.class);
49 | }
50 |
51 | public void setRequest(MandrillRESTRequest request) {
52 | this.request = request;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillUrlsRequest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.request;
2 |
3 | import java.util.List;
4 |
5 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
6 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
7 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithQuery;
8 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithUrl;
9 | import com.cribbstechnologies.clients.mandrill.model.ServiceMethods;
10 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
11 | import com.cribbstechnologies.clients.mandrill.model.response.urls.UrlListResponse;
12 | import com.cribbstechnologies.clients.mandrill.model.response.urls.UrlResponse;
13 | import com.fasterxml.jackson.core.type.TypeReference;
14 |
15 | public class MandrillUrlsRequest {
16 |
17 | MandrillRESTRequest request;
18 |
19 | TypeReference> urlsListReference = new TypeReference>() {
20 | };
21 |
22 | public UrlListResponse getList(BaseMandrillRequest listRequest) throws RequestFailedException {
23 | UrlListResponse response = new UrlListResponse();
24 | response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(listRequest, ServiceMethods.Urls.LIST, UrlListResponse.class, urlsListReference))
25 | .getList());
26 | return response;
27 | }
28 |
29 | public UrlListResponse doSearch(MandrillRequestWithQuery searchRequest) throws RequestFailedException {
30 | UrlListResponse response = new UrlListResponse();
31 | response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(searchRequest, ServiceMethods.Urls.SEARCH, UrlListResponse.class, urlsListReference))
32 | .getList());
33 | return response;
34 | }
35 |
36 | public UrlListResponse getTimeSeries(MandrillRequestWithUrl seriesRequest) throws RequestFailedException {
37 | UrlListResponse response = new UrlListResponse();
38 | response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(seriesRequest, ServiceMethods.Urls.TIME_SERIES, UrlListResponse.class,
39 | urlsListReference)).getList());
40 | return response;
41 | }
42 |
43 | public void setRequest(MandrillRESTRequest request) {
44 | this.request = request;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillUsersRequest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.request;
2 |
3 | import java.util.List;
4 |
5 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
6 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
7 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithDomain;
8 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail;
9 | import com.cribbstechnologies.clients.mandrill.model.ServiceMethods;
10 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
11 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
12 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillStringResponse;
13 | import com.cribbstechnologies.clients.mandrill.model.response.users.DisableResponse;
14 | import com.cribbstechnologies.clients.mandrill.model.response.users.MandrillSender;
15 | import com.cribbstechnologies.clients.mandrill.model.response.users.PingResponse;
16 | import com.cribbstechnologies.clients.mandrill.model.response.users.UsersInfoResponse;
17 | import com.cribbstechnologies.clients.mandrill.model.response.users.UsersSendersResponse;
18 | import com.cribbstechnologies.clients.mandrill.model.response.users.VerifyResponse;
19 | import com.fasterxml.jackson.core.type.TypeReference;
20 |
21 | /**
22 | *
23 | * This class holds various functions for the Mandrill Users API.
24 | *
25 | * @author Brian Cribbs, brian@cribbstechnologies.com
26 | *
27 | */
28 | public class MandrillUsersRequest {
29 |
30 | MandrillRESTRequest request;
31 |
32 | TypeReference> usersListReference = new TypeReference>() {
33 | };
34 |
35 | /**
36 | * Return the information about the API-connected user
37 | *
38 | * @param infoRequest
39 | * a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest
40 | * @throws RequestFailedException
41 | */
42 | public UsersInfoResponse getInfo(BaseMandrillRequest infoRequest) throws RequestFailedException {
43 | BaseMandrillResponse response = request.postRequest(infoRequest, ServiceMethods.Users.INFO, UsersInfoResponse.class);
44 | return (UsersInfoResponse) response;
45 | }
46 |
47 | /**
48 | * Validate an API key and respond to a ping
49 | *
50 | * @param pingRequest
51 | * a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest
52 | * @throws RequestFailedException
53 | */
54 | public BaseMandrillStringResponse performPing(BaseMandrillRequest pingRequest) throws RequestFailedException {
55 | BaseMandrillStringResponse response = (BaseMandrillStringResponse) request.postRequest(pingRequest, ServiceMethods.Users.PING, null);
56 | return response;
57 | }
58 |
59 | /**
60 | * Validate an API key and respond to a ping, this uses actually formatted JSON response
61 | *
62 | * @param pingRequest
63 | * a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest
64 | * @throws RequestFailedException
65 | */
66 | public PingResponse performPing2(BaseMandrillRequest pingRequest) throws RequestFailedException {
67 | PingResponse response = (PingResponse) request.postRequest(pingRequest, ServiceMethods.Users.PING2, null);
68 | return response;
69 | }
70 |
71 | /**
72 | * Return the senders that have tried to use this account, both verified and unverified
73 | *
74 | * @param sendersRequest
75 | * a populated @see com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest
76 | * @throws RequestFailedException
77 | */
78 | public UsersSendersResponse getSenders(BaseMandrillRequest sendersRequest) throws RequestFailedException {
79 | UsersSendersResponse response = new UsersSendersResponse();
80 | response.setList(((BaseMandrillAnonymousListResponse) request.postRequest(sendersRequest, ServiceMethods.Users.SENDERS, UsersSendersResponse.class,
81 | usersListReference)).getList());
82 | return response;
83 | }
84 |
85 | /**
86 | * Disable a sender from being able to send
87 | *
88 | * @param disableRequest
89 | * a populated @see com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail
90 | * @throws RequestFailedException
91 | */
92 | @Deprecated
93 | public DisableResponse disableSender(MandrillRequestWithDomain disableRequest) throws RequestFailedException {
94 | return (DisableResponse) request.postRequest(disableRequest, ServiceMethods.Users.DISABLE_SENDER, DisableResponse.class);
95 | }
96 |
97 | /**
98 | * Send an email to the given address to verify that it is an accepted sender for your Mandrill account
99 | *
100 | * @param verifyRequest
101 | * a populated @see com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail
102 | * @throws RequestFailedException
103 | */
104 | @Deprecated
105 | public VerifyResponse verifySender(MandrillRequestWithEmail verifyRequest) throws RequestFailedException {
106 | return (VerifyResponse) request.postRequest(verifyRequest, ServiceMethods.Users.VERIFY_SENDER, VerifyResponse.class);
107 | }
108 |
109 | public void setRequest(MandrillRESTRequest request) {
110 | this.request = request;
111 | }
112 |
113 | public TypeReference> getUsersListReference() {
114 | return usersListReference;
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/util/MandrillConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.util;
2 |
3 | public class MandrillConfiguration {
4 |
5 | private String apiVersion;
6 | private String baseURL;
7 | private String apiKey;
8 |
9 | public String getApiKey() {
10 | return apiKey;
11 | }
12 |
13 | public void setApiKey(String apiKey) {
14 | this.apiKey = apiKey;
15 | }
16 |
17 | public void setApiVersion(String apiVersion) {
18 | this.apiVersion = apiVersion;
19 | }
20 |
21 | public void setBaseURL(String baseURL) {
22 | this.baseURL = baseURL;
23 | }
24 |
25 | public String getServiceUrl() {
26 | StringBuffer sb = new StringBuffer();
27 | sb.append(baseURL);
28 | sb.append("/");
29 | sb.append(apiVersion);
30 | sb.append("/");
31 | return sb.toString();
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/cribbstechnologies/clients/mandrill/util/MandrillSimpleDateFormat.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.util;
2 |
3 | import java.text.SimpleDateFormat;
4 |
5 | /**
6 | * Mandrill date objects are in the format of "2012-03-03 17:58:56"
7 | *
8 | * The classes within this client jar will always return dates as Strings. This class can be used to
9 | * convert them to/from proper Date objects.
10 | * @author Brian Cribbs
11 | *
12 | */
13 | public class MandrillSimpleDateFormat extends SimpleDateFormat {
14 |
15 | /**
16 | *
17 | */
18 | private static final long serialVersionUID = -8742099030724331039L;
19 |
20 | public MandrillSimpleDateFormat() {
21 | super("yyyy-MM-dd kk:mm:ss");
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/resources/spring/mandrillConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/test/java/com/cribbstechnologies/clients/mandrill/request/MandrillRESTRequestTest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.request;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.assertTrue;
6 | import static org.junit.Assert.fail;
7 | import static org.mockito.Matchers.isA;
8 | import static org.mockito.Mockito.doReturn;
9 | import static org.mockito.Mockito.doThrow;
10 | import static org.mockito.MockitoAnnotations.initMocks;
11 |
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 | import java.io.StringWriter;
15 | import java.net.MalformedURLException;
16 | import java.util.HashMap;
17 | import java.util.List;
18 | import java.util.Map;
19 |
20 | import org.apache.commons.io.IOUtils;
21 | import org.apache.http.HttpEntity;
22 | import org.apache.http.HttpResponse;
23 | import org.apache.http.StatusLine;
24 | import org.apache.http.client.ClientProtocolException;
25 | import org.apache.http.client.HttpClient;
26 | import org.apache.http.client.methods.HttpPost;
27 | import org.apache.http.conn.ClientConnectionManager;
28 | import org.junit.Before;
29 | import org.junit.Test;
30 | import org.mockito.Mock;
31 | import org.mockito.Mockito;
32 |
33 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
34 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
35 | import com.cribbstechnologies.clients.mandrill.model.MandrillHtmlMessage;
36 | import com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest;
37 | import com.cribbstechnologies.clients.mandrill.model.MandrillRecipient;
38 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithDomain;
39 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithQuery;
40 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithTag;
41 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithUrl;
42 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse;
43 | import com.cribbstechnologies.clients.mandrill.model.response.StatsResponse;
44 | import com.cribbstechnologies.clients.mandrill.model.response.message.MessageResponse;
45 | import com.cribbstechnologies.clients.mandrill.model.response.message.SendMessageResponse;
46 | import com.cribbstechnologies.clients.mandrill.model.response.tags.BaseTag;
47 | import com.cribbstechnologies.clients.mandrill.model.response.tags.TagListResponse;
48 | import com.cribbstechnologies.clients.mandrill.model.response.tags.TagSeriesResponse;
49 | import com.cribbstechnologies.clients.mandrill.model.response.tags.TagWithTime;
50 | import com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse;
51 | import com.cribbstechnologies.clients.mandrill.model.response.urls.TimeUrlResponse;
52 | import com.cribbstechnologies.clients.mandrill.model.response.urls.UrlListResponse;
53 | import com.cribbstechnologies.clients.mandrill.model.response.urls.UrlResponse;
54 | import com.cribbstechnologies.clients.mandrill.model.response.urls.UrlTimeResponse;
55 | import com.cribbstechnologies.clients.mandrill.model.response.users.DisableResponse;
56 | import com.cribbstechnologies.clients.mandrill.model.response.users.MandrillSender;
57 | import com.cribbstechnologies.clients.mandrill.model.response.users.UsersInfoResponse;
58 | import com.cribbstechnologies.clients.mandrill.model.response.users.UsersSendersResponse;
59 | import com.cribbstechnologies.clients.mandrill.util.MandrillConfiguration;
60 | import com.fasterxml.jackson.core.JsonGenerationException;
61 | import com.fasterxml.jackson.core.JsonParseException;
62 | import com.fasterxml.jackson.core.JsonProcessingException;
63 | import com.fasterxml.jackson.core.type.TypeReference;
64 | import com.fasterxml.jackson.databind.JsonMappingException;
65 | import com.fasterxml.jackson.databind.ObjectMapper;
66 |
67 | public class MandrillRESTRequestTest {
68 |
69 | MandrillRESTRequest request;
70 | @Mock
71 | ObjectMapper mapper;
72 | @Mock
73 | HttpClient client;
74 | @Mock
75 | ClientConnectionManager manager;
76 | @Mock
77 | HttpEntity entity;
78 | @Mock
79 | HttpResponse response;
80 | @Mock
81 | StatusLine statusLine;
82 | MandrillConfiguration config = new MandrillConfiguration();
83 |
84 | BaseMandrillRequest emptyBaseRequest = new BaseMandrillRequest();
85 | BaseMandrillRequest mutableBaseRequest;
86 |
87 | MandrillRequestWithDomain emptyEmailRequest = new MandrillRequestWithDomain();
88 | MandrillRequestWithDomain mutableEmailRequest = new MandrillRequestWithDomain();
89 |
90 | MandrillRequestWithQuery emptyQueryRequest = new MandrillRequestWithQuery();
91 | MandrillRequestWithQuery mutableQueryRequest;
92 |
93 | MandrillRequestWithTag emptyTagRequest = new MandrillRequestWithTag();
94 | MandrillRequestWithTag mutableTagRequest;
95 |
96 | MandrillRequestWithUrl emptyUrlRequest = new MandrillRequestWithUrl();
97 | MandrillRequestWithUrl mutableUrlRequest;
98 |
99 | MandrillMessageRequest emptyMessageRequest = new MandrillMessageRequest();
100 | MandrillHtmlMessage emptyMessage;
101 |
102 | MandrillMessageRequest mutableMessageRequest = new MandrillMessageRequest();
103 | MandrillHtmlMessage mutableMessage;
104 |
105 | @Before
106 | public void before() {
107 | initMocks(this);
108 | this.config.setApiVersion("1.0");
109 | this.config.setBaseURL("https://mandrillapp.com/api");
110 | }
111 |
112 | private void initRequestWithActualMapper() {
113 | this.request = new MandrillRESTRequest();
114 | this.request.setObjectMapper(new ObjectMapper());
115 | }
116 |
117 | private void initRequestWithMockedMapper() {
118 | this.request = new MandrillRESTRequest();
119 | this.request.setObjectMapper(this.mapper);
120 | }
121 |
122 | @Test
123 | public void testDisableResponseConversion() throws IOException {
124 | this.initRequestWithActualMapper();
125 |
126 | StringWriter sw = new StringWriter();
127 | IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("users/disableSenderResponse.txt"), sw);
128 | DisableResponse response = (DisableResponse) this.request.convertResponseData(sw.toString(), DisableResponse.class);
129 |
130 | assertEquals("example domain", response.getDomain());
131 | assertEquals("example created_at", response.getCreated_at());
132 | assertEquals("example approved_at", response.getApproved_at());
133 | assertTrue(response.isIs_enabled());
134 | }
135 |
136 | @Test
137 | public void testGetPostDataBaseMandrillRequest() throws Exception {
138 | this.initRequestWithActualMapper();
139 |
140 | assertEquals("{\"key\":null}", this.request.getPostData(this.emptyBaseRequest));
141 | this.mutableBaseRequest = new BaseMandrillRequest();
142 | this.mutableBaseRequest.setKey("this is my key");
143 | assertEquals("{\"key\":\"this is my key\"}", this.request.getPostData(this.mutableBaseRequest));
144 |
145 | this.mutableBaseRequest.setKey("this is my key with \"extra\" quotes");
146 | assertEquals("{\"key\":\"this is my key with \\\"extra\\\" quotes\"}", this.request.getPostData(this.mutableBaseRequest));
147 |
148 | }
149 |
150 | @Test
151 | public void testGetPostDataJsonGenerationException() throws Exception {
152 | this.initRequestWithMockedMapper();
153 |
154 | Mockito.when(this.mapper.writeValueAsString(this.emptyBaseRequest)).thenThrow(new JsonGenerationException("Mockito!"));
155 | try {
156 | this.request.getPostData(this.emptyBaseRequest);
157 | fail("Exception not thrown");
158 | } catch (JsonGenerationException jge) {
159 | assertEquals("Mockito!", jge.getMessage());
160 | }
161 | }
162 |
163 | @Test
164 | public void testGetPostDataJsonMappingException() throws Exception {
165 | this.initRequestWithMockedMapper();
166 |
167 | Mockito.when(this.mapper.writeValueAsString(this.emptyBaseRequest)).thenThrow(new JsonMappingException("Mockito!"));
168 | try {
169 | this.request.getPostData(this.emptyBaseRequest);
170 | } catch (JsonMappingException jme) {
171 | assertEquals("Mockito!", jme.getMessage());
172 | }
173 | }
174 |
175 | @Test
176 | public void testGetPostDataMandrillMessageRequest() throws Exception {
177 | this.initRequestWithActualMapper();
178 |
179 | this.emptyMessageRequest.setMessage(this.emptyMessage);
180 | assertEquals("{\"key\":null,\"message\":null}", this.request.getPostData(this.emptyMessageRequest));
181 |
182 | this.mutableMessageRequest = new MandrillMessageRequest();
183 | this.mutableMessageRequest.setKey("API Key");
184 | this.mutableMessage = new MandrillHtmlMessage();
185 | this.mutableMessage.setHtml("Test html");
186 | this.mutableMessage.setText("Test text");
187 | this.mutableMessage.setSubject("Test subject");
188 | this.mutableMessage.setFrom_email("from@email.com");
189 | this.mutableMessage.setFrom_name("From Name");
190 | this.mutableMessage.setSubaccount("test");
191 | MandrillRecipient[] to = new MandrillRecipient[2];
192 | to[0] = new MandrillRecipient("to1", "to1");
193 | to[1] = new MandrillRecipient("to2", "to2");
194 | this.mutableMessage.setTo(to);
195 | this.mutableMessage.setTrack_opens(false);
196 | this.mutableMessage.setTrack_clicks(true);
197 | String[] tags = new String[2];
198 | tags[0] = "tag1";
199 | tags[1] = "tag2";
200 | this.mutableMessage.setTags(tags);
201 | Map headerMap = new HashMap();
202 | headerMap.put("headerName", "headerValue");
203 |
204 | this.mutableMessage.setHeaders(headerMap);
205 |
206 | this.mutableMessageRequest.setMessage(this.mutableMessage);
207 | // System.out.println(request.getPostData(mutableMessageRequest));
208 | StringBuffer sb = new StringBuffer();
209 | sb.append("{");
210 | sb.append("\"key\":\"API Key\"");
211 | sb.append(",\"message\":{");
212 | sb.append("\"text\":\"Test text\"");
213 | sb.append(",\"subject\":\"Test subject\"");
214 | sb.append(",\"from_email\":\"from@email.com\"");
215 | sb.append(",\"from_name\":\"From Name\"");
216 | sb.append(",\"subaccount\":\"test\"");
217 | sb.append(",\"to\":[{\"email\":\"to1\",\"name\":\"to1\"},{\"email\":\"to2\",\"name\":\"to2\"}]");
218 | sb.append(",\"bcc_address\":null");
219 | sb.append(",\"track_opens\":false");
220 | sb.append(",\"track_clicks\":true");
221 | sb.append(",\"auto_text\":false");
222 | sb.append(",\"url_strip_qs\":false");
223 | sb.append(",\"preserve_recipients\":false");
224 | sb.append(",\"tags\":[\"tag1\",\"tag2\"]");
225 | sb.append(",\"google_analytics_domains\":[]");
226 | sb.append(",\"google_analytics_campaign\":[]");
227 | sb.append(",\"global_merge_vars\":null");
228 | sb.append(",\"merge_vars\":null");
229 | sb.append(",\"attachments\":null");
230 | sb.append(",\"important\":false");
231 | sb.append(",\"auto_html\":false");
232 | sb.append(",\"inline_css\":false");
233 | sb.append(",\"merge\":false");
234 | sb.append(",\"merge_language\":null");
235 | sb.append(",\"metadata\":null");
236 | sb.append(",\"recipient_metadata\":null");
237 | sb.append(",\"headers\":{\"headerName\":\"headerValue\"},");
238 | sb.append("\"html\":\"Test html\"");
239 | sb.append("}}");
240 | String output = this.request.getPostData(this.mutableMessageRequest);
241 | System.out.println("Comparing:\n" + sb.toString() + "\n" + output);
242 | assertEquals(sb.toString(), output);
243 | }
244 |
245 | @Test
246 | public void testGetPostDataMandrillMessageRequestWithBCC() throws Exception {
247 | initRequestWithActualMapper();
248 |
249 | emptyMessageRequest.setMessage(emptyMessage);
250 | assertEquals("{\"key\":null,\"message\":null}", request.getPostData(emptyMessageRequest));
251 |
252 | mutableMessageRequest = new MandrillMessageRequest();
253 | mutableMessageRequest.setKey("API Key");
254 | mutableMessage = new MandrillHtmlMessage();
255 | mutableMessage.setHtml("Test html");
256 | mutableMessage.setText("Test text");
257 | mutableMessage.setSubject("Test subject");
258 | mutableMessage.setFrom_email("from@email.com");
259 | mutableMessage.setFrom_name("From Name");
260 | MandrillRecipient[] to = new MandrillRecipient[2];
261 | to[0] = new MandrillRecipient("to1", "to1");
262 | to[1] = new MandrillRecipient("to2", "to2");
263 | mutableMessage.setTo(to);
264 | mutableMessage.setBcc_address("bcc@email.com");
265 | mutableMessage.setTrack_opens(false);
266 | mutableMessage.setTrack_clicks(true);
267 | String[] tags = new String[2];
268 | tags[0] = "tag1";
269 | tags[1] = "tag2";
270 | mutableMessage.setTags(tags);
271 | Map headerMap = new HashMap();
272 | headerMap.put("headerName", "headerValue");
273 |
274 | mutableMessage.setHeaders(headerMap);
275 |
276 | mutableMessageRequest.setMessage(mutableMessage);
277 | // System.out.println(request.getPostData(mutableMessageRequest));
278 | StringBuffer sb = new StringBuffer();
279 | sb.append("{");
280 | sb.append("\"key\":\"API Key\"");
281 | sb.append(",\"message\":{");
282 | sb.append("\"text\":\"Test text\"");
283 | sb.append(",\"subject\":\"Test subject\"");
284 | sb.append(",\"from_email\":\"from@email.com\"");
285 | sb.append(",\"from_name\":\"From Name\"");
286 | sb.append(",\"subaccount\":null");
287 | sb.append(",\"to\":[{\"email\":\"to1\",\"name\":\"to1\"},{\"email\":\"to2\",\"name\":\"to2\"}]");
288 | sb.append(",\"bcc_address\":\"bcc@email.com\"");
289 | sb.append(",\"track_opens\":false");
290 | sb.append(",\"track_clicks\":true");
291 | sb.append(",\"auto_text\":false");
292 | sb.append(",\"url_strip_qs\":false");
293 | sb.append(",\"preserve_recipients\":false");
294 | sb.append(",\"tags\":[\"tag1\",\"tag2\"]");
295 | sb.append(",\"google_analytics_domains\":[]");
296 | sb.append(",\"google_analytics_campaign\":[]");
297 | sb.append(",\"global_merge_vars\":null");
298 | sb.append(",\"merge_vars\":null");
299 | sb.append(",\"attachments\":null");
300 | sb.append(",\"important\":false");
301 | sb.append(",\"auto_html\":false");
302 | sb.append(",\"inline_css\":false");
303 | sb.append(",\"merge\":false");
304 | sb.append(",\"merge_language\":null");
305 | sb.append(",\"metadata\":null");
306 | sb.append(",\"recipient_metadata\":null");
307 | sb.append(",\"headers\":{\"headerName\":\"headerValue\"},");
308 | sb.append("\"html\":\"Test html\"");
309 | sb.append("}}");
310 | String output = request.getPostData(mutableMessageRequest);
311 | System.out.println("Comparing:\n" + sb.toString() + "\n" + output);
312 | assertEquals(sb.toString(), output);
313 | }
314 |
315 | @Test
316 | public void testGetPostDataMandrillRequestWithEmail() throws Exception {
317 | this.initRequestWithActualMapper();
318 |
319 | assertEquals("{\"key\":null,\"domain\":null}", this.request.getPostData(this.emptyEmailRequest));
320 | this.mutableEmailRequest = new MandrillRequestWithDomain();
321 | this.mutableEmailRequest.setKey("12345");
322 | this.mutableEmailRequest.setDomain("email@email.com");
323 | assertEquals("{\"key\":\"12345\",\"domain\":\"email@email.com\"}", this.request.getPostData(this.mutableEmailRequest));
324 | }
325 |
326 | @Test
327 | public void testGetPostDataMandrillRequestWithQuery() throws Exception {
328 | this.initRequestWithActualMapper();
329 |
330 | assertEquals("{\"key\":null,\"q\":null}", this.request.getPostData(this.emptyQueryRequest));
331 | this.mutableQueryRequest = new MandrillRequestWithQuery();
332 | this.mutableQueryRequest.setKey("7890");
333 | this.mutableQueryRequest.setQ("query string");
334 | assertEquals("{\"key\":\"7890\",\"q\":\"query string\"}", this.request.getPostData(this.mutableQueryRequest));
335 | }
336 |
337 | @Test
338 | public void testGetPostDataMandrillRequestWithTag() throws Exception {
339 | this.initRequestWithActualMapper();
340 |
341 | assertEquals("{\"key\":null,\"tag\":null}", this.request.getPostData(this.emptyTagRequest));
342 | this.mutableTagRequest = new MandrillRequestWithTag();
343 | this.mutableTagRequest.setKey("ABC");
344 | this.mutableTagRequest.setTag("Tag, you're it");
345 | assertEquals("{\"key\":\"ABC\",\"tag\":\"Tag, you're it\"}", this.request.getPostData(this.mutableTagRequest));
346 | }
347 |
348 | @Test
349 | public void testGetPostDataMandrillRequestWithUrl() throws Exception {
350 | this.initRequestWithActualMapper();
351 |
352 | assertEquals("{\"key\":null,\"url\":null}", this.request.getPostData(this.emptyUrlRequest));
353 | this.mutableUrlRequest = new MandrillRequestWithUrl();
354 | this.mutableUrlRequest.setKey("TEST");
355 | this.mutableUrlRequest.setUrl("http://www.google.com");
356 | assertEquals("{\"key\":\"TEST\",\"url\":\"http://www.google.com\"}", this.request.getPostData(this.mutableUrlRequest));
357 | }
358 |
359 | @Test
360 | public void testListTagsResponseConversion() throws IOException {
361 | this.initRequestWithActualMapper();
362 |
363 | StringWriter sw = new StringWriter();
364 | IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("tags/listResponse.txt"), sw);
365 | TypeReference tagListReference = new TypeReference>() {
366 | };
367 | BaseMandrillAnonymousListResponse response = (BaseMandrillAnonymousListResponse) this.request.convertAnonymousListResponseData(sw.toString(),
368 | TagListResponse.class, tagListReference);
369 |
370 | assertEquals(2, response.getList().size());
371 |
372 | BaseTag tag = response.getList().get(0);
373 | assertEquals("example tag1", tag.getTag());
374 | assertEquals(1, tag.getSent());
375 | assertEquals(2, tag.getHard_bounces());
376 | assertEquals(3, tag.getSoft_bounces());
377 | assertEquals(4, tag.getRejects());
378 | assertEquals(5, tag.getComplaints());
379 | assertEquals(6, tag.getUnsubs());
380 | assertEquals(7, tag.getOpens());
381 | assertEquals(8, tag.getClicks());
382 |
383 | tag = response.getList().get(1);
384 | assertEquals("example tag11", tag.getTag());
385 | assertEquals(11, tag.getSent());
386 | assertEquals(12, tag.getHard_bounces());
387 | assertEquals(13, tag.getSoft_bounces());
388 | assertEquals(14, tag.getRejects());
389 | assertEquals(15, tag.getComplaints());
390 | assertEquals(16, tag.getUnsubs());
391 | assertEquals(17, tag.getOpens());
392 | assertEquals(18, tag.getClicks());
393 | }
394 |
395 | @Test
396 | public void testPostRequest() throws ClientProtocolException, IOException {
397 | this.request = new MandrillRESTRequest();
398 | this.request.setHttpClient(this.client);
399 | this.request.setConfig(this.config);
400 | this.request.setObjectMapper(new ObjectMapper());
401 |
402 | doThrow(new MalformedURLException("Mockito!")).when(this.client).execute(isA(HttpPost.class));
403 | try {
404 | this.request.postRequest(this.emptyBaseRequest, "test", null);
405 | fail("Exception not thrown");
406 | } catch (RequestFailedException e) {
407 | assertEquals("Malformed url", e.getMessage());
408 | }
409 |
410 | doThrow(new IOException("Mockito!")).when(this.client).execute(isA(HttpPost.class));
411 | try {
412 | this.request.postRequest(this.emptyBaseRequest, "test", null);
413 | fail("Exception not thrown");
414 | } catch (RequestFailedException e) {
415 | assertEquals("IOException", e.getMessage());
416 | }
417 | }
418 |
419 | @Test
420 | public void testPostRequestMapperExceptions() throws ClientProtocolException, IOException {
421 | this.request = new MandrillRESTRequest();
422 | this.request.setHttpClient(this.client);
423 | this.request.setConfig(this.config);
424 | this.request.setObjectMapper(this.mapper);
425 |
426 | doThrow(new JsonGenerationException("Mockito!")).when(this.mapper).writeValueAsString(isA(BaseMandrillRequest.class));
427 | try {
428 | this.request.postRequest(this.emptyBaseRequest, "test", null);
429 | fail("Exception not thrown");
430 | } catch (RequestFailedException e) {
431 | assertEquals("Json Generation Exception", e.getMessage());
432 | }
433 |
434 | doThrow(new JsonMappingException("Mockito!")).when(this.mapper).writeValueAsString(isA(BaseMandrillRequest.class));
435 | try {
436 | this.request.postRequest(this.emptyBaseRequest, "test", null);
437 | fail("Exception not thrown");
438 | } catch (RequestFailedException e) {
439 | assertEquals("Json Mapping Exception", e.getMessage());
440 | }
441 | }
442 |
443 | @Test
444 | public void testPostRequestNon200Response() {
445 | try {
446 | this.request = new MandrillRESTRequest();
447 | this.request.setHttpClient(this.client);
448 | this.request.setConfig(this.config);
449 | this.request.setObjectMapper(this.mapper);
450 |
451 | doReturn("postData").when(this.mapper).writeValueAsString(this.emptyBaseRequest);
452 | doReturn(this.response).when(this.client).execute(isA(HttpPost.class));
453 | doReturn(this.manager).when(this.client).getConnectionManager();
454 | Mockito.when(this.response.getEntity()).thenReturn(this.entity);
455 | InputStream inputStream = IOUtils.toInputStream("INPUT");
456 | Mockito.when(this.entity.getContent()).thenReturn(inputStream);
457 | Mockito.when(this.response.getStatusLine()).thenReturn(this.statusLine);
458 | Mockito.when(this.statusLine.getStatusCode()).thenReturn(500);
459 |
460 | this.request.postRequest(this.emptyBaseRequest, "Foo", null);
461 | } catch (RequestFailedException rfe) {
462 | assertEquals("Failed : HTTP error code : 500 INPUT", rfe.getMessage());
463 | } catch (ClientProtocolException e) {
464 | fail("Mockito is a good mocking framework, this shouldn't happen");
465 | } catch (IOException e) {
466 | fail("Mockito is a good mocking framework, this shouldn't happen");
467 | }
468 | }
469 |
470 | @Test
471 | public void testSendersResponseConversion() throws IOException {
472 | this.initRequestWithActualMapper();
473 |
474 | StringWriter sw = new StringWriter();
475 | IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("users/sendersResponse.txt"), sw);
476 | TypeReference usersListReference = new TypeReference>() {
477 | };
478 | BaseMandrillAnonymousListResponse response = (BaseMandrillAnonymousListResponse) this.request.convertAnonymousListResponseData(
479 | sw.toString(), UsersSendersResponse.class, usersListReference);
480 |
481 | assertEquals(2, response.getList().size());
482 |
483 | MandrillSender sender = response.getList().get(0);
484 | assertEquals("example address", sender.getAddress());
485 | assertEquals("example created_at", sender.getCreated_at());
486 | assertTrue(sender.getIs_enabled());
487 |
488 | sender = response.getList().get(1);
489 | assertEquals("example address2", sender.getAddress());
490 | assertEquals("example created_at2", sender.getCreated_at());
491 | assertFalse(sender.getIs_enabled());
492 | }
493 |
494 | @Test
495 | public void testSendMessageResponseConversion() throws IOException {
496 | this.initRequestWithActualMapper();
497 |
498 | StringWriter sw = new StringWriter();
499 | IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("messages/sendMessageResponse.txt"), sw);
500 | TypeReference responseListReference = new TypeReference>() {
501 | };
502 | BaseMandrillAnonymousListResponse response = (BaseMandrillAnonymousListResponse) this.request.convertAnonymousListResponseData(
503 | sw.toString(), SendMessageResponse.class, responseListReference);
504 |
505 | assertEquals(2, response.getList().size());
506 |
507 | MessageResponse resp = response.getList().get(0);
508 | assertEquals("example email", resp.getEmail());
509 | assertEquals("example status", resp.getStatus());
510 |
511 | resp = response.getList().get(1);
512 | assertEquals("example email2", resp.getEmail());
513 | assertEquals("example status2", resp.getStatus());
514 | }
515 |
516 | @Test
517 | public void testTemplateListResponseConversion() throws IOException {
518 | this.initRequestWithActualMapper();
519 |
520 | StringWriter sw = new StringWriter();
521 | IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("templates/templatesListResponse.txt"), sw);
522 | TypeReference templatesListReference = new TypeReference>() {
523 | };
524 | BaseMandrillAnonymousListResponse response = (BaseMandrillAnonymousListResponse) this.request.convertAnonymousListResponseData(
525 | sw.toString(), TemplateResponse.class, templatesListReference);
526 |
527 | assertEquals(2, response.getList().size());
528 | TemplateResponse tr = response.getList().get(0);
529 | assertEquals("example name1", tr.getName());
530 | assertEquals("example code1", tr.getCode());
531 | assertEquals("example created_at1", tr.getCreated_at());
532 | assertEquals("example updated_at1", tr.getUpdated_at());
533 |
534 | tr = response.getList().get(1);
535 | assertEquals("example name11", tr.getName());
536 | assertEquals("example code11", tr.getCode());
537 | assertEquals("example created_at11", tr.getCreated_at());
538 | assertEquals("example updated_at11", tr.getUpdated_at());
539 | }
540 |
541 | @Test
542 | public void testTemplateResponseConversion() throws IOException {
543 | this.initRequestWithActualMapper();
544 |
545 | StringWriter sw = new StringWriter();
546 | IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("templates/templateResponse.txt"), sw);
547 |
548 | TemplateResponse response = (TemplateResponse) this.request.convertResponseData(sw.toString(), TemplateResponse.class);
549 |
550 | assertEquals("example name", response.getName());
551 | assertEquals("example code", response.getCode());
552 | assertEquals("example created_at", response.getCreated_at());
553 | assertEquals("example updated_at", response.getUpdated_at());
554 | }
555 |
556 | @Test
557 | public void testTimeTagsResponseConversion() throws IOException {
558 | this.initRequestWithActualMapper();
559 |
560 | StringWriter sw = new StringWriter();
561 | IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("tags/timeSeriesResponse.txt"), sw);
562 | TypeReference tagListReference = new TypeReference>() {
563 | };
564 | BaseMandrillAnonymousListResponse response = (BaseMandrillAnonymousListResponse) this.request.convertAnonymousListResponseData(sw.toString(),
565 | TagSeriesResponse.class, tagListReference);
566 |
567 | assertEquals(2, response.getList().size());
568 |
569 | TagWithTime tag = response.getList().get(0);
570 | assertEquals("example time1", tag.getTime());
571 | assertEquals(2, tag.getSent());
572 | assertEquals(3, tag.getHard_bounces());
573 | assertEquals(4, tag.getSoft_bounces());
574 | assertEquals(5, tag.getRejects());
575 | assertEquals(6, tag.getComplaints());
576 | assertEquals(7, tag.getOpens());
577 | assertEquals(8, tag.getUnique_opens());
578 | assertEquals(9, tag.getClicks());
579 | assertEquals(10, tag.getUnique_clicks());
580 |
581 | tag = response.getList().get(1);
582 | assertEquals("example time11", tag.getTime());
583 | assertEquals(12, tag.getSent());
584 | assertEquals(13, tag.getHard_bounces());
585 | assertEquals(14, tag.getSoft_bounces());
586 | assertEquals(15, tag.getRejects());
587 | assertEquals(16, tag.getComplaints());
588 | assertEquals(17, tag.getOpens());
589 | assertEquals(18, tag.getUnique_opens());
590 | assertEquals(19, tag.getClicks());
591 | assertEquals(110, tag.getUnique_clicks());
592 | }
593 |
594 | @Test
595 | public void testUrlListResponseConversion() throws IOException {
596 | this.initRequestWithActualMapper();
597 |
598 | StringWriter sw = new StringWriter();
599 | IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("urls/urlList.txt"), sw);
600 | TypeReference urlListReference = new TypeReference>() {
601 | };
602 | BaseMandrillAnonymousListResponse response = (BaseMandrillAnonymousListResponse) this.request.convertAnonymousListResponseData(sw.toString(),
603 | UrlListResponse.class, urlListReference);
604 |
605 | assertEquals(2, response.getList().size());
606 |
607 | UrlResponse urlResponse = response.getList().get(0);
608 | assertEquals("example url1", urlResponse.getUrl());
609 | assertEquals(2, urlResponse.getSent());
610 | assertEquals(3, urlResponse.getClicks());
611 | assertEquals(4, urlResponse.getUnique_clicks());
612 |
613 | urlResponse = response.getList().get(1);
614 | assertEquals("example url11", urlResponse.getUrl());
615 | assertEquals(12, urlResponse.getSent());
616 | assertEquals(13, urlResponse.getClicks());
617 | assertEquals(14, urlResponse.getUnique_clicks());
618 | }
619 |
620 | @Test
621 | public void testUrlTimeResponseConversion() throws IOException {
622 | this.initRequestWithActualMapper();
623 |
624 | StringWriter sw = new StringWriter();
625 | IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("urls/urlTimeResponse.txt"), sw);
626 | TypeReference urlTimeReference = new TypeReference>() {
627 | };
628 | BaseMandrillAnonymousListResponse response = (BaseMandrillAnonymousListResponse) this.request.convertAnonymousListResponseData(
629 | sw.toString(), UrlTimeResponse.class, urlTimeReference);
630 |
631 | assertEquals(2, response.getList().size());
632 |
633 | TimeUrlResponse timeUrlResponse = response.getList().get(0);
634 | assertEquals("example time1", timeUrlResponse.getTime());
635 | assertEquals(2, timeUrlResponse.getSent());
636 | assertEquals(3, timeUrlResponse.getClicks());
637 | assertEquals(4, timeUrlResponse.getUnique_clicks());
638 |
639 | timeUrlResponse = response.getList().get(1);
640 | assertEquals("example time11", timeUrlResponse.getTime());
641 | assertEquals(12, timeUrlResponse.getSent());
642 | assertEquals(13, timeUrlResponse.getClicks());
643 | assertEquals(14, timeUrlResponse.getUnique_clicks());
644 | }
645 |
646 | @Test
647 | public void testUsersInfoResponseConversion() throws JsonParseException, JsonMappingException, IOException {
648 | this.initRequestWithActualMapper();
649 |
650 | StringWriter sw = new StringWriter();
651 | IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("users/infoResponse.txt"), sw);
652 | UsersInfoResponse myResponse = (UsersInfoResponse) this.request.convertResponseData(sw.toString(), UsersInfoResponse.class);
653 |
654 | assertEquals("example username", myResponse.getUsername());
655 | assertEquals("example created_at", myResponse.getCreated_at());
656 | assertEquals(42, myResponse.getReputation());
657 | assertEquals(32, myResponse.getHourly_quota());
658 |
659 | StatsResponse today = myResponse.getStats().getToday();
660 | assertEquals(1, today.getSent());
661 | assertEquals(2, today.getHard_bounces());
662 | assertEquals(3, today.getSoft_bounces());
663 | assertEquals(4, today.getRejects());
664 | assertEquals(5, today.getComplaints());
665 | assertEquals(6, today.getUnsubs());
666 | assertEquals(7, today.getOpens());
667 | assertEquals(8, today.getUnique_opens());
668 | assertEquals(9, today.getClicks());
669 | assertEquals(10, today.getUnique_clicks());
670 |
671 | StatsResponse last7 = myResponse.getStats().getLast_7_days();
672 | assertEquals(11, last7.getSent());
673 | assertEquals(12, last7.getHard_bounces());
674 | assertEquals(13, last7.getSoft_bounces());
675 | assertEquals(14, last7.getRejects());
676 | assertEquals(15, last7.getComplaints());
677 | assertEquals(16, last7.getUnsubs());
678 | assertEquals(17, last7.getOpens());
679 | assertEquals(18, last7.getUnique_opens());
680 | assertEquals(19, last7.getClicks());
681 | assertEquals(20, last7.getUnique_clicks());
682 |
683 | StatsResponse last30 = myResponse.getStats().getLast_30_days();
684 | assertEquals(21, last30.getSent());
685 | assertEquals(22, last30.getHard_bounces());
686 | assertEquals(23, last30.getSoft_bounces());
687 | assertEquals(24, last30.getRejects());
688 | assertEquals(25, last30.getComplaints());
689 | assertEquals(26, last30.getUnsubs());
690 | assertEquals(27, last30.getOpens());
691 | assertEquals(28, last30.getUnique_opens());
692 | assertEquals(29, last30.getClicks());
693 | assertEquals(30, last30.getUnique_clicks());
694 |
695 | StatsResponse last60 = myResponse.getStats().getLast_60_days();
696 | assertEquals(31, last60.getSent());
697 | assertEquals(32, last60.getHard_bounces());
698 | assertEquals(33, last60.getSoft_bounces());
699 | assertEquals(34, last60.getRejects());
700 | assertEquals(35, last60.getComplaints());
701 | assertEquals(36, last60.getUnsubs());
702 | assertEquals(37, last60.getOpens());
703 | assertEquals(38, last60.getUnique_opens());
704 | assertEquals(39, last60.getClicks());
705 | assertEquals(40, last60.getUnique_clicks());
706 |
707 | StatsResponse last90 = myResponse.getStats().getLast_90_days();
708 | assertEquals(41, last90.getSent());
709 | assertEquals(42, last90.getHard_bounces());
710 | assertEquals(43, last90.getSoft_bounces());
711 | assertEquals(44, last90.getRejects());
712 | assertEquals(45, last90.getComplaints());
713 | assertEquals(46, last90.getUnsubs());
714 | assertEquals(47, last90.getOpens());
715 | assertEquals(48, last90.getUnique_opens());
716 | assertEquals(49, last90.getClicks());
717 | assertEquals(50, last90.getUnique_clicks());
718 |
719 | StatsResponse allTime = myResponse.getStats().getAll_time();
720 | assertEquals(51, allTime.getSent());
721 | assertEquals(52, allTime.getHard_bounces());
722 | assertEquals(53, allTime.getSoft_bounces());
723 | assertEquals(54, allTime.getRejects());
724 | assertEquals(55, allTime.getComplaints());
725 | assertEquals(56, allTime.getUnsubs());
726 | assertEquals(57, allTime.getOpens());
727 | assertEquals(58, allTime.getUnique_opens());
728 | assertEquals(59, allTime.getClicks());
729 | assertEquals(60, allTime.getUnique_clicks());
730 | }
731 |
732 | @Test
733 | public void testVerifySenderResponseConversion() throws IOException {
734 | this.initRequestWithActualMapper();
735 |
736 | StringWriter sw = new StringWriter();
737 | IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("users/verifySenderResponse.txt"), sw);
738 | DisableResponse response = (DisableResponse) this.request.convertResponseData(sw.toString(), DisableResponse.class);
739 |
740 | assertEquals("example domain", response.getDomain());
741 | assertEquals("example created_at", response.getCreated_at());
742 | assertEquals("example approved_at", response.getApproved_at());
743 | assertTrue(response.isIs_enabled());
744 | }
745 | }
--------------------------------------------------------------------------------
/src/test/java/com/cribbstechnologies/clients/mandrill/request/MandrillUsersRequestTest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.request;
2 |
3 | import static org.mockito.MockitoAnnotations.initMocks;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.mockito.Mock;
8 | import org.mockito.Mockito;
9 |
10 | import com.cribbstechnologies.clients.mandrill.exception.RequestFailedException;
11 | import com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest;
12 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithDomain;
13 | import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail;
14 | import com.cribbstechnologies.clients.mandrill.model.ServiceMethods;
15 | import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillStringResponse;
16 | import com.cribbstechnologies.clients.mandrill.model.response.users.DisableResponse;
17 | import com.cribbstechnologies.clients.mandrill.model.response.users.UsersInfoResponse;
18 | import com.cribbstechnologies.clients.mandrill.model.response.users.UsersSendersResponse;
19 | import com.cribbstechnologies.clients.mandrill.model.response.users.VerifyResponse;
20 |
21 | public class MandrillUsersRequestTest {
22 |
23 | @Mock
24 | MandrillRESTRequest request;
25 |
26 | MandrillUsersRequest usersRequest = new MandrillUsersRequest();
27 |
28 | BaseMandrillRequest bmr;
29 |
30 | @Before
31 | public void before() {
32 | initMocks(this);
33 |
34 | bmr = new BaseMandrillRequest();
35 | bmr.setKey("123");
36 | }
37 |
38 | @Test
39 | public void testGetInfo() throws RequestFailedException {
40 | usersRequest.setRequest(request);
41 |
42 | UsersInfoResponse response = new UsersInfoResponse();
43 |
44 | Mockito.when(request.postRequest(bmr, ServiceMethods.Users.INFO, UsersInfoResponse.class)).thenReturn(response);
45 |
46 | usersRequest.getInfo(bmr);
47 |
48 | Mockito.verify(request).postRequest(bmr, ServiceMethods.Users.INFO, UsersInfoResponse.class);
49 | }
50 |
51 | @Test
52 | public void testPerformPing() throws RequestFailedException {
53 | usersRequest.setRequest(request);
54 |
55 | BaseMandrillStringResponse response = new BaseMandrillStringResponse();
56 |
57 | Mockito.when(request.postRequest(bmr, ServiceMethods.Users.PING, null)).thenReturn(response);
58 | usersRequest.performPing(bmr);
59 | Mockito.verify(request).postRequest(bmr, ServiceMethods.Users.PING, null);
60 | }
61 |
62 | @Test
63 | public void testGetSenders() throws RequestFailedException {
64 | usersRequest.setRequest(request);
65 | UsersSendersResponse response = new UsersSendersResponse();
66 |
67 | Mockito.when(request.postRequest(bmr, ServiceMethods.Users.SENDERS, UsersSendersResponse.class, usersRequest.getUsersListReference())).thenReturn(response);
68 |
69 | usersRequest.getSenders(bmr);
70 |
71 | Mockito.verify(request).postRequest(bmr, ServiceMethods.Users.SENDERS, UsersSendersResponse.class, usersRequest.getUsersListReference());
72 | }
73 |
74 | @Test
75 | public void testDisableSender() throws RequestFailedException {
76 | usersRequest.setRequest(request);
77 | MandrillRequestWithDomain disableRequest = new MandrillRequestWithDomain();
78 | DisableResponse response = new DisableResponse();
79 |
80 | Mockito.when(request.postRequest(disableRequest, ServiceMethods.Users.DISABLE_SENDER, DisableResponse.class)).thenReturn(response);
81 |
82 | usersRequest.disableSender(disableRequest);
83 |
84 | Mockito.verify(request).postRequest(disableRequest, ServiceMethods.Users.DISABLE_SENDER, DisableResponse.class);
85 | }
86 |
87 | @Test
88 | public void testVerifySender() throws RequestFailedException {
89 | usersRequest.setRequest(request);
90 | MandrillRequestWithEmail verifyRequest = new MandrillRequestWithEmail();
91 | VerifyResponse response = new VerifyResponse();
92 |
93 | Mockito.when(request.postRequest(verifyRequest, ServiceMethods.Users.VERIFY_SENDER, VerifyResponse.class)).thenReturn(response);
94 |
95 | usersRequest.verifySender(verifyRequest);
96 |
97 | Mockito.verify(request).postRequest(verifyRequest, ServiceMethods.Users.VERIFY_SENDER, VerifyResponse.class);
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/src/test/java/com/cribbstechnologies/clients/mandrill/util/MandrillConfigurationTest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.util;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Test;
6 |
7 | public class MandrillConfigurationTest {
8 |
9 | @Test
10 | public void testGetServiceUrl() {
11 | MandrillConfiguration config = new MandrillConfiguration();
12 | config.setApiVersion("1.0");
13 | config.setBaseURL("https://mandrillapp.com/api");
14 |
15 | String expectedResult = "https://mandrillapp.com/api/1.0/";
16 |
17 | assertEquals(expectedResult, config.getServiceUrl());
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/test/java/com/cribbstechnologies/clients/mandrill/util/MandrillSimpleDateFormatTest.java:
--------------------------------------------------------------------------------
1 | package com.cribbstechnologies.clients.mandrill.util;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.fail;
5 |
6 | import java.text.ParseException;
7 | import java.util.Calendar;
8 | import java.util.Date;
9 |
10 | import org.junit.Test;
11 |
12 | public class MandrillSimpleDateFormatTest {
13 |
14 | MandrillSimpleDateFormat format = new MandrillSimpleDateFormat();
15 |
16 | @Test
17 | public void testParse() {
18 | try {
19 | Date myDate = format.parse("2012-07-03 17:58:56");
20 | Calendar cal = Calendar.getInstance();
21 | cal.setTime(myDate);
22 | assertEquals(new Integer("2012"), (Integer)cal.get(Calendar.YEAR));
23 | assertEquals(new Integer("06"), (Integer)cal.get(Calendar.MONTH));
24 | assertEquals(new Integer("03"), (Integer)cal.get(Calendar.DAY_OF_MONTH));
25 | assertEquals(new Integer("17"), (Integer)cal.get(Calendar.HOUR_OF_DAY));
26 | assertEquals(new Integer("58"), (Integer)cal.get(Calendar.MINUTE));
27 | assertEquals(new Integer("56"), (Integer)cal.get(Calendar.SECOND));
28 | } catch (ParseException e) {
29 | fail(e.getMessage());
30 | }
31 | }
32 |
33 | @Test
34 | public void testFormat() {
35 | Calendar cal = Calendar.getInstance();
36 | cal.set(2011, 9, 1, 14, 30, 24);
37 | Date toFormat = cal.getTime();
38 | assertEquals("2011-10-01 14:30:24", format.format(toFormat));
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/resources/mandrill.properties:
--------------------------------------------------------------------------------
1 | apiKey=
2 | email.from=
3 | email.to.name1=
4 | email.to.address1=
5 | email.to.name2=
6 | email.to.address2=
7 | verify.email=
--------------------------------------------------------------------------------
/src/test/resources/messages/sendMessageResponse.txt:
--------------------------------------------------------------------------------
1 | [{"email": "example email", "status": "example status"},{"email": "example email2", "status": "example status2"}]
--------------------------------------------------------------------------------
/src/test/resources/tags/allTimeSeriesResponse.txt:
--------------------------------------------------------------------------------
1 | [{"time": "example time", "sent":42,"hard_bounces":42,"soft_bounces":42,"rejects":42,"complaints":42,"opens":42,"unique_opens":42,"clicks":42,"unique_clicks":42}]
--------------------------------------------------------------------------------
/src/test/resources/tags/listResponse.txt:
--------------------------------------------------------------------------------
1 | [{"tag": "example tag1", "sent":1,"hard_bounces":2,"soft_bounces":3,"rejects":4,"complaints":5,"unsubs":6,"opens":7,"clicks":8},{"tag": "example tag11", "sent":11,"hard_bounces":12,"soft_bounces":13,"rejects":14,"complaints":15,"unsubs":16,"opens":17,"clicks":18}]
--------------------------------------------------------------------------------
/src/test/resources/tags/timeSeriesResponse.txt:
--------------------------------------------------------------------------------
1 | [{"time": "example time1", "sent":2,"hard_bounces":3,"soft_bounces":4,"rejects":5,"complaints":6,"opens":7,"unique_opens":8,"clicks":9,"unique_clicks":10},{"time": "example time11", "sent":12,"hard_bounces":13,"soft_bounces":14,"rejects":15,"complaints":16,"opens":17,"unique_opens":18,"clicks":19,"unique_clicks":110}]
--------------------------------------------------------------------------------
/src/test/resources/templates/templateResponse.txt:
--------------------------------------------------------------------------------
1 | {"name": "example name", "code": "example code", "created_at": "example created_at", "updated_at": "example updated_at"}
--------------------------------------------------------------------------------
/src/test/resources/templates/templatesListResponse.txt:
--------------------------------------------------------------------------------
1 | [{"name": "example name1", "code": "example code1", "created_at": "example created_at1", "updated_at": "example updated_at1"},{"name": "example name11", "code": "example code11", "created_at": "example created_at11", "updated_at": "example updated_at11"}]
--------------------------------------------------------------------------------
/src/test/resources/urls/urlList.txt:
--------------------------------------------------------------------------------
1 | [{"url": "example url1", "sent":2,"clicks":3,"unique_clicks":4},{"url": "example url11", "sent":12,"clicks":13,"unique_clicks":14}]
--------------------------------------------------------------------------------
/src/test/resources/urls/urlTimeResponse.txt:
--------------------------------------------------------------------------------
1 | [{"time": "example time1", "sent":2,"clicks":3,"unique_clicks":4},{"time": "example time11", "sent":12,"clicks":13,"unique_clicks":14}]
--------------------------------------------------------------------------------
/src/test/resources/users/disableSenderResponse.txt:
--------------------------------------------------------------------------------
1 | {"domain": "example domain", "created_at": "example created_at", "approved_at": "example approved_at", "is_enabled":true}
--------------------------------------------------------------------------------
/src/test/resources/users/infoResponse.txt:
--------------------------------------------------------------------------------
1 | {"username": "example username", "created_at": "example created_at", "reputation":42,"hourly_quota":32,"stats":{"today":{"sent":1,"hard_bounces":2,"soft_bounces":3,"rejects":4,"complaints":5,"unsubs":6,"opens":7,"unique_opens":8,"clicks":9,"unique_clicks":10},"last_7_days":{"sent":11,"hard_bounces":12,"soft_bounces":13,"rejects":14,"complaints":15,"unsubs":16,"opens":17,"unique_opens":18,"clicks":19,"unique_clicks":20},"last_30_days":{"sent":21,"hard_bounces":22,"soft_bounces":23,"rejects":24,"complaints":25,"unsubs":26,"opens":27,"unique_opens":28,"clicks":29,"unique_clicks":30},"last_60_days":{"sent":31,"hard_bounces":32,"soft_bounces":33,"rejects":34,"complaints":35,"unsubs":36,"opens":37,"unique_opens":38,"clicks":39,"unique_clicks":40},"last_90_days":{"sent":41,"hard_bounces":42,"soft_bounces":43,"rejects":44,"complaints":45,"unsubs":46,"opens":47,"unique_opens":48,"clicks":49,"unique_clicks":50},"all_time":{"sent":51,"hard_bounces":52,"soft_bounces":53,"rejects":54,"complaints":55,"unsubs":56,"opens":57,"unique_opens":58,"clicks":59,"unique_clicks":60}}}
--------------------------------------------------------------------------------
/src/test/resources/users/pingResponse.txt:
--------------------------------------------------------------------------------
1 | "PONG!"
--------------------------------------------------------------------------------
/src/test/resources/users/sendersResponse.txt:
--------------------------------------------------------------------------------
1 | [{"address": "example address", "created_at": "example created_at", "is_enabled":true},{"address": "example address2", "created_at": "example created_at2", "is_enabled":false}]
--------------------------------------------------------------------------------
/src/test/resources/users/verifySenderResponse.txt:
--------------------------------------------------------------------------------
1 | {"domain": "example domain", "created_at": "example created_at", "approved_at": "example approved_at", "is_enabled":true}
--------------------------------------------------------------------------------