Skip to content

Commit edfe520

Browse files
author
Guillaume Badi
committed
3.1.0
1 parent 43527bf commit edfe520

File tree

108 files changed

+34
-33
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+34
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
# Package Files #
44
*.DS_Store
5+
/target/

src/main/java/com/mailjet/client/MailjetClient.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.mailjet.client.errors.MailjetException;
2020
import com.turbomanage.httpclient.BasicHttpClient;
21+
import com.turbomanage.httpclient.BasicRequestHandler;
2122
import com.turbomanage.httpclient.ConsoleRequestLogger;
2223
import com.turbomanage.httpclient.HttpResponse;
2324
import com.turbomanage.httpclient.ParameterMap;
@@ -41,6 +42,7 @@ public class MailjetClient {
4142

4243
private String _baseUrl = "https://api.mailjet.com/v3";
4344
private BasicHttpClient _client;
45+
private BasicRequestHandler _handler;
4446

4547
private String _apiKey;
4648
private String _apiSecret;
@@ -85,7 +87,7 @@ public void logResponse(HttpResponse hr) {}
8587

8688
_client
8789
.addHeader("Accept", "application/json")
88-
.addHeader("user-agent", "mailjet-apiv3-java/v3.0.0")
90+
.addHeader("user-agent", "mailjet-apiv3-java/v3.1.0")
8991
.addHeader("Authorization", "Basic " + authEncBytes);
9092
}
9193

@@ -121,6 +123,7 @@ public MailjetResponse get(MailjetRequest request) throws MailjetException {
121123
ParameterMap p = new ParameterMap();
122124
p.putAll(request._filters);
123125
HttpResponse response = _client.get(url, p);
126+
124127
return new MailjetResponse(
125128
response.getStatus(),
126129
new JSONObject(response.getBodyAsString())
@@ -152,7 +155,7 @@ public MailjetResponse post(MailjetRequest request) throws MailjetException {
152155
HttpResponse response;
153156
String json;
154157

155-
response = _client.post(_baseUrl + url, request.getContentType(), request.getBody().getBytes());
158+
response = _client.post(_baseUrl + url, request.getContentType(), request.getBody().getBytes("UTF8"));
156159
json = (response.getBodyAsString() != null ? response.getBodyAsString() : "{}");
157160
return new MailjetResponse(response.getStatus(), new JSONObject(json));
158161
} catch (MalformedURLException ex) {
@@ -174,7 +177,7 @@ public MailjetResponse put(MailjetRequest request) throws MailjetException {
174177

175178
HttpResponse response;
176179

177-
response = _client.put(_baseUrl + url, request.getContentType(), request.getBody().getBytes());
180+
response = _client.put(_baseUrl + url, request.getContentType(), request.getBody().getBytes("UTF8"));
178181
return new MailjetResponse(response.getStatus(), new JSONObject(response.getBodyAsString()));
179182
} catch (MalformedURLException ex) {
180183
throw new MailjetException("Internal Exception: Malformed Url");

src/main/java/com/mailjet/client/Main.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.mailjet.client;
1818

1919
import com.mailjet.client.errors.MailjetException;
20+
import com.mailjet.client.resource.Contact;
2021
import com.mailjet.client.resource.Email;
2122
import org.json.JSONArray;
2223
import org.json.JSONObject;
@@ -28,28 +29,24 @@
2829
public class Main {
2930

3031
public static void main(String[] args) throws MailjetException {
31-
MailjetClient client;
32-
MailjetRequest request;
33-
MailjetResponse response;
34-
client = new MailjetClient("", "");
35-
client.setDebug(MailjetClient.VERBOSE_DEBUG);
36-
request = new MailjetRequest(Email.resource)
37-
.property(Email.FROMEMAIL, "gbadi@student.42.fr")
38-
.property(Email.FROMNAME, "Mailjet Pilot")
39-
.property(Email.SUBJECT, "Your email flight plan2!")
40-
.property(Email.TEXTPART, "Dear passenger, welcome to Mailjet! May the delivery force be with you!")
41-
.property(Email.HTMLPART, "<h3>Dear passenger, welcome to <img src=\"cid:logo.gif\">Mailjet!</h3><br />May the delivery force be with you!")
42-
.property(Email.RECIPIENTS, new JSONArray()
43-
.put(new JSONObject()
44-
.put("Email", "gbadi@mailjet.com")))
45-
.property(Email.INLINE_ATTACHMENTS, new JSONArray()
46-
.put(new JSONObject()
47-
.put("Content-type", "image/gif")
48-
.put("Filename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wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MjY5ODYxMzYzMkJCMTFFMDkzQkFFMkFENzVGN0JGRkYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MjY5ODYxMzczMkJCMTFFMDkzQkFFMkFENzVGN0JGRkYiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDoyNjk4NjEzNDMyQkIxMUUwOTNCQUUyQUQ3NUY3QkZGRiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDoyNjk4NjEzNTMyQkIxMUUwOTNCQUUyQUQ3NUY3QkZGRiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PgH//v38+/r5+Pf29fTz8vHw7+7t7Ovq6ejn5uXk4+Lh4N/e3dzb2tnY19bV1NPS0dDPzs3My8rJyMfGxcTDwsHAv769vLu6ubi3trW0s7KxsK+urayrqqmop6alpKOioaCfnp2cm5qZmJeWlZSTkpGQj46NjIuKiYiHhoWEg4KBgH9+fXx7enl4d3Z1dHNycXBvbm1sa2ppaGdmZWRjYmFgX15dXFtaWVhXVlVUU1JRUE9OTUxLSklIR0ZFRENCQUA/Pj08Ozo5ODc2NTQzMjEwLy4tLCsqKSgnJiUkIyIhIB8eHRwbGhkYFxYVFBMSERAPDg0MCwoJCAcGBQQDAgEAACH5BAEAAAAALAAAAAAQABAAAAdUgACCg4SFhoeIiYRGLhaKhA0TMDgSLxAUiEIZHAUsIUQpKAo9Og6FNh8zJUNFJioYQIgJRzc+NBEkiAcnBh4iO4o8QRsjj0gaOY+CDwPKzs/Q0YSBADs=")));
50-
response = client.post(request);
51-
System.out.println(response);
52-
System.out.println(response.getStatus());
53-
System.out.println(response.getData());
32+
MailjetClient client = new MailjetClient("85480869a17b7d13ef8bd393283d40d9", "f961d94099350d269f661d92e3cc195f");
33+
34+
MailjetRequest email;
35+
JSONArray recipients;
36+
MailjetResponse response;
37+
38+
recipients = new JSONArray()
39+
.put(new JSONObject().put(Contact.EMAIL, "gbadi@mailjet.com"));
40+
41+
email = new MailjetRequest(Email.resource)
42+
.property(Email.FROMNAME, "Teste")
43+
.property(Email.FROMEMAIL, "gbadi@student.42.fr")
44+
.property(Email.SUBJECT, "Testçndo")
45+
.property(Email.HTMLPART, "<html> <body> <h1>Tesçte</h1> <p>Lorem ipsum..</p></body> </html>")
46+
.property(Email.RECIPIENTS, recipients)
47+
.property(Email.MJCUSTOMID, "JAVA-Email");
48+
49+
response = client.post(email);
50+
5451
}
5552
}
1.85 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1.88 KB
Binary file not shown.
765 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
289 Bytes
Binary file not shown.

target/client-3.0.0.jar

289 Bytes
Binary file not shown.

target/maven-archiver/pom.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Generated by Maven
2-
#Mon Feb 29 14:05:44 CET 2016
2+
#Wed Mar 02 09:54:03 CET 2016
33
version=3.0.0
44
groupId=com.mailjet
55
artifactId=client

target/surefire-reports/TEST-com.mailjet.client.MJEasyClientTest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<testsuite tests="1" failures="0" name="com.mailjet.client.MJEasyClientTest" time="0.012" errors="0" skipped="0">
2+
<testsuite tests="1" failures="0" name="com.mailjet.client.MJEasyClientTest" time="0.015" errors="0" skipped="0">
33
<properties>
44
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
55
<property name="sun.boot.library.path" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib"/>
@@ -63,5 +63,5 @@
6363
<property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
6464
<property name="sun.cpu.isalist" value=""/>
6565
</properties>
66-
<testcase classname="com.mailjet.client.MJEasyClientTest" name="testEmailSend" time="0.011"/>
66+
<testcase classname="com.mailjet.client.MJEasyClientTest" name="testEmailSend" time="0.015"/>
6767
</testsuite>

target/surefire-reports/TEST-com.mailjet.client.MailjetClientTest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<testsuite tests="3" failures="0" name="com.mailjet.client.MailjetClientTest" time="0.247" errors="0" skipped="0">
2+
<testsuite tests="3" failures="0" name="com.mailjet.client.MailjetClientTest" time="0.159" errors="0" skipped="0">
33
<properties>
44
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
55
<property name="sun.boot.library.path" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib"/>
@@ -63,7 +63,7 @@
6363
<property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
6464
<property name="sun.cpu.isalist" value=""/>
6565
</properties>
66-
<testcase classname="com.mailjet.client.MailjetClientTest" name="testSimpleGet" time="0.074"/>
66+
<testcase classname="com.mailjet.client.MailjetClientTest" name="testSimpleGet" time="0.028"/>
6767
<testcase classname="com.mailjet.client.MailjetClientTest" name="testFilteringGet" time="0"/>
6868
<testcase classname="com.mailjet.client.MailjetClientTest" name="testActionGet" time="0"/>
6969
</testsuite>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-------------------------------------------------------------------------------
22
Test set: com.mailjet.client.MJEasyClientTest
33
-------------------------------------------------------------------------------
4-
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.011 sec
4+
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-------------------------------------------------------------------------------
22
Test set: com.mailjet.client.MailjetClientTest
33
-------------------------------------------------------------------------------
4-
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.247 sec
4+
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.159 sec
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)