Skip to content

Commit e23f90f

Browse files
committed
Tidied up a little.
- (Mostly) automatically reformatted code using IntelliJ IDEA to match the Google Style Guide (as documented in CONTRIBUTING.md). - 2 space indent, where it wasn't already. - Line wrap at 100 characters, where it wasn't already. - Wildcard imports were replaced with explicit imports. - Unused imports were removed. - Annotations were put onto their own line, and additional lines added for readability where necessary. - Braces were added to if-statements that didn't already have them. - Also made some minor edits, e.g. as suggested by IntelliJ IDEA (e.g. public --> private). This will help with getting the code into shape before style conformance is required as per issue #472 and pull request #496. See also: - https://github.com/google/google-java-format - https://plugins.jetbrains.com/plugin/8527-google-java-format - https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml
1 parent 40d073e commit e23f90f

23 files changed

Lines changed: 1040 additions & 660 deletions
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
package com.sendgrid;
22

33
/**
4-
* An interface describing a callback mechanism for the
5-
* asynchronous, rate limit aware API connection.
4+
* An interface describing a callback mechanism for the asynchronous, rate limit aware API
5+
* connection.
66
*/
77
public interface APICallback {
8-
/**
9-
* Callback method in case of an error.
10-
* @param ex the error that was thrown.
11-
*/
12-
void error(Exception ex);
138

14-
/**
15-
* Callback method in case of a valid response.
16-
* @param response the valid response.
17-
*/
18-
void response(Response response);
9+
/**
10+
* Callback method in case of an error.
11+
*
12+
* @param ex the error that was thrown.
13+
*/
14+
void error(Exception ex);
15+
16+
/**
17+
* Callback method in case of a valid response.
18+
*
19+
* @param response the valid response.
20+
*/
21+
void response(Response response);
1922
}
Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
package com.sendgrid;
22

33
/**
4-
* An exception thrown when the maximum number of retries
5-
* have occurred, and the API calls are still rate limited.
4+
* An exception thrown when the maximum number of retries have occurred, and the API calls are still
5+
* rate limited.
66
*/
77
public class RateLimitException extends Exception {
8-
private final Request request;
9-
private final int retryCount;
108

11-
/**
12-
* Construct a new exception.
13-
* @param request the originating request object.
14-
* @param retryCount the number of times a retry was attempted.
15-
*/
16-
public RateLimitException(Request request, int retryCount) {
17-
this.request = request;
18-
this.retryCount = retryCount;
19-
}
9+
private final Request request;
10+
private final int retryCount;
2011

21-
/**
22-
* Get the originating request object.
23-
* @return the request object.
24-
*/
25-
public Request getRequest() {
26-
return this.request;
27-
}
12+
/**
13+
* Construct a new exception.
14+
*
15+
* @param request the originating request object.
16+
* @param retryCount the number of times a retry was attempted.
17+
*/
18+
public RateLimitException(Request request, int retryCount) {
19+
this.request = request;
20+
this.retryCount = retryCount;
21+
}
2822

29-
/**
30-
* Get the number of times the action was attemted.
31-
* @return the retry count.
32-
*/
33-
public int getRetryCount() {
34-
return this.retryCount;
35-
}
23+
/**
24+
* Get the originating request object.
25+
*
26+
* @return the request object.
27+
*/
28+
public Request getRequest() {
29+
return this.request;
30+
}
31+
32+
/**
33+
* Get the number of times the action was attemted.
34+
*
35+
* @return the retry count.
36+
*/
37+
public int getRetryCount() {
38+
return this.retryCount;
39+
}
3640
}

src/main/java/com/sendgrid/SendGrid.java

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import java.io.IOException;
44
import java.util.HashMap;
55
import java.util.Map;
6-
import java.util.concurrent.Executors;
76
import java.util.concurrent.ExecutorService;
7+
import java.util.concurrent.Executors;
88

99
/**
10-
* Class Twilio SendGrid allows for quick and easy access to the Twilio SendGrid API.
11-
*/
10+
* The Twilio SendGrid class allows for quick and easy access to the Twilio SendGrid API.
11+
*/
1212
public class SendGrid implements SendGridAPI {
1313

1414
private static final String VERSION = "3.0.0";
@@ -43,6 +43,7 @@ public class SendGrid implements SendGridAPI {
4343

4444
/**
4545
* Construct a new Twilio SendGrid API wrapper.
46+
*
4647
* @param apiKey is your Twilio SendGrid API Key: https://app.sendgrid.com/settings/api_keys
4748
*/
4849
public SendGrid(String apiKey) {
@@ -52,6 +53,7 @@ public SendGrid(String apiKey) {
5253

5354
/**
5455
* Construct a new Twilio SendGrid API wrapper.
56+
*
5557
* @param apiKey is your Twilio SendGrid API Key: https://app.sendgrid.com/settings/api_keys
5658
* @param test is true if you are unit testing
5759
*/
@@ -62,6 +64,7 @@ public SendGrid(String apiKey, Boolean test) {
6264

6365
/**
6466
* Construct a new Twilio SendGrid API wrapper.
67+
*
6568
* @param apiKey is your Twilio SendGrid API Key: https://app.sendgrid.com/settings/api_keys
6669
* @param client the Client to use (allows to customize its configuration)
6770
*/
@@ -72,6 +75,7 @@ public SendGrid(String apiKey, Client client) {
7275

7376
/**
7477
* Initialize the client.
78+
*
7579
* @param apiKey the user's API key.
7680
*/
7781
public void initializeSendGrid(String apiKey) {
@@ -89,14 +93,16 @@ public void initializeSendGrid(String apiKey) {
8993

9094
/**
9195
* Retrieve the current library version.
96+
*
9297
* @return the current version.
9398
*/
9499
public String getLibraryVersion() {
95-
return this.VERSION;
100+
return VERSION;
96101
}
97102

98103
/**
99104
* Get the API version.
105+
*
100106
* @return the current API versioin (v3 by default).
101107
*/
102108
public String getVersion() {
@@ -105,6 +111,7 @@ public String getVersion() {
105111

106112
/**
107113
* Set the API version.
114+
*
108115
* @param version the new version.
109116
*/
110117
public void setVersion(String version) {
@@ -113,6 +120,7 @@ public void setVersion(String version) {
113120

114121
/**
115122
* Obtain the request headers.
123+
*
116124
* @return the request headers.
117125
*/
118126
public Map<String, String> getRequestHeaders() {
@@ -121,6 +129,7 @@ public Map<String, String> getRequestHeaders() {
121129

122130
/**
123131
* Add a new request header.
132+
*
124133
* @param key the header key.
125134
* @param value the header value.
126135
* @return the new set of request headers.
@@ -132,6 +141,7 @@ public Map<String, String> addRequestHeader(String key, String value) {
132141

133142
/**
134143
* Remove a request header.
144+
*
135145
* @param key the header key to remove.
136146
* @return the new set of request headers.
137147
*/
@@ -142,6 +152,7 @@ public Map<String, String> removeRequestHeader(String key) {
142152

143153
/**
144154
* Get the Twilio SendGrid host (api.sendgrid.com by default).
155+
*
145156
* @return the Twilio SendGrid host.
146157
*/
147158
public String getHost() {
@@ -150,15 +161,16 @@ public String getHost() {
150161

151162
/**
152163
* Set the Twilio SendGrid host.
164+
*
153165
* @param host the new Twilio SendGrid host.
154166
*/
155167
public void setHost(String host) {
156168
this.host = host;
157169
}
158170

159171
/**
160-
* Get the maximum number of retries on a rate limit response.
161-
* The default is 5.
172+
* Get the maximum number of retries on a rate limit response. The default is 5.
173+
*
162174
* @return the number of retries on a rate limit.
163175
*/
164176
public int getRateLimitRetry() {
@@ -167,25 +179,26 @@ public int getRateLimitRetry() {
167179

168180
/**
169181
* Set the maximum number of retries on a rate limit response.
182+
*
170183
* @param rateLimitRetry the maximum retry count.
171184
*/
172185
public void setRateLimitRetry(int rateLimitRetry) {
173186
this.rateLimitRetry = rateLimitRetry;
174187
}
175188

176189
/**
177-
* Get the duration of time (in milliseconds) to sleep between
178-
* consecutive rate limit retries. The Twilio SendGrid API enforces
179-
* the rate limit to the second. The default value is 1.1 seconds.
190+
* Get the duration of time (in milliseconds) to sleep between consecutive rate limit retries. The
191+
* Twilio SendGrid API enforces the rate limit to the second. The default value is 1.1 seconds.
192+
*
180193
* @return the sleep duration.
181194
*/
182195
public int getRateLimitSleep() {
183196
return this.rateLimitSleep;
184197
}
185198

186199
/**
187-
* Set the duration of time (in milliseconds) to sleep between
188-
* consecutive rate limit retries.
200+
* Set the duration of time (in milliseconds) to sleep between consecutive rate limit retries.
201+
*
189202
* @param rateLimitSleep the sleep duration.
190203
*/
191204
public void setRateLimitSleep(int rateLimitSleep) {
@@ -194,6 +207,7 @@ public void setRateLimitSleep(int rateLimitSleep) {
194207

195208
/**
196209
* Impersonate subuser for subsequent requests
210+
*
197211
* @param subuser the subuser to be impersonated
198212
*/
199213
public void addImpersonateSubuser(String subuser) {
@@ -211,14 +225,16 @@ public void removeImpersonateSubuser() {
211225

212226
/**
213227
* Get the impersonated subuser or null if empty
228+
*
214229
* @return the impersonated subuser
215230
*/
216231
public String getImpersonateSubuser() {
217-
return this.subuser;
232+
return this.subuser;
218233
}
219234

220235
/**
221236
* Makes the call to the Twilio SendGrid API, override this method for testing.
237+
*
222238
* @param request the request to make.
223239
* @return the response object.
224240
* @throws IOException in case of a network error.
@@ -229,6 +245,7 @@ public Response makeCall(Request request) throws IOException {
229245

230246
/**
231247
* Class api sets up the request to the Twilio SendGrid API, this is main interface.
248+
*
232249
* @param request the request object.
233250
* @return the response object.
234251
* @throws IOException in case of a network error.
@@ -250,9 +267,9 @@ public Response api(Request request) throws IOException {
250267
}
251268

252269
/**
253-
* Attempt an API call. This method executes the API call asynchronously
254-
* on an internal thread pool. If the call is rate limited, the thread
255-
* will retry up to the maximum configured time.
270+
* Attempt an API call. This method executes the API call asynchronously on an internal thread
271+
* pool. If the call is rate limited, the thread will retry up to the maximum configured time.
272+
*
256273
* @param request the API request.
257274
*/
258275
public void attempt(Request request) {
@@ -267,10 +284,10 @@ public void response(Response r) {
267284
}
268285

269286
/**
270-
* Attempt an API call. This method executes the API call asynchronously
271-
* on an internal thread pool. If the call is rate limited, the thread
272-
* will retry up to the maximum configured time. The supplied callback
273-
* will be called in the event of an error, or a successful response.
287+
* Attempt an API call. This method executes the API call asynchronously on an internal thread
288+
* pool. If the call is rate limited, the thread will retry up to the maximum configured time. The
289+
* supplied callback will be called in the event of an error, or a successful response.
290+
*
274291
* @param request the API request.
275292
* @param callback the callback.
276293
*/

0 commit comments

Comments
 (0)