Created
September 24, 2017 22:32
-
-
Save pymblesoftware/30a26505af653a495f95983ad1528958 to your computer and use it in GitHub Desktop.
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
// API class | |
@retrofit2.http.PUT("/api/v1/user/logout") | |
fun logout( @Header("Authorization") token: String) : io.reactivex.Observable<Void> | |
// Repository class | |
fun logout(token: String) : io.reactivex.Observable<Void> { | |
return apiService.logout("Bearer " + token) | |
} | |
// network wrapper class | |
fun logout( context: Context, successHandler : () -> Unit, errorHandler: () -> Unit ) { | |
if (token != null) { | |
compositeDisposable.add( | |
repository.logout(token!!) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribeOn(Schedulers.io()) | |
.subscribe({ result -> | |
// Need to be looking for a 204 here. | |
if (result != null) { | |
Log.d("RR:", "Result ${result}") | |
successHandler() | |
} | |
Log.d(MainActivity.TAG, "*** Success ***") | |
}, { | |
// Error null pointer exception comes from it is a 204, empty response. | |
// java.lang.NullPointerException: Null is not a valid element | |
error -> | |
Log.d(MainActivity.TAG, "Error: ${error}") | |
error.printStackTrace() | |
errorHandler() | |
}) | |
) | |
} else { | |
Log.d(TAG, "*** NO TOKEN ***") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment