Created
February 7, 2016 08:11
-
-
Save bl-lia/49130ad9d9730c826d02 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
import retrofit2.GsonConverterFactory | |
import retrofit2.Retrofit | |
import retrofit2.RxJavaCallAdapterFactory | |
import retrofit2.http.GET | |
import rx.Observable | |
import rx.Scheduler | |
import rx.android.schedulers.AndroidSchedulers | |
import rx.schedulers.Schedulers | |
import java.util.concurrent.TimeUnit | |
class ApiSample() { | |
data class Item(val id: String, val title: String) | |
interface ItemService { | |
@GET("/api/v2/items") | |
fun items(): Observable<List<Item>> | |
} | |
fun api() { | |
val retrofit = Retrofit.Builder() | |
.baseUrl("http://qiita.com") | |
.addConverterFactory(GsonConverterFactory.create()) | |
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()) | |
.build(); | |
val service = retrofit.create(ItemService::class.java) | |
service.items().subscribe { it.map { println(it.title) } } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment