Skip to content

Commit ad8b84c

Browse files
Vitalii.ChornobryvyiVitalii.Chornobryvyi
authored andcommitted
release 5.2.4
1 parent 00ba9ad commit ad8b84c

File tree

6 files changed

+45
-14
lines changed

6 files changed

+45
-14
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ Check out all the resources and all the Java code examples in the [Official Docu
4949

5050
## Release notes
5151

52+
v5.2.4
53+
- add ability to attach the file into request
54+
- fix for uploading CSV file through the DATA API
55+
5256
v5.2.3
5357
- update dependency versions
5458

@@ -88,7 +92,7 @@ Add the following in your `pom.xml`
8892
<dependency>
8993
<groupId>com.mailjet</groupId>
9094
<artifactId>mailjet-client</artifactId>
91-
<version>5.2.3</version>
95+
<version>5.2.4</version>
9296
</dependency>
9397
</dependencies>
9498
```

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<!--General configuration -->
77
<groupId>com.mailjet</groupId>
88
<artifactId>mailjet-client</artifactId>
9-
<version>5.2.3</version>
9+
<version>5.2.4</version>
1010
<packaging>jar</packaging>
1111
<name>Mailjet Client</name>
1212
<description>A Mailjet API Client</description>
@@ -27,7 +27,7 @@
2727
<connection>scm:git:https://github.com/mailjet/mailjet-apiv3-java.git</connection>
2828
<developerConnection>scm:git:https://github.com/mailjet/mailjet-apiv3-java.git</developerConnection>
2929
<url>[email protected]:mailjet/mailjet-apiv3-java.git</url>
30-
<tag>mailjet-client-5.2.3</tag>
30+
<tag>mailjet-client-5.2.4</tag>
3131
</scm>
3232
<!--License-->
3333
<licenses>

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
package com.mailjet.client;
1818

19+
import java.io.File;
1920
import java.io.IOException;
2021
import java.io.UnsupportedEncodingException;
2122
import java.nio.charset.StandardCharsets;
23+
import java.util.Objects;
2224
import java.util.concurrent.CompletableFuture;
2325

2426
import com.mailjet.client.errors.MailjetClientCommunicationException;
@@ -38,7 +40,7 @@ public class MailjetClient {
3840
private ClientOptions _options;
3941
private OkHttpClient _client;
4042

41-
private static final String userAgent = "mailjet-apiv3-java/v5.2.3";
43+
private static final String userAgent = "mailjet-apiv3-java/v5.2.4";
4244

4345
/**
4446
* Deprecated - please, use MailjetClient(ClientOptions clientOptions) ctor instead
@@ -160,11 +162,16 @@ public CompletableFuture<MailjetResponse> postAsync(MailjetRequest request) {
160162
}
161163

162164
private Call getPostCall(MailjetRequest request) throws MailjetException {
163-
164-
final byte[] bodyContent = request.getBody().getBytes(StandardCharsets.UTF_8);
165-
166-
final RequestBody requestBody = RequestBody.create(
167-
MediaType.parse(request.getContentType()), bodyContent);
165+
final File attachment = request.getAttachment();
166+
final RequestBody requestBody;
167+
final MediaType mediaType = MediaType.parse(request.getContentType());
168+
final byte[] bodyContent = request.getBody().getBytes(StandardCharsets.UTF_8);
169+
170+
if (Objects.nonNull(attachment)) {
171+
requestBody = RequestBody.create(mediaType, attachment);
172+
} else {
173+
requestBody = RequestBody.create(mediaType, bodyContent);
174+
}
168175

169176
final Request okHttpRequest = getPreconfiguredRequestBuilder(request)
170177
.post(requestBody)

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

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

1919
import static com.mailjet.client.MailjetRequestUtil.decodeDecimals;
2020

21+
import java.io.File;
2122
import java.io.IOException;
2223
import java.io.UnsupportedEncodingException;
2324
import java.net.URLEncoder;
@@ -71,6 +72,9 @@ public class MailjetRequest {
7172

7273
private String _data;
7374

75+
@Getter
76+
private File attachment;
77+
7478
@Getter
7579
private final ApiVersion apiVersion;
7680

@@ -102,7 +106,7 @@ public class MailjetRequest {
102106
* @param res
103107
*/
104108
public MailjetRequest(Resource res) {
105-
this._path = "/REST";
109+
this._path = definePath(res);
106110
_configuration = 1;
107111
resource = res.getResource();
108112
_action = res.getAction();
@@ -123,7 +127,7 @@ public MailjetRequest(Resource res) {
123127
* @param id
124128
*/
125129
public MailjetRequest(Resource res, long id) {
126-
this._path = "/REST";
130+
this._path = definePath(res);
127131
resource = res.getResource();
128132
_action = res.getAction();
129133
_withoutNamespace = res.getWithoutNamespace();
@@ -144,7 +148,7 @@ public MailjetRequest(Resource res, long id) {
144148
* @param id
145149
*/
146150
public MailjetRequest(Resource res, String id) {
147-
this._path = "/REST";
151+
this._path = definePath(res);
148152
resource = res.getResource();
149153
_action = res.getAction();
150154
_withoutNamespace = res.getWithoutNamespace();
@@ -166,7 +170,7 @@ public MailjetRequest(Resource res, String id) {
166170
* @param actionid the resource action ID
167171
*/
168172
public MailjetRequest(Resource res, long id, long actionid) {
169-
this._path = "/REST";
173+
this._path = definePath(res);
170174
resource = res.getResource();
171175
_action = res.getAction();
172176
_withoutNamespace = res.getWithoutNamespace();
@@ -184,6 +188,11 @@ public MailjetRequest setData(String path) throws IOException {
184188
return this;
185189
}
186190

191+
public MailjetRequest attachFile(File file) {
192+
this.attachment = file;
193+
return this;
194+
}
195+
187196
/**
188197
* Pass a String formatted json as the request body
189198
* @param json
@@ -236,7 +245,7 @@ public JSONObject getBodyJSON() {
236245
*/
237246
public String getContentType() {
238247
if ("csvdata".equals(_action))
239-
return "text:csv";
248+
return "text/plain";
240249
if ("csverror".equals(_action))
241250
return "text/plain";
242251
else
@@ -263,6 +272,8 @@ public String buildUrl(String baseApiUrl) throws UnsupportedEncodingException {
263272
url = base + '/' + _action;
264273
else if (_action.equals("managemanycontacts") && id != null)
265274
url = base + '/' + _action + '/' + id;
275+
else if (_action.equals("csvdata"))
276+
url = base + '/' + id + '/' + _action + '/' + "text:plain";
266277
else if (_configuration == 1)
267278
url = base;
268279
else if (_configuration == 2)
@@ -359,4 +370,11 @@ public String toString() {
359370
.put("Body", _body.toString())
360371
.toString();
361372
}
373+
374+
private String definePath(Resource res) {
375+
if (res.getAction().equals("csvdata")) {
376+
return "/DATA";
377+
}
378+
return "/REST";
379+
}
362380
}

src/main/java/com/mailjet/client/resource/Contactslist.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
public class Contactslist {
1717

1818
public static Resource resource = new Resource("contactslist", "", ApiVersion.V3, ApiAuthenticationType.Basic);
19+
public static Resource csvDataResource = new Resource("contactslist", "csvdata", ApiVersion.V3, ApiAuthenticationType.Basic);
1920

2021
public static String ADDRESS = "Address";
2122
public static String CREATEDAT = "CreatedAt";

src/main/java/com/mailjet/client/resource/Csvimport.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class Csvimport {
1919

2020
public static String ALIVEAT = "AliveAt";
2121
public static String CONTACTSLIST = "ContactsList";
22+
public static String CONTACTSLISTID = "ContactsListID";
2223
public static String COUNT = "Count";
2324
public static String CURRENT = "Current";
2425
public static String DATAID = "DataID";

0 commit comments

Comments
 (0)