Skip to content

Commit db70381

Browse files
Merge pull request #124 from cweidenkeller/timeout_to_client_options
Add timeout to ClientOptions Object
2 parents e9b4a41 + 4c80917 commit db70381

5 files changed

Lines changed: 47 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ target/*
44
/.settings/org.eclipse.core.resources.prefs
55
/.settings/org.eclipse.jdt.core.prefs
66
/.settings/org.eclipse.m2e.core.prefs
7+
/bin/
8+
/.idea
9+
mailjet-client.iml

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Add the following in your `pom.xml`
5959
<dependency>
6060
<groupId>com.mailjet</groupId>
6161
<artifactId>mailjet-client</artifactId>
62-
<version>4.2.0</version>
62+
<version>4.4.0</version>
6363
</dependency>
6464
</dependencies>
6565
```

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.mailjet</groupId>
55
<artifactId>mailjet-client</artifactId>
6-
<version>4.2.1-SNAPSHOT</version>
6+
<version>4.4.0</version>
77
<packaging>jar</packaging>
88
<name>Mailjet Client</name>
99
<description>A Mailjet API Client</description>
@@ -22,7 +22,7 @@
2222
<connection>scm:git:https://github.com/mailjet/mailjet-apiv3-java.git</connection>
2323
<developerConnection>scm:git:https://github.com/mailjet/mailjet-apiv3-java.git</developerConnection>
2424
<url>git@github.com:mailjet/mailjet-apiv3-java.git</url>
25-
<tag>mailjet-client-4.2.1</tag>
25+
<tag>v4.4.0</tag>
2626
</scm>
2727
<licenses>
2828
<license>
@@ -52,7 +52,7 @@
5252
<dependency>
5353
<groupId>org.json</groupId>
5454
<artifactId>json</artifactId>
55-
<version>20140107</version>
55+
<version>20190722</version>
5656
</dependency>
5757
<dependency>
5858
<groupId>junit</groupId>
@@ -98,6 +98,7 @@
9898
<plugin>
9999
<groupId>org.apache.maven.plugins</groupId>
100100
<artifactId>maven-source-plugin</artifactId>
101+
<version>3.0.0</version>
101102
<executions>
102103
<execution>
103104
<id>attach-sources</id>

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,66 @@ public class ClientOptions {
1313

1414
private static String defaultBaseURL = "https://api.mailjet.com";
1515
private static String defaultVersion = "v3";
16+
private static Integer defaultTimeout = 10;
1617

1718
private String baseUrl;
1819
private String version;
20+
private Integer timeout;
1921

2022
public ClientOptions() {
2123
this.baseUrl = ClientOptions.defaultBaseURL;
2224
this.version = ClientOptions.defaultVersion;
25+
this.timeout = ClientOptions.defaultTimeout;
26+
}
27+
28+
public ClientOptions(String version, String baseUrl, Integer timeout) {
29+
this.baseUrl = baseUrl;
30+
this.version = version;
31+
this.timeout = timeout;
32+
33+
}
34+
35+
public ClientOptions(Integer timeout) {
36+
this.baseUrl = ClientOptions.defaultBaseURL;
37+
this.version = ClientOptions.defaultVersion;
38+
this.timeout = timeout;
39+
2340
}
2441

2542
public ClientOptions(String version, String baseUrl) {
2643
this.baseUrl = baseUrl;
2744
this.version = version;
45+
this.timeout = ClientOptions.defaultTimeout;
2846
}
2947

3048
public ClientOptions(String version) {
3149
this.baseUrl = ClientOptions.defaultBaseURL;
3250
this.version = version;
51+
this.timeout = ClientOptions.defaultTimeout;
3352
}
3453

3554
public String getBaseUrl() {
3655
return this.baseUrl;
3756
}
57+
58+
public void setBaseUrl(String baseUrl) {
59+
this.baseUrl = baseUrl;
60+
}
3861

3962
public String getVersion() {
4063
return this.version;
4164
}
65+
66+
public void setVersion(String version) {
67+
this.version = version;
68+
}
69+
70+
public Integer getTimeout() {
71+
return this.timeout;
72+
}
73+
74+
public void setTimeout(Integer timeout) {
75+
this.timeout = timeout;
76+
}
4277

4378
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class MailjetClient {
5252
private String _apiKey;
5353
private String _apiSecret;
5454
private String _token;
55+
private static final String userAgent = "mailjet-apiv3-java/v4.4.0";
5556
private int _debug = 0;
5657

5758
/**
@@ -154,7 +155,7 @@ private void initBasicAuth(String apiKey, String apiSecret) {
154155

155156
_client
156157
.addHeader("Accept", "application/json")
157-
.addHeader("user-agent", "mailjet-apiv3-java/v4.2.1")
158+
.addHeader("User-Agent", this.userAgent)
158159
.addHeader("Authorization", "Basic " + authEncBytes);
159160

160161
}
@@ -164,7 +165,7 @@ private void initTokenAuth(String token) {
164165

165166
_client
166167
.addHeader("Accept", "application/json")
167-
.addHeader("user-agent", "mailjet-apiv3-java/v4.2.1")
168+
.addHeader("User-Agent", this.userAgent)
168169
.addHeader("Authorization", "Bearer " + token);
169170

170171
}
@@ -353,6 +354,7 @@ public MailjetResponse delete(MailjetRequest request) throws MailjetException, M
353354

354355
private void setOptions(ClientOptions options) {
355356
this._options = options;
357+
this._client.setReadTimeout(options.getTimeout());
356358
}
357359

358360
private String createUrl() {

0 commit comments

Comments
 (0)