Skip to content

Commit

Permalink
Changes in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Miotti committed Oct 2, 2020
1 parent fa71b7d commit 3ef84b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import retrofit2.Response
/**
* An adapter that converts Retrofit's responses to other, more specific, ones
* depending on network status codes or failures when using Kotlin's Coroutines.
*
* @param <T> the type of object expected to be returned from the API call
* It will return a [NetworkResponse] object indicating operation result.
*/
object NetworkRequestHandler {

/**
* Static method that allows to execute requests and returns a NetworkResponse object {@link NetworkResponse}
* depending on HTTP response
*
* @param block is a suspend function of Response<T> type
* Static method that allows to execute requests from a [suspend] function of [Response] type
* and returns a [NetworkResponse] object depending on HTTP response.
*/
suspend fun <T : Response<*>> safeApiCall(block: suspend () -> T): NetworkResponse<T> =
try {
Expand All @@ -34,27 +31,24 @@ sealed class NetworkResponse<T> {
/**
* Successful HTTP response from the server.
* The server received the request, answered it and the response is not of an error type.
*
* @param response the API JSON response converted to a Java/Kotlin object.
* The API response code is included in the response object.
* It will return a [T] object, the API JSON response converted to a Java/Kotlin object,
* which includes the API response code.
*/
data class Success<T>(val response: T) : NetworkResponse<T>()

/**
* Successful HTTP response from the server, but has an error body.
* The server received the request, answered it and reported an error.
*
* @param response the API JSON response converted to a Java/Kotlin object.
* The API response code is included in the response object.
* It will return a [T], the API JSON response converted to a Java/Kotlin object,
* which includes the API response code.
*/
data class Error<T>(val response: T) : NetworkResponse<T>()

/**
* The HTTP request to the server failed on the local device, no data was transmitted.
* Invoked when a network or unexpected exception occurred during the HTTP request, meaning
* that the request couldn't be executed.
*
* @param t A Throwable with the cause of the call failure
* that the request couldn't be executed. The cause of the failure will be given through a
* [Throwable] object
*/
data class Failure<T>(val t: Throwable) : NetworkResponse<T>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class NetworkRequestHandlerTest {
// GIVEN
val apiResponse = mock(Response::class.java) as Response<Any>


// WHEN
`when`(apiResponse.isSuccessful).thenReturn(true)

Expand Down

0 comments on commit 3ef84b4

Please sign in to comment.