Search in sources :

Example 1 with FavoriteException

use of com.dante.exception.FavoriteException in project 91Pop by DanteAndroid.

the class AppApiHelper method favoritePorn91Video.

@Override
public Observable<String> favoritePorn91Video(String uId, String videoId, String ownnerId) {
    String cpaintFunction = "addToFavorites";
    String responseType = "json";
    return noLimit91PornServiceApi.favoriteVideo(cpaintFunction, uId, videoId, ownnerId, responseType, HeaderUtils.getIndexHeader(addressHelper)).map(new Function<String, Favorite>() {

        @Override
        public Favorite apply(String s) throws Exception {
            Logger.t(TAG).d("favoriteStr: " + s);
            return new Gson().fromJson(s, Favorite.class);
        }
    }).map(new Function<Favorite, Integer>() {

        @Override
        public Integer apply(Favorite favorite) throws Exception {
            return favorite.getAddFavMessage().get(0).getData();
        }
    }).map(new Function<Integer, String>() {

        @Override
        public String apply(Integer code) throws Exception {
            String msg;
            switch(code) {
                case Favorite.FAVORITE_SUCCESS:
                    msg = "收藏成功";
                    break;
                case Favorite.FAVORITE_FAIL:
                    throw new FavoriteException("收藏失败");
                case Favorite.FAVORITE_ALREADY:
                    throw new FavoriteException("已经收藏过了");
                case Favorite.FAVORITE_YOURSELF:
                    throw new FavoriteException("不能收藏自己的视频");
                default:
                    throw new FavoriteException("收藏失败");
            }
            return msg;
        }
    });
}
Also used : Favorite(com.dante.data.model.Favorite) Function(io.reactivex.functions.Function) FavoriteException(com.dante.exception.FavoriteException) Gson(com.google.gson.Gson) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

Aggregations

Favorite (com.dante.data.model.Favorite)1 FavoriteException (com.dante.exception.FavoriteException)1 MessageException (com.dante.exception.MessageException)1 Gson (com.google.gson.Gson)1 Function (io.reactivex.functions.Function)1