Skip to content

Commit d06279a

Browse files
renames to bearer token in client options to be more readable, adds documentation for MailjetClient methods
1 parent 3c7da27 commit d06279a

5 files changed

Lines changed: 28 additions & 17 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ClientOptions {
2323
/**
2424
* Bearer token used for SMS Api calls
2525
*/
26-
private String apiAccessToken;
26+
private String bearerAccessToken;
2727

2828
/**
2929
* API key to authenticate Email Api calls

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public MailjetClient(String apiKey, String apiSecret) {
6161
public MailjetClient(String token) {
6262
this(ClientOptions
6363
.builder()
64-
.apiAccessToken(token)
64+
.bearerAccessToken(token)
6565
.build());
6666
}
6767

@@ -76,10 +76,10 @@ public MailjetClient(ClientOptions clientOptions) {
7676
}
7777

7878
/**
79-
* Performs a get request to the Mailjet endpoint
80-
* @param request formed request to the MailJet API
81-
* @return MailjetResponse
82-
* @throws MailjetException exception is thrown in case of unsuccessful HTTP call execution
79+
* performs GET request.
80+
* @param request request to be sent to Mailjet server
81+
* @return MailjetResponse with parameters of the response
82+
* @throws com.mailjet.client.errors.MailjetException in case of unsuccess response status code
8383
*/
8484
public MailjetResponse get(MailjetRequest request) throws MailjetException {
8585
try {
@@ -98,12 +98,11 @@ public MailjetResponse get(MailjetRequest request) throws MailjetException {
9898
}
9999

100100

101-
102101
/**
103-
* perform a Mailjet POST request.
104-
* @param request
105-
* @return
106-
* @throws com.mailjet.client.errors.MailjetException
102+
* performs POST request.
103+
* @param request request to be sent to Mailjet server
104+
* @return MailjetResponse with parameters of the response
105+
* @throws com.mailjet.client.errors.MailjetException in case of unsuccess response status code
107106
*/
108107
public MailjetResponse post(MailjetRequest request) throws MailjetException {
109108

@@ -124,6 +123,12 @@ public MailjetResponse post(MailjetRequest request) throws MailjetException {
124123
}
125124
}
126125

126+
/**
127+
* performs PUT request.
128+
* @param request request to be sent to Mailjet server
129+
* @return MailjetResponse with parameters of the response
130+
* @throws com.mailjet.client.errors.MailjetException in case of unsuccess response status code
131+
*/
127132
public MailjetResponse put(MailjetRequest request) throws MailjetException {
128133
try {
129134
final RequestBody requestBody = RequestBody.create(
@@ -142,6 +147,12 @@ public MailjetResponse put(MailjetRequest request) throws MailjetException {
142147
}
143148
}
144149

150+
/**
151+
* performs DELETE request.
152+
* @param request request to be sent to Mailjet server
153+
* @return MailjetResponse with parameters of the response
154+
* @throws com.mailjet.client.errors.MailjetException in case of unsuccess response status code
155+
*/
145156
public MailjetResponse delete(MailjetRequest request) throws MailjetException {
146157
try {
147158

@@ -197,10 +208,10 @@ private Request.Builder getPreconfiguredRequestBuilder(MailjetRequest request) t
197208
break;
198209

199210
case Bearer:
200-
if (_options.getApiAccessToken() == null)
211+
if (_options.getBearerAccessToken() == null)
201212
throw new MailjetUnauthorizedException("To do a request to MailJet api, api access token should be set");
202213

203-
builder.addHeader("Authorization", "Bearer " + _options.getApiAccessToken());
214+
builder.addHeader("Authorization", "Bearer " + _options.getBearerAccessToken());
204215
break;
205216
}
206217

src/main/java/com/mailjet/client/easy/MJEasyClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public MJEasyClient(String apiKeyPublic, String apiKeyPrivate) {
3434
public MJEasyClient(String token) {
3535
ClientOptions clientOptions = ClientOptions
3636
.builder()
37-
.apiAccessToken(token)
37+
.bearerAccessToken(token)
3838
.build();
3939

4040
client = new MailjetClient(clientOptions);

src/test/java/com/mailjet/client/MailjetClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void initialize() throws IOException {
3333
.baseUrl(mockWebServer.url("/").toString())
3434
.apiSecretKey("secret-key")
3535
.apiKey("api-key")
36-
.apiAccessToken("bearer-token")
36+
.bearerAccessToken("bearer-token")
3737
.build();
3838

3939
client = new MailjetClient(clientOptions);

src/test/java/com/mailjet/client/SendSmsIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void sendSms_UnsupportedCountry_ThrowsMailjetException() {
1414
// arrange
1515
MailjetClient mailjetClient = new MailjetClient(ClientOptions
1616
.builder()
17-
.apiAccessToken(System.getenv("MJ_APITOKEN"))
17+
.bearerAccessToken(System.getenv("MJ_APITOKEN"))
1818
.build());
1919

2020
String ukrainePhoneNumber = "+380507363100";
@@ -38,7 +38,7 @@ public void sendSms_SupportedCountry_ReturnsSuccessResponse() throws MailjetExce
3838
// arrange
3939
MailjetClient mailjetClient = new MailjetClient(ClientOptions
4040
.builder()
41-
.apiAccessToken(System.getenv("MJ_APITOKEN"))
41+
.bearerAccessToken(System.getenv("MJ_APITOKEN"))
4242
.build());
4343

4444
// to verify other countries, free services like https://receive-smss.com/ can be used

0 commit comments

Comments
 (0)