Skip to content

Commit c89b689

Browse files
committed
Hotfix for URI.post extension
1 parent a5e6c24 commit c89b689

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
- Add GET and POST extension functions to URI for JSON handling
2-
- Add toException method to WrappedException for better exception handling
1+
Hotfix for `URI.post` extension

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = 'eth.likespro'
8-
version = '1.5.0'
8+
version = '1.5.1'
99

1010
sourceCompatibility = 17
1111
targetCompatibility = 17

src/main/java/eth/likespro/commons/network/NetworkUtils.kt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class NetworkUtils {
3030
}
3131

3232
/**
33-
* Sends a GET request to the given URI and returns the response as a JSONObject.
33+
* Sends a GET request to the given URI and returns the response as a String.
3434
*
35-
* @return The response body as a JSONObject.
35+
* @return The response body as String.
3636
*/
37-
fun URI.get(): JSONObject {
37+
fun URI.get(): String {
3838
val response = HttpClient.newBuilder()
3939
.build()
4040
.send(
@@ -43,27 +43,25 @@ class NetworkUtils {
4343
.build(),
4444
HttpResponse.BodyHandlers.ofString()
4545
)
46-
return JSONObject(response.body())
46+
return response.body()
4747
}
4848

4949
/**
50-
* Sends a POST request to the given URI with the specified JSON body.
50+
* Sends a POST request to the given URI with the specified body and returns the response as a String.
5151
*
52-
* @param body The JSON body to be sent in the POST request.
52+
* @param body The body of the POST request.
53+
* @return The response body as String.
5354
*/
54-
fun URI.post(body: JSONObject) {
55-
HttpClient.newBuilder()
55+
fun URI.post(body: String): String {
56+
return HttpClient.newBuilder()
5657
.build()
5758
.send(
5859
HttpRequest.newBuilder(this)
5960
.header("Content-Type", "application/json")
60-
.POST(HttpRequest.BodyPublishers.ofString(JSONObject().apply {
61-
put("functionName", "ping")
62-
put("functionArgs", JSONObject())
63-
}.toString()))
61+
.POST(HttpRequest.BodyPublishers.ofString(body))
6462
.build(),
6563
HttpResponse.BodyHandlers.ofString()
66-
)
64+
).body()
6765
}
6866
}
6967
}

0 commit comments

Comments
 (0)