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;
}
});
}
Aggregations