illiashenkoo / startask-http-code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StartaskHttpCode

JitPack

Represents an HTTP status code in Kotlin for Android.

Using in your projects

Gradle Gradle

The library is published to JitPack repository.

  1. Add the JitPack repository to your root build.gradle at the end of repositories.
allprojects {
    repositories {
        //...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency

${latest.version} is

dependencies {
    implementation "com.github.illiashenkoo:startask-http-code:${latest.version}"
}

Kotlin Usage with Kotlin

  1. Create a HttpStatusCode object
    HttpStatusCode.fromValue(200)
  1. Use HttpStatusCode object
    when (response.toHttpStatusCode()) {
        HttpStatusCode.OK -> {
            // do something
        }
        HttpStatusCode.NotFound -> {
            // do something
        }
        else -> {
            // do something
        }
    }
  1. Use HttpStatusCode object
    val statusCode = response.toHttpStatusCode()
    if(statusCode.isNoContent()){
        //do something
    }
  1. 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

License

Apache License 2.0

Contacts

Oleg Illiashenko

Contributions and releases

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.

About

License:Apache License 2.0


Languages

Language:Kotlin 100.0%