Search in sources :

Example 1 with ResultMapReverse

use of com.fanap.podchat.model.ResultMapReverse in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method mapReverse.

public String mapReverse(RequestMapReverse request) {
    String uniqueId = null;
    if (chatReady) {
        double lat = request.getLat();
        double lng = request.getLng();
        uniqueId = generateUniqueId();
        RetrofitHelperMap retrofitHelperMap = new RetrofitHelperMap("https://api.neshan.org/");
        MapApi mapApi = retrofitHelperMap.getService(MapApi.class);
        Observable<Response<MapReverse>> observable = mapApi.mapReverse(API_KEY_MAP, lat, lng);
        String finalUniqueId = uniqueId;
        observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(mapReverseResponse -> {
            if (mapReverseResponse.isSuccessful()) {
                MapReverse mapReverse = mapReverseResponse.body();
                if (mapReverse == null) {
                    captureError(ChatConstant.ERROR_UNKNOWN_EXCEPTION, ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, finalUniqueId);
                    return;
                }
                ChatResponse<ResultMapReverse> chatResponse = new ChatResponse<>();
                ResultMapReverse resultMap = new ResultMapReverse();
                String address = mapReverse.getAddress();
                if (!Util.isNullOrEmpty(address)) {
                    resultMap.setAddress(address);
                }
                resultMap.setCity(mapReverse.getCity());
                resultMap.setIn_odd_even_zone(mapReverse.isIn_odd_even_zone());
                resultMap.setIn_traffic_zone(mapReverse.isIn_traffic_zone());
                resultMap.setMunicipality_zone(mapReverse.getMunicipality_zone());
                resultMap.setNeighbourhood(mapReverse.getNeighbourhood());
                resultMap.setState(mapReverse.getState());
                chatResponse.setUniqueId(finalUniqueId);
                chatResponse.setResult(resultMap);
                String json = gson.toJson(chatResponse);
                listenerManager.callOnMapReverse(json, chatResponse);
                showLog("RECEIVE_MAP_REVERSE", json);
            } else {
                try {
                    String errorBody;
                    if (mapReverseResponse.errorBody() != null) {
                        errorBody = mapReverseResponse.errorBody().string();
                        JSONObject jObjError = new JSONObject(errorBody);
                        String errorMessage = jObjError.getString("message");
                        int errorCode = jObjError.getInt("code");
                        captureError(errorMessage, errorCode, finalUniqueId);
                    }
                } catch (JSONException e) {
                    captureError(e.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, finalUniqueId, e);
                } catch (IOException e) {
                    captureError(e.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, finalUniqueId, e);
                }
            }
        }, (Throwable throwable) -> captureError(throwable.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, finalUniqueId, throwable));
    }
    return uniqueId;
}
Also used : ResultMapReverse(com.fanap.podchat.model.ResultMapReverse) RequestMapReverse(com.fanap.podchat.requestobject.RequestMapReverse) MapReverse(com.fanap.podchat.mainmodel.MapReverse) JSONException(org.json.JSONException) IOException(java.io.IOException) ResultMapReverse(com.fanap.podchat.model.ResultMapReverse) RetrofitHelperMap(com.fanap.podchat.networking.retrofithelper.RetrofitHelperMap) ChatResponse(com.fanap.podchat.model.ChatResponse) Response(retrofit2.Response) MapApi(com.fanap.podchat.networking.api.MapApi) JSONObject(org.json.JSONObject) ChatResponse(com.fanap.podchat.model.ChatResponse)

Aggregations

MapReverse (com.fanap.podchat.mainmodel.MapReverse)1 ChatResponse (com.fanap.podchat.model.ChatResponse)1 ResultMapReverse (com.fanap.podchat.model.ResultMapReverse)1 MapApi (com.fanap.podchat.networking.api.MapApi)1 RetrofitHelperMap (com.fanap.podchat.networking.retrofithelper.RetrofitHelperMap)1 RequestMapReverse (com.fanap.podchat.requestobject.RequestMapReverse)1 IOException (java.io.IOException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Response (retrofit2.Response)1