Search in sources :

Example 1 with SSOApi

use of com.fanap.podchat.networking.api.SSOApi in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method deviceIdRequest.

private void deviceIdRequest(String ssoHost, String serverAddress, String appId, String severName) {
    showLog("GET_DEVICE_ID", "");
    currentDeviceExist = false;
    RetrofitHelperSsoHost retrofitHelperSsoHost = new RetrofitHelperSsoHost(ssoHost);
    SSOApi SSOApi = retrofitHelperSsoHost.getService(SSOApi.class);
    rx.Observable<Response<DeviceResult>> listObservable = SSOApi.getDeviceId("Bearer" + " " + getToken());
    listObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(deviceResults -> {
        if (deviceResults.isSuccessful()) {
            ArrayList<Device> devices = null;
            if (deviceResults.body() != null) {
                devices = deviceResults.body().getDevices();
            }
            for (Device device : devices) {
                if (device.isCurrent()) {
                    currentDeviceExist = true;
                    showLog("DEVICE_ID :" + device.getUid(), "");
                    async.connect(serverAddress, appId, severName, token, ssoHost, device.getUid());
                    break;
                }
            }
            if (!currentDeviceExist) {
                captureError(ChatConstant.ERROR_CURRENT_DEVICE, ChatConstant.ERROR_CODE_CURRENT_DEVICE, null);
            }
        } else {
            if (deviceResults.code() == 401) {
                captureError("unauthorized", deviceResults.code(), null);
            } else {
                captureError(deviceResults.message(), deviceResults.code(), null);
            }
        }
    }, (Throwable throwable) -> {
        if (log)
            Log.e(TAG, "Error on get devices" + throwable.getMessage());
    });
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) Response(retrofit2.Response) SSOApi(com.fanap.podchat.networking.api.SSOApi) Device(com.fanap.podasync.model.Device) RetrofitHelperSsoHost(com.fanap.podchat.networking.retrofithelper.RetrofitHelperSsoHost)

Aggregations

Device (com.fanap.podasync.model.Device)1 ChatResponse (com.fanap.podchat.model.ChatResponse)1 SSOApi (com.fanap.podchat.networking.api.SSOApi)1 RetrofitHelperSsoHost (com.fanap.podchat.networking.retrofithelper.RetrofitHelperSsoHost)1 Response (retrofit2.Response)1