Search in sources :

Example 1 with Rx2ANRequest

use of com.rx2androidnetworking.Rx2ANRequest in project Fast-Android-Networking by amitshekhariitbhu.

the class Rx2ApiTestActivity method checkForHeaderPost.

public void checkForHeaderPost(View view) {
    Rx2ANRequest.PostRequestBuilder postRequestBuilder = Rx2AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.CHECK_FOR_HEADER);
    postRequestBuilder.addHeaders("token", "1234");
    Rx2ANRequest rxAnRequest = postRequestBuilder.setTag(this).build();
    rxAnRequest.setAnalyticsListener(new AnalyticsListener() {

        @Override
        public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
            Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
            Log.d(TAG, " bytesSent : " + bytesSent);
            Log.d(TAG, " bytesReceived : " + bytesReceived);
            Log.d(TAG, " isFromCache : " + isFromCache);
        }
    });
    rxAnRequest.getJSONObjectSingle().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<JSONObject>() {

        @Override
        public void onSubscribe(@NonNull Disposable disposable) {
        }

        @Override
        public void onSuccess(@NonNull JSONObject jsonObject) {
            Log.d(TAG, "onResponse object : " + jsonObject.toString());
            Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
        }

        @Override
        public void onError(@NonNull Throwable throwable) {
            Utils.logError(TAG, throwable);
        }
    });
}
Also used : Rx2ANRequest(com.rx2androidnetworking.Rx2ANRequest) Disposable(io.reactivex.disposables.Disposable) AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) JSONObject(org.json.JSONObject)

Aggregations

AnalyticsListener (com.androidnetworking.interfaces.AnalyticsListener)1 Rx2ANRequest (com.rx2androidnetworking.Rx2ANRequest)1 Disposable (io.reactivex.disposables.Disposable)1 JSONObject (org.json.JSONObject)1