Skip to content

Commit 7e97354

Browse files
updates README.md
1 parent d06279a commit 7e97354

1 file changed

Lines changed: 25 additions & 41 deletions

File tree

README.md

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Check out all the resources and all the Java code examples in the [Offical Docum
2020

2121
## Table of contents
2222

23+
- [Release notes](#release-notes)
2324
- [Compatibility](#compatibility)
2425
- [Installation (Maven)](#installation-maven)
2526
- [Authentication](#authentication)
@@ -46,6 +47,12 @@ Check out all the resources and all the Java code examples in the [Offical Docum
4647
- [Contribute](#contribute)
4748

4849

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+
4956
## Compatibility
5057

5158
This library requires Java version 1.8 or higher.
@@ -155,7 +162,7 @@ To instantiate the library you can use the following constructor:
155162

156163
#### Set connection timeouts and log requests
157164

158-
You can pass customly configured HttpClient to the Mailjet client to get request logs or custom timeouts:
165+
You can pass a custom configured HttpClient to the Mailjet client to get request logs or custom timeouts:
159166

160167
```java
161168
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
@@ -490,60 +497,37 @@ public class MyClass {
490497

491498
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.
492499

493-
```java
494-
client = new MailjetClient(ClientOptions.builder().apiAccessToken(System.getenv("MJ_TOKEN")).build());
495-
```
496-
497500
### Example request
498501

499-
Here's an example SMS API request:
502+
An example SMS API request:
500503

501504
``` java
502505

503506
MailjetClient client;
504507
MailjetRequest request;
505508
MailjetResponse response;
506509

507-
// Note how we use an already generated token
508-
MailjetClient client = new MailjetClient(ClientOptions.builder().apiAccessToken(System.getenv("MJ_TOKEN")).build());
509-
request = new MailjetRequest(Send.resource)
510-
.property(Send.From, "MJPilot")
511-
.property(Send.To, "+33600000000")
512-
.property(Send.Text, "Have a nice SMS flight with Mailjet!");
510+
MailjetClient mailjetClient = new MailjetClient(ClientOptions
511+
.builder()
512+
.bearerAccessToken(System.getenv("MJ_APITOKEN"))
513+
.build());
513514

514-
response = client.post(request);
515+
String germanyPhoneNumber = "+4915207831169";
515516

516-
package com.my.project;
517-
import com.mailjet.client.errors.MailjetException;
518-
import com.mailjet.client.errors.MailjetSocketTimeoutException;
519-
import com.mailjet.client.MailjetClient;
520-
import com.mailjet.client.MailjetRequest;
521-
import com.mailjet.client.MailjetResponse;
522-
import com.mailjet.client.ClientOptions;
523-
import com.mailjet.client.resource.sms.SmsSend;
524-
import org.json.JSONArray;
525-
import org.json.JSONObject;
526-
public class MyClass {
527-
/**
528-
* Run:
529-
*/
530-
public static void main(String[] args) throws MailjetException {
531-
MailjetClient client;
532-
MailjetRequest request;
533-
MailjetResponse response;
534-
client = new MailjetClient(ClientOptions.builder().apiAccessToken(System.getenv("MJ_TOKEN")).build());
535-
request = new MailjetRequest(SmsSend.resource)
536-
.property(SmsSend.FROM, "MJPilot")
537-
.property(SmsSend.TO, "+33600000000")
538-
.property(SmsSend.TEXT, "Have a nice SMS flight with Mailjet!")
539-
response = client.post(request);
540-
System.out.println(response.getStatus());
541-
System.out.println(response.getData());
542-
}
543-
}
517+
MailjetRequest mailjetRequest = new MailjetRequest(SmsSend.resource)
518+
.property(SmsSend.FROM, "MJPilot")
519+
.property(SmsSend.TO, germanyPhoneNumber)
520+
.property(SmsSend.TEXT, "Have a nice SMS flight with Mailjet!");
521+
522+
// send the request
523+
MailjetResponse response = mailjetClient.post(mailjetRequest);
544524

525+
// assert response
526+
Assert.assertEquals(200, response.getStatus());
527+
Assert.assertEquals("Message is being sent", response.getData().getJSONObject(0).getJSONObject("Status").getString("Description"));
545528

546529
```
530+
Also, you can check [integration tests](src/test/java/com/mailjet/client/SendSmsIT.java) how to work with Mailjet client.
547531

548532
## Contribute
549533

0 commit comments

Comments
 (0)