更方便的使用retrofit2,兼容retrofit1.x

来源:互联网 发布:淘宝网披肩女装 编辑:程序博客网 时间:2024/06/05 06:05

RetrofitPlus

retrofit2的扩展库,方便的使用https、callback、兼容retrofit1.x的用法

【Github源码地址,欢迎Star和Follow】

Feature

1、已经 rebase 到最新 retrofit2 代码(目前是最新的retrofit2.0.1),支持原生 retrofit2 所有特性。

2、增加@HTTPS Annotation,可以灵活配置哪些方法使用 https。

例如:

@HTTPS@GET("/search/users")Call<GitResult> getUsersByName(@Query("q") String name);

3、为 okhttp3 的 https 设置certificate pinning。

例如:
* 将证书文件放入assets文件夹

OkHttpClientUtil.getSSLClient(okClient, context, "xxx.pem");
  • 直接设置证书字符串
OkHttpClientUtil.getSSLClientByCertificateString(okClient,  certificateString);

4、兼容 Retrofit 1.x,可以把 callback 放到参数里,执行方法后直接发送异步请求,此时方法返回值必须void。

例如:

@GET("/search/users")void getUsersByName2(@Query("q") String name, Callback<GitResult> callback);

5、添加 RetrofitPlusCallBack 类,回调方法更完整清晰

onCallStart();onCallFinish();onHttpSuccess(Call<T> call, Response<T> response);onHttpFailure(Call<T> call, Response<T> response);onNetFailure(Call<T> call, Throwable t);

Usage

repositories {    maven {        url "https://jitpack.io"    }}dependencies {    compile 'com.github.MasonLiuChn:RetrofitPlus:2.0.1.0'}

Demo:https://github.com/MasonLiuChn/RetrofitPlus/tree/master/retrofit-plus-demo

Usage of retrofit2.0:https://realm.io/cn/news/droidcon-jake-wharton-simple-http-retrofit-2

Contact me:

  • Blog:http://blog.csdn.net/masonblog

  • Email:MasonLiuChn@gmail.com

0 0
原创粉丝点击