Search in sources :

Example 6 with EhException

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;
}
Also used : EhException(com.hippo.ehviewer.client.exception.EhException) Response(okhttp3.Response) Call(okhttp3.Call) Headers(okhttp3.Headers) FormBody(okhttp3.FormBody) Request(okhttp3.Request) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException) CancelledException(com.hippo.ehviewer.client.exception.CancelledException) NoHAtHClientException(com.hippo.ehviewer.client.exception.NoHAtHClientException) StatusCodeException(com.hippo.network.StatusCodeException)

Example 7 with EhException

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;
}
Also used : EhException(com.hippo.ehviewer.client.exception.EhException) Matcher(java.util.regex.Matcher) PiningException(com.hippo.ehviewer.client.exception.PiningException) GalleryDetail(com.hippo.ehviewer.client.data.GalleryDetail) Document(org.jsoup.nodes.Document) OffensiveException(com.hippo.ehviewer.client.exception.OffensiveException)

Aggregations

EhException (com.hippo.ehviewer.client.exception.EhException)7 ParseException (com.hippo.ehviewer.client.exception.ParseException)5 CancelledException (com.hippo.ehviewer.client.exception.CancelledException)4 NoHAtHClientException (com.hippo.ehviewer.client.exception.NoHAtHClientException)4 StatusCodeException (com.hippo.network.StatusCodeException)4 Call (okhttp3.Call)4 FormBody (okhttp3.FormBody)4 Headers (okhttp3.Headers)4 Request (okhttp3.Request)4 Response (okhttp3.Response)4 Document (org.jsoup.nodes.Document)3 Matcher (java.util.regex.Matcher)2 Elements (org.jsoup.select.Elements)2 Point (android.graphics.Point)1 Bundle (android.os.Bundle)1 GalleryDetail (com.hippo.ehviewer.client.data.GalleryDetail)1 GalleryInfo (com.hippo.ehviewer.client.data.GalleryInfo)1 OffensiveException (com.hippo.ehviewer.client.exception.OffensiveException)1 PiningException (com.hippo.ehviewer.client.exception.PiningException)1 FavoritesParser (com.hippo.ehviewer.client.parser.FavoritesParser)1