网络请求接口封装方式

来源:互联网 发布:用mac给iphone装软件 编辑:程序博客网 时间:2024/05/21 10:44

最近需要给别人做sdk,所以很多需要封装的接口,网络请求的。

这个需求是type不能暴露在方法里面,但是上传服务器必须要有type这个参数。


<span style="font-size:14px;">public class LetvPlayServiceBusiness implements IMultiPublicBusiness {    private IHttpManager httpManager;    private Context context;    public LetvPlayServiceBusiness(Context context) {        this.context = context;        httpManager = HttpFactory.getInstance(context).getKaraokeHttpManager();    }    /**     * 收藏列表(获取全部作品列表)     *     * @param start     * @param length     * @param callBack     */    @Override    public void getAllProductList(int start, int length, BusinessCallBack<LetvCollectionListResult> callBack) {        getProductList(LoginManager.defaultManager().getUserId(),0,start, length, callBack);    }    /**     * 历史记录(作品)     *     * @param start     * @param length     * @param callBack     */    @Override    public void getHistoryMusicLibraryList(int start, int length, BusinessCallBack<LetvHistoryResult> callBack) {        getMyHistoryList(start, length, 2, callBack);    }    private void getProductList(int userid, int type, int start, int length, BusinessCallBack<LetvCollectionListResult> callBack) {        TypeReference<LetvCollectionListResult> typeReference = new TypeReference<LetvCollectionListResult>() {        };        HttpRequestParams params = new HttpRequestParams();        params.put("userid", userid);        params.put("type", type);        params.put("start", start);        params.put("length", length);        httpManager.request(context, "/tian/ugc/getMvList.action", params, typeReference, callBack, KaraokeHttpManager.METHOD_GET);    }    private void getMyHistoryList(int start, int length, int type, BusinessCallBack<LetvHistoryResult> callBack) {        TypeReference<LetvHistoryResult> typeReference = new TypeReference<LetvHistoryResult>() {        };        HttpRequestParams params = new HttpRequestParams();        params.put("start", start);        params.put("length", length);        params.put("type", type);        httpManager.request(context, "/tian/ugc/getMyDownList.action", params, typeReference, callBack, KaraokeHttpManager.METHOD_GET);    }</span>

其实就是把接口数据具体化,把type的参数定死,然后抽取出来,直接传进去就行。
























0 0
原创粉丝点击