网络请求接口封装方式

最近需要给别人做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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值