ServerPolicyApiValidationHelper.java 781 Bytes
Newer Older
1 2 3 4
package chat.rocket.android.helper;

import android.support.annotation.NonNull;

5 6
import io.reactivex.Flowable;

7 8 9 10
import chat.rocket.android.api.rest.ServerPolicyApi;

public class ServerPolicyApiValidationHelper {

Tiago Cunha's avatar
Tiago Cunha committed
11
  private final ServerPolicyApi serverPolicyApi;
12

Tiago Cunha's avatar
Tiago Cunha committed
13 14
  public ServerPolicyApiValidationHelper(@NonNull ServerPolicyApi serverPolicyApi) {
    this.serverPolicyApi = serverPolicyApi;
15 16
  }

17
  public Flowable<ServerPolicyHelper.ServerInfoResponse> getApiVersion() {
Tiago Cunha's avatar
Tiago Cunha committed
18 19
    return serverPolicyApi.getApiInfoSecurely()
        .onErrorResumeNext(serverPolicyApi.getApiInfoInsecurely())
Yusuke Iwaki's avatar
Yusuke Iwaki committed
20
        .map(response -> new ServerPolicyHelper.ServerInfoResponse(
Tiago Cunha's avatar
Tiago Cunha committed
21 22 23
            response.getProtocol().equals(ServerPolicyApi.SECURE_PROTOCOL),
            response.getData()
        ));
24 25
  }
}