Skip to content

Commit

Permalink
Response body ext improvements #132 (#133)
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
rybalkinsd and DeviantBadge committed Aug 4, 2019
1 parent d63a722 commit 1889895
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .codecov.yaml
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
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()

0 comments on commit 1889895

Please sign in to comment.