use of com.hippo.ehviewer.client.exception.EhException in project EhViewer by seven332.
the class EhEngine method addFavorites.
/**
* @param dstCat -1 for delete, 0 - 9 for cloud favorite, others throw Exception
* @param note max 250 characters
*/
public static Void addFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient, long gid, String token, int dstCat, String note) throws Exception {
String catStr;
if (dstCat == -1) {
catStr = "favdel";
} else if (dstCat >= 0 && dstCat <= 9) {
catStr = String.valueOf(dstCat);
} else {
throw new EhException("Invalid dstCat: " + dstCat);
}
FormBody.Builder builder = new FormBody.Builder();
builder.add("favcat", catStr);
builder.add("favnote", note != null ? note : "");
// submit=Add+to+Favorites is not necessary, just use submit=Apply+Changes all the time
builder.add("submit", "Apply Changes");
builder.add("update", "1");
String url = EhUrl.getAddFavorites(gid, token);
Log.d(TAG, url);
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).post(builder.build()).build();
Call call = okHttpClient.newCall(request);
// Put call
if (null != task) {
task.setCall(call);
}
String body = null;
Headers headers = null;
int code = -1;
try {
Response response = call.execute();
code = response.code();
headers = response.headers();
body = response.body().string();
throwException(call, code, headers, body, null);
} catch (Exception e) {
throwException(call, code, headers, body, e);
throw e;
}
return null;
}
use of com.hippo.ehviewer.client.exception.EhException in project EhViewer by seven332.
the class GalleryDetailParser method parse.
public static GalleryDetail parse(String body) throws EhException {
if (body.contains(OFFENSIVE_STRING)) {
throw new OffensiveException();
}
if (body.contains(PINING_STRING)) {
throw new PiningException();
}
// Error info
Matcher m = PATTERN_ERROR.matcher(body);
if (m.find()) {
throw new EhException(m.group(1));
}
GalleryDetail galleryDetail = new GalleryDetail();
Document document = Jsoup.parse(body);
parseDetail(galleryDetail, document, body);
galleryDetail.tags = parseTagGroups(document);
galleryDetail.comments = parseComments(document);
galleryDetail.previewPages = parsePreviewPages(document, body);
galleryDetail.previewSet = parsePreviewSet(document, body);
return galleryDetail;
}
Aggregations