rxjava, retrofit packaging is used to process network requests
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
rxpal
README.md

README.md

rxpal

rxjava, retrofit packaging is used to process network requests

How to use?

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.hawkyAndroid:rxpal:0.2'
}

Step 3. Extends GeneralSubscriber(Built-In) Or Custom Subscriber

for example:

public class MySubscriber extends GeneralSubscriber {

public MySubscriber(Context context, boolean cancelable, CallBack callBack) {
    super(context, cancelable, callBack);
}

public MySubscriber(Context context, CallBack callBack) {
    super(context, callBack);
}

@Override
public void onNext(String result) {
   // execute successful, do something...
   // callBack.onSuccess(new Gson(), data);...
   // callBack.onFailure(code, errMsg);...
}

@Override
public void onError(Throwable e, int code) {
    super.onError(e, code);
   // execute failed, do something...
   // callBack.onFailure(code, errMsg);...
}

}

Step 4. You can init Rxpal in Application with onCreate()

RxPal.init("http://xxx.xxx.com/", true);

Step 5. At last, You can wrap it as a RestfulApi.

public class RestfulApi {

/**
 * POST Request
 *
 * @param url        Request url
 * @param headers    Request headers
 * @param params     Request params
 * @param context    Context
 * @param cancelable whether or not can cancel request
 * @param callBack   callback interface
 */
 public static Subscription post(String url, Map<String, String> headers, Object params, Context context, boolean cancelable, GeneralSubscriber.CallBack callBack) {
    return RxPal.post(url, headers, params, new MySubscriber(context, cancelable, callBack));
}

// other warpped method for request...

}

Execution

RestfulApi.post(url, headers, params, this, false, new GeneralSubscriber.CallBack() {
    @Override
    public void onSuccess(Gson gson, String s) {
        // Log.d(TAG,"s:" + s);
    }

    @Override
    public void onFailure(int code, String error) {
        // Log.d(TAG,"code:" + code + ",error:" + error);
    }
});

To Do

Upload file, download file.