Represents an HTTP status code in Kotlin for Android.
The library is published to JitPack repository.
- Add the JitPack repository to your root build.gradle at the end of repositories.
allprojects {
repositories {
//...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
implementation "com.github.illiashenkoo:startask-http-code:${latest.version}"
}
- Create a
HttpStatusCode
object
HttpStatusCode.fromValue(200)
- Use
HttpStatusCode
object
when (response.toHttpStatusCode()) {
HttpStatusCode.OK -> {
// do something
}
HttpStatusCode.NotFound -> {
// do something
}
else -> {
// do something
}
}
- Use
HttpStatusCode
object
val statusCode = response.toHttpStatusCode()
if(statusCode.isNoContent()){
//do something
}
- Extension function for Retrofit2 Response
import net.codecision.startask.http.code.HttpStatusCode
import retrofit2.Response
fun <T> Response<T>.toHttpStatusCode(): HttpStatusCode {
return HttpStatusCode.fromValue(code())
}
Look at the examples of using the library
All development (both new features and bug fixes) is performed in develop
branch.
This way master
sources always contain sources of the most recently released version.
Please send PRs with bug fixes to develop
branch.
Fixes to documentation in markdown files are an exception to this rule. They are updated directly in master
.
The develop
branch is pushed to master
during release.