-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* 1. closing body 2. added explicit types 3. added docs * changed patch configuration for codcov * Update kohttp/src/main/kotlin/io/github/rybalkinsd/kohttp/ext/ResponseExt.kt Co-Authored-By: DeviantBadge <zhenya_vorobyov@mail.ru> * Update kohttp/src/main/kotlin/io/github/rybalkinsd/kohttp/ext/ResponseExt.kt Co-Authored-By: DeviantBadge <zhenya_vorobyov@mail.ru>
- Loading branch information
1 parent
d63a722
commit 1889895
Showing
2 changed files
with
16 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
status: | ||
project: | ||
default: | ||
target: 90 | ||
target: 90 | ||
patch: | ||
default: | ||
enabled: no |
17 changes: 12 additions & 5 deletions
17
kohttp/src/main/kotlin/io/github/rybalkinsd/kohttp/ext/ResponseExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
package io.github.rybalkinsd.kohttp.ext | ||
|
||
import okhttp3.Response | ||
|
||
import java.io.InputStream | ||
|
||
/** | ||
* Returns Response Body as String. | ||
* | ||
* @return Response body as a `String?`. | ||
* <p> | ||
* Note: This function will close `ResponseBody` | ||
* </p> | ||
* @since 0.9.0 | ||
* @author gokul | ||
* @author gokul, sergey | ||
*/ | ||
fun Response.asString() = body()?.string() | ||
fun Response.asString(): String? = body()?.use { it.string() } | ||
|
||
/** | ||
* Returns Response Body as a Stream. | ||
* Returns Response Body as a Stream. | ||
* | ||
* | ||
* @return Response body as a `InputStream?`. | ||
* <p> | ||
* Note: Response stream must be closed after use | ||
* </p> | ||
* @since 0.9.0 | ||
* @author gokul | ||
*/ | ||
fun Response.asStream() = body()?.byteStream() | ||
fun Response.asStream(): InputStream? = body()?.byteStream() |