Skip to content

Commit 58bf3e6

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 sendgrid#472 and pull request sendgrid#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 7560a8d commit 58bf3e6

23 files changed

Lines changed: 1029 additions & 652 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-
public void error(Exception ex);
138

14-
/**
15-
* Callback method in case of a valid response.
16-
* @param response the valid response.
17-
*/
18-
public void response(Response response);
9+
/**
10+
* Callback method in case of an error.
11+
*
12+
* @param ex the error that was thrown.
13+
*/
14+
public void error(Exception ex);
15+
16+
/**
17+
* Callback method in case of a valid response.
18+
*
19+
* @param response the valid response.
20+
*/
21+
public 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: 33 additions & 18 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 SendGrid allows for quick and easy access to the SendGrid API.
11-
*/
10+
* The SendGrid class allows for quick and easy access to the 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 SendGrid API wrapper.
46+
*
4647
* @param apiKey is your 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 SendGrid API wrapper.
56+
*
5557
* @param apiKey is your 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 SendGrid API wrapper.
67+
*
6568
* @param apiKey is your 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) {
@@ -90,14 +94,16 @@ public void initializeSendGrid(String apiKey) {
9094

9195
/**
9296
* Retrieve the current library version.
97+
*
9398
* @return the current version.
9499
*/
95100
public String getLibraryVersion() {
96-
return this.VERSION;
101+
return VERSION;
97102
}
98103

99104
/**
100105
* Get the API version.
106+
*
101107
* @return the current API versioin (v3 by default).
102108
*/
103109
public String getVersion() {
@@ -106,6 +112,7 @@ public String getVersion() {
106112

107113
/**
108114
* Set the API version.
115+
*
109116
* @param version the new version.
110117
*/
111118
public void setVersion(String version) {
@@ -114,6 +121,7 @@ public void setVersion(String version) {
114121

115122
/**
116123
* Obtain the request headers.
124+
*
117125
* @return the request headers.
118126
*/
119127
public Map<String, String> getRequestHeaders() {
@@ -122,6 +130,7 @@ public Map<String, String> getRequestHeaders() {
122130

123131
/**
124132
* Add a new request header.
133+
*
125134
* @param key the header key.
126135
* @param value the header value.
127136
* @return the new set of request headers.
@@ -133,6 +142,7 @@ public Map<String, String> addRequestHeader(String key, String value) {
133142

134143
/**
135144
* Remove a request header.
145+
*
136146
* @param key the header key to remove.
137147
* @return the new set of request headers.
138148
*/
@@ -143,6 +153,7 @@ public Map<String, String> removeRequestHeader(String key) {
143153

144154
/**
145155
* Get the SendGrid host (api.sendgrid.com by default).
156+
*
146157
* @return the SendGrid host.
147158
*/
148159
public String getHost() {
@@ -151,15 +162,16 @@ public String getHost() {
151162

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

160172
/**
161-
* Get the maximum number of retries on a rate limit response.
162-
* The default is 5.
173+
* Get the maximum number of retries on a rate limit response. The default is 5.
174+
*
163175
* @return the number of retries on a rate limit.
164176
*/
165177
public int getRateLimitRetry() {
@@ -168,25 +180,26 @@ public int getRateLimitRetry() {
168180

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

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

187200
/**
188-
* Set the duration of time (in milliseconds) to sleep between
189-
* consecutive rate limit retries.
201+
* Set the duration of time (in milliseconds) to sleep between consecutive rate limit retries.
202+
*
190203
* @param rateLimitSleep the sleep duration.
191204
*/
192205
public void setRateLimitSleep(int rateLimitSleep) {
@@ -195,6 +208,7 @@ public void setRateLimitSleep(int rateLimitSleep) {
195208

196209
/**
197210
* Makes the call to the SendGrid API, override this method for testing.
211+
*
198212
* @param request the request to make.
199213
* @return the response object.
200214
* @throws IOException in case of a network error.
@@ -205,6 +219,7 @@ public Response makeCall(Request request) throws IOException {
205219

206220
/**
207221
* Class api sets up the request to the SendGrid API, this is main interface.
222+
*
208223
* @param request the request object.
209224
* @return the response object.
210225
* @throws IOException in case of a network error.
@@ -226,9 +241,9 @@ public Response api(Request request) throws IOException {
226241
}
227242

228243
/**
229-
* Attempt an API call. This method executes the API call asynchronously
230-
* on an internal thread pool. If the call is rate limited, the thread
231-
* will retry up to the maximum configured time.
244+
* Attempt an API call. This method executes the API call asynchronously on an internal thread
245+
* pool. If the call is rate limited, the thread will retry up to the maximum configured time.
246+
*
232247
* @param request the API request.
233248
*/
234249
public void attempt(Request request) {
@@ -243,10 +258,10 @@ public void response(Response r) {
243258
}
244259

245260
/**
246-
* Attempt an API call. This method executes the API call asynchronously
247-
* on an internal thread pool. If the call is rate limited, the thread
248-
* will retry up to the maximum configured time. The supplied callback
249-
* will be called in the event of an error, or a successful response.
261+
* Attempt an API call. This method executes the API call asynchronously on an internal thread
262+
* pool. If the call is rate limited, the thread will retry up to the maximum configured time. The
263+
* supplied callback will be called in the event of an error, or a successful response.
264+
*
250265
* @param request the API request.
251266
* @param callback the callback.
252267
*/

src/main/java/com/sendgrid/SendGridAPI.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ public interface SendGridAPI {
77

88
/**
99
* Initializes SendGrid
10-
*
10+
*
1111
* @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys
1212
*/
1313
public void initializeSendGrid(String apiKey);
1414

1515
/**
1616
* Returns the library version
17-
*
17+
*
1818
* @return the library version.
1919
*/
2020
public String getLibraryVersion();
@@ -28,20 +28,21 @@ public interface SendGridAPI {
2828

2929
/**
3030
* Sets the version.
31-
*
31+
*
3232
* @param version the SendGrid version.
3333
*/
3434
public void setVersion(String version);
3535

3636
/**
3737
* Gets the request headers.
38+
*
3839
* @return returns a map of request headers.
3940
*/
4041
public Map<String, String> getRequestHeaders();
4142

4243
/**
4344
* Adds a request headers.
44-
*
45+
*
4546
* @param key the key
4647
* @param value the value
4748
* @return returns a map of request headers.
@@ -50,30 +51,29 @@ public interface SendGridAPI {
5051

5152
/**
5253
* Removes a request headers.
53-
*
54+
*
5455
* @param key the key
5556
* @return returns a map of request headers.
5657
*/
5758
public Map<String, String> removeRequestHeader(String key);
5859

5960
/**
6061
* Gets the host.
61-
*
62+
*
6263
* @return returns the host.
6364
*/
6465
public String getHost();
6566

6667
/**
6768
* Sets the host.
68-
*
69+
*
6970
* @param host the host to set
7071
*/
7172
public void setHost(String host);
7273

7374
/**
74-
* Class makeCall makes the call to the SendGrid API, override this method for
75-
* testing.
76-
*
75+
* Class makeCall makes the call to the SendGrid API, override this method for testing.
76+
*
7777
* @param request the request
7878
* @return returns a response.
7979
* @throws IOException in case of network or marshal error.
@@ -82,7 +82,7 @@ public interface SendGridAPI {
8282

8383
/**
8484
* Class api sets up the request to the SendGrid API, this is main interface.
85-
*
85+
*
8686
* @param request the request
8787
* @return returns a response.
8888
* @throws IOException in case of network or marshal error.

0 commit comments

Comments
 (0)