1414 * limitations under the License.
1515 */
1616
17-
17+ import io.reactivex.Single
1818import kotlinx.coroutines.experimental.CommonPool
1919import kotlinx.coroutines.experimental.launch
20- import kotlinx.coroutines.experimental.rx1.awaitSingle
20+ import kotlinx.coroutines.experimental.rx2.await
2121import retrofit2.Retrofit
22- import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
22+ import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
2323import retrofit2.converter.gson.GsonConverterFactory
2424import retrofit2.http.GET
2525import retrofit2.http.Path
26- import rx.Observable
2726
2827interface GitHub {
2928 @GET(" /repos/{owner}/{repo}/contributors" )
3029 fun contributors (
3130 @Path(" owner" ) owner : String ,
3231 @Path(" repo" ) repo : String
33- ): Observable <List <Contributor >>
32+ ): Single <List <Contributor >>
3433
3534 @GET(" users/{user}/repos" )
36- fun listRepos (@Path(" user" ) user : String ): Observable <List <Repo >>
35+ fun listRepos (@Path(" user" ) user : String ): Single <List <Repo >>
3736}
3837
3938data class Contributor (val login : String , val contributions : Int )
@@ -43,21 +42,21 @@ fun main(args: Array<String>) {
4342 val retrofit = Retrofit .Builder ().apply {
4443 baseUrl(" https://api.github.com" )
4544 addConverterFactory(GsonConverterFactory .create())
46- addCallAdapterFactory(RxJavaCallAdapterFactory .create())
45+ addCallAdapterFactory(RxJava2CallAdapterFactory .create())
4746 }.build()
4847
4948 val github = retrofit.create(GitHub ::class .java)
5049
5150 launch(CommonPool ) {
5251 val contributors =
5352 github.contributors(" JetBrains" , " Kotlin" )
54- .awaitSingle ().take(10 )
53+ .await ().take(10 )
5554
5655 for ((name, contributions) in contributors) {
5756 println (" $name has $contributions contributions, other repos: " )
5857
5958 val otherRepos =
60- github.listRepos(name).awaitSingle ()
59+ github.listRepos(name).await ()
6160 .map(Repo ::name).joinToString(" , " )
6261
6362 println (otherRepos)
0 commit comments