Skip to content

Commit e485b1b

Browse files
Refactor Api, ApiClient, Utils, and MultipartBodyBuilder classes to add private constructors preventing instantiation. Enhance ApiRequest class with additional getter methods for request details, improving code readability. Remove unused JsonMap class.
1 parent 9ff9b98 commit e485b1b

6 files changed

Lines changed: 44 additions & 2 deletions

File tree

src/main/java/io/mochaapi/client/Api.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
public class Api {
2626

27+
/** Private constructor to prevent instantiation. */
28+
private Api() {}
29+
2730
private static final HttpClientEngine DEFAULT_ENGINE = new DefaultHttpClientEngine();
2831
private static final Executor DEFAULT_EXECUTOR = createDefaultExecutor();
2932

src/main/java/io/mochaapi/client/ApiClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ private ApiResponse applyResponseInterceptors(ApiResponse response) {
202202
* Builder class for creating configured ApiClient instances.
203203
*/
204204
public static class Builder {
205+
206+
/** Creates a new Builder instance. */
207+
public Builder() {}
205208
private HttpClientEngine engine;
206209
private Executor executor;
207210
private Duration connectTimeout = Duration.ofSeconds(30);

src/main/java/io/mochaapi/client/ApiRequest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,39 @@ public void async(Consumer<ApiResponse> callback) {
277277
}
278278

279279
// Getters for internal use
280+
/**
281+
* Gets the request URL.
282+
* @return the request URL
283+
*/
280284
public String getUrl() { return url; }
285+
286+
/**
287+
* Gets the HTTP method.
288+
* @return the HTTP method
289+
*/
281290
public String getMethod() { return method; }
291+
292+
/**
293+
* Gets the request headers.
294+
* @return the request headers
295+
*/
282296
public Map<String, String> getHeaders() { return headers; }
297+
298+
/**
299+
* Gets the query parameters.
300+
* @return the query parameters
301+
*/
283302
public Map<String, Object> getQueryParams() { return queryParams; }
303+
304+
/**
305+
* Gets the request body.
306+
* @return the request body
307+
*/
284308
public Object getBody() { return body; }
309+
310+
/**
311+
* Checks if this is a multipart request.
312+
* @return true if this is a multipart request
313+
*/
285314
public boolean isMultipart() { return isMultipart; }
286315
}

src/main/java/io/mochaapi/client/JsonMap renamed to src/main/java/io/mochaapi/client/JsonMap.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* ApiResponse response = Api.get("https://api.example.com/user").execute();
1515
*
1616
* // Traditional approach (verbose with casting)
17-
* Map<String, Object> data = response.toMap();
18-
* String city = ((Map<String, Object>)((Map<String, Object>)data.get("user")).get("address")).get("city").toString();
17+
* Map&lt;String, Object&gt; data = response.toMap();
18+
* String city = ((Map&lt;String, Object&gt;)((Map&lt;String, Object&gt;)data.get("user")).get("address")).get("city").toString();
1919
*
2020
* // JsonMap approach (clean chaining)
2121
* String city = response.toJsonMap().get("user").get("address").get("city").toString();
@@ -29,6 +29,7 @@
2929
*/
3030
public class JsonMap extends HashMap<String, Object> {
3131

32+
/** Internal field to wrap primitive values for chaining. */
3233
private Object wrappedValue = null;
3334

3435
/**

src/main/java/io/mochaapi/client/internal/Utils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*/
1515
public class Utils {
1616

17+
/** Private constructor to prevent instantiation. */
18+
private Utils() {}
19+
1720
// Pattern to match dangerous URL schemes that could be used for open redirects
1821
private static final Pattern DANGEROUS_SCHEMES = Pattern.compile(
1922
"^(javascript|data|vbscript|file|ftp):", Pattern.CASE_INSENSITIVE);

src/main/java/io/mochaapi/client/multipart/MultipartBodyBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*/
1818
public class MultipartBodyBuilder {
1919

20+
/** Private constructor to prevent instantiation. */
21+
private MultipartBodyBuilder() {}
22+
2023
private static final String BOUNDARY_PREFIX = "----MochaAPI-";
2124
private static final String CRLF = "\r\n";
2225
private static final long DEFAULT_MAX_FILE_SIZE = 50 * 1024 * 1024; // 50MB default limit

0 commit comments

Comments
 (0)