14
14
* limitations under the License.
15
15
*/
16
16
17
-
17
+ import io.reactivex.Single
18
18
import kotlinx.coroutines.experimental.CommonPool
19
19
import kotlinx.coroutines.experimental.launch
20
- import kotlinx.coroutines.experimental.rx1.awaitSingle
20
+ import kotlinx.coroutines.experimental.rx2.await
21
21
import retrofit2.Retrofit
22
- import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
22
+ import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
23
23
import retrofit2.converter.gson.GsonConverterFactory
24
24
import retrofit2.http.GET
25
25
import retrofit2.http.Path
26
- import rx.Observable
27
26
28
27
interface GitHub {
29
28
@GET(" /repos/{owner}/{repo}/contributors" )
30
29
fun contributors (
31
30
@Path(" owner" ) owner : String ,
32
31
@Path(" repo" ) repo : String
33
- ): Observable <List <Contributor >>
32
+ ): Single <List <Contributor >>
34
33
35
34
@GET(" users/{user}/repos" )
36
- fun listRepos (@Path(" user" ) user : String ): Observable <List <Repo >>
35
+ fun listRepos (@Path(" user" ) user : String ): Single <List <Repo >>
37
36
}
38
37
39
38
data class Contributor (val login : String , val contributions : Int )
@@ -43,21 +42,21 @@ fun main(args: Array<String>) {
43
42
val retrofit = Retrofit .Builder ().apply {
44
43
baseUrl(" https://api.github.com" )
45
44
addConverterFactory(GsonConverterFactory .create())
46
- addCallAdapterFactory(RxJavaCallAdapterFactory .create())
45
+ addCallAdapterFactory(RxJava2CallAdapterFactory .create())
47
46
}.build()
48
47
49
48
val github = retrofit.create(GitHub ::class .java)
50
49
51
50
launch(CommonPool ) {
52
51
val contributors =
53
52
github.contributors(" JetBrains" , " Kotlin" )
54
- .awaitSingle ().take(10 )
53
+ .await ().take(10 )
55
54
56
55
for ((name, contributions) in contributors) {
57
56
println (" $name has $contributions contributions, other repos: " )
58
57
59
58
val otherRepos =
60
- github.listRepos(name).awaitSingle ()
59
+ github.listRepos(name).await ()
61
60
.map(Repo ::name).joinToString(" , " )
62
61
63
62
println (otherRepos)
0 commit comments