You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+91-65Lines changed: 91 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,7 @@ Check out all the resources and all the Java code examples in the [Offical Docum
20
20
21
21
## Table of contents
22
22
23
+
-[Release notes](#release-notes)
23
24
-[Compatibility](#compatibility)
24
25
-[Installation (Maven)](#installation-maven)
25
26
-[Authentication](#authentication)
@@ -46,6 +47,12 @@ Check out all the resources and all the Java code examples in the [Offical Docum
46
47
-[Contribute](#contribute)
47
48
48
49
50
+
## Release notes
51
+
v5.0.0
52
+
- migrated to more reliable OkHttpClient
53
+
- removed ApiVersion from the MailjetClient configuration: Now the client will determine the needed API version from the resource itself.
54
+
- added ClientOptions builder to make configuration more explicit. If you have troubles with migration, please, check [tests](src/test/java/com/mailjet/client/SendIT.java) for more examples.
55
+
49
56
## Compatibility
50
57
51
58
This library requires Java version 1.8 or higher.
@@ -59,7 +66,7 @@ Add the following in your `pom.xml`
59
66
<dependency>
60
67
<groupId>com.mailjet</groupId>
61
68
<artifactId>mailjet-client</artifactId>
62
-
<version>4.5.0</version>
69
+
<version>5.0.0</version>
63
70
</dependency>
64
71
</dependencies>
65
72
```
@@ -78,7 +85,14 @@ export MJ_APIKEY_PRIVATE='your API secret'
for more configuration options, please, refer to the [OkHttpClient documentation](https://square.github.io/okhttp/)
186
+
143
187
#### API Versioning
144
188
145
189
The Mailjet API is spread among three distinct versions:
@@ -148,13 +192,8 @@ The Mailjet API is spread among three distinct versions:
148
192
-`v3.1` - Email Send API v3.1, which is the latest version of our Send API
149
193
-`v4` - SMS API
150
194
151
-
Since most Email API endpoints are located under `v3`, it is set as the default one and does not need to be specified when making your request. For the others you need to specify the version using `ClientOptions`. For example, if using Send API `v3.1`:
195
+
You can skip version specification during the request, as MailJet client will determine the needed API version by himself.
If your account has been moved to Mailjet's **US architecture**, the URL you need to add is `https://api.us.mailjet.com`.
@@ -218,7 +263,7 @@ public class MyClass {
218
263
MailjetClient client;
219
264
MailjetRequest request;
220
265
MailjetResponse response;
221
-
client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
266
+
client = new MailjetClient(ClientOptions.builder().apiKey(System.getenv("MJ_APIKEY_PUBLIC")).apiSecretKey(System.getenv("MJ_APIKEY_PRIVATE")).build());
222
267
request = new MailjetRequest(Contact.resource)
223
268
.property(Contact.EMAIL, "Mister@mailjet.com");
224
269
response = client.post(request);
@@ -251,7 +296,7 @@ public class MyClass {
251
296
MailjetClient client;
252
297
MailjetRequest request;
253
298
MailjetResponse response;
254
-
client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
299
+
client = new MailjetClient(ClientOptions.builder().apiKey(System.getenv("MJ_APIKEY_PUBLIC")).apiSecretKey(System.getenv("MJ_APIKEY_PRIVATE")).build());
255
300
request = new MailjetRequest(ContactManagecontactslists.resource, ID)
256
301
.property(ContactManagecontactslists.CONTACTSLISTS, new JSONArray()
257
302
.put(new JSONObject()
@@ -292,7 +337,8 @@ public class MyClass {
292
337
MailjetClient client;
293
338
MailjetRequest request;
294
339
MailjetResponse response;
295
-
client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
340
+
client = new MailjetClient(ClientOptions.builder().apiKey(System.getenv("MJ_APIKEY_PUBLIC")).apiSecretKey(System.getenv("MJ_APIKEY_PRIVATE")).build());
341
+
296
342
request = new MailjetRequest(Contact.resource);
297
343
response = client.get(request);
298
344
System.out.println(response.getStatus());
@@ -324,7 +370,8 @@ public class MyClass {
324
370
MailjetClient client;
325
371
MailjetRequest request;
326
372
MailjetResponse response;
327
-
client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
373
+
client = new MailjetClient(ClientOptions.builder().apiKey(System.getenv("MJ_APIKEY_PUBLIC")).apiSecretKey(System.getenv("MJ_APIKEY_PRIVATE")).build());
client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
408
+
client = new MailjetClient(ClientOptions.builder().apiKey(System.getenv("MJ_APIKEY_PUBLIC")).apiSecretKey(System.getenv("MJ_APIKEY_PRIVATE")).build());
409
+
362
410
request = new MailjetRequest(Contact.resource, ID);
363
411
response = client.get(request);
364
412
System.out.println(response.getStatus());
@@ -392,7 +440,8 @@ public class MyClass {
392
440
MailjetClient client;
393
441
MailjetRequest request;
394
442
MailjetResponse response;
395
-
client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
443
+
client = new MailjetClient(ClientOptions.builder().apiKey(System.getenv("MJ_APIKEY_PUBLIC")).apiSecretKey(System.getenv("MJ_APIKEY_PRIVATE")).build());
444
+
396
445
request = new MailjetRequest(Contactdata.resource, ID)
Authentication for the SMS API endpoints is done using a bearer token. The bearer token is generated in the [SMS section](https://app.mailjet.com/sms) of your Mailjet account.
Authentication for the SMS API endpoints is done using a bearer token. The bearer token generated in the [SMS section](https://app.mailjet.com/sms) of your Mailjet account.
453
499
454
500
### Example request
455
501
456
-
Here's an example SMS API request:
502
+
An example SMS API request:
457
503
458
504
```java
459
505
460
506
MailjetClient client;
461
507
MailjetRequest request;
462
508
MailjetResponse response;
463
509
464
-
// Note how we set the version to v4 using ClientOptions and use an already generated token
0 commit comments