Skip to content

Instantly share code, notes, and snippets.

@bl-lia
Created February 7, 2016 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bl-lia/49130ad9d9730c826d02 to your computer and use it in GitHub Desktop.
Save bl-lia/49130ad9d9730c826d02 to your computer and use it in GitHub Desktop.
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