Created
December 17, 2018 09:52
-
-
Save timsheu/1d27a439287e8601fce4ebb730b65862 to your computer and use it in GitHub Desktop.
Retrofit with RxKotlin sample
This file contains hidden or 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
| package com.nuvoton.nupowerstation | |
| import com.nuvoton.nupowerstation.model.RequestLogin | |
| import com.nuvoton.nupowerstation.model.ResponseLogin | |
| import io.reactivex.Observable | |
| import retrofit2.Retrofit | |
| import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory | |
| import retrofit2.converter.gson.GsonConverterFactory | |
| import retrofit2.http.Body | |
| import retrofit2.http.HeaderMap | |
| import retrofit2.http.POST | |
| interface NPSWebAPIInterface { | |
| @POST("login") | |
| abstract fun postLogin(@Body request: RequestLogin, | |
| @HeaderMap header: HashMap<String, String>) : Observable<ResponseLogin> | |
| companion object Factory { | |
| val baseUrl = "https://5x1san66yg.execute-api.us-east-1.amazonaws.com/prod/" | |
| fun create(): NPSWebAPIInterface { | |
| val retrofit = Retrofit.Builder() | |
| .baseUrl(baseUrl) | |
| .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | |
| .addConverterFactory(GsonConverterFactory.create()) | |
| .build() | |
| return retrofit.create(NPSWebAPIInterface::class.java) | |
| } | |
| } | |
| } | |
| //interface NPSGetSTSToken{ | |
| // @POST("") | |
| //} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment