相关疑难解决方法(0)

如何在 RxJava 2 自定义运算符的 onSubscribe 上获取 RetroFit 请求的 URL 和方法?

因此,我尝试集成 Http 请求的 Firebase 性能并手动添加它们,如此处所示步骤 9)。

我正在使用 Retrofit 2 和 RxJava 2,所以我想到了做一个自定义运算符,检查下面的代码:

改造 2 客户端

@GET("branch-{environment}/v2/branches")
    fun getBranch(@Path("environment") environment: String, @Query("location") location: String, @Query("fulfilment_type") fulfilmentType: String): Single<Response<GetBranchResponse>>
Run Code Online (Sandbox Code Playgroud)

RxJava 调用 Retrofit 客户端

private val client: BranchClient = clientFactory.create(urlProvider.apiUrl)

override fun getBranch(postCode: String, fulfilmentType: FulfilmentType): Single<GetBranchResponse> {
        return client
                .getBranch(environment, postCode.toUpperCase(), fulfilmentType.toString())
                .lift(RxHttpPerformanceSingleOperator(URL?, METHOD?))
                .map { it.body() }
                .subscribeIO() //custom Kotlin extension 
                .observeMain() //custom Kotlin extension 
                ...
    } 
Run Code Online (Sandbox Code Playgroud)

RxJava 2 自定义操作符通过 lift:

class RxHttpPerformanceSingleOperator<T>(private val url: String, private val method: …
Run Code Online (Sandbox Code Playgroud)

kotlin firebase retrofit2 rx-java2 firebase-performance

2
推荐指数
1
解决办法
1244
查看次数