Search in sources :

Example 31 with Headers

use of com.amazonaws.services.s3.Headers in project EhViewer by seven332.

the class EhEngine method commentGallery.

public static GalleryComment[] commentGallery(@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url, String comment) throws Exception {
    FormBody.Builder builder = new FormBody.Builder().add("commenttext_new", comment);
    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();
        Document document = Jsoup.parse(body);
        Elements elements = document.select("#chd + p");
        if (elements.size() > 0) {
            throw new EhException(elements.get(0).text());
        }
        return GalleryDetailParser.parseComments(document);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
}
Also used : Call(okhttp3.Call) Headers(okhttp3.Headers) FormBody(okhttp3.FormBody) Request(okhttp3.Request) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) 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) Response(okhttp3.Response) EhException(com.hippo.ehviewer.client.exception.EhException)

Example 32 with Headers

use of com.amazonaws.services.s3.Headers in project EhViewer by seven332.

the class EhEngine method imageSearch.

/**
 * @param image Must be jpeg
 */
public static GalleryListParser.Result imageSearch(@Nullable EhClient.Task task, OkHttpClient okHttpClient, File image, boolean uss, boolean osc, boolean se) throws Exception {
    MultipartBody.Builder builder = new MultipartBody.Builder();
    builder.setType(MultipartBody.FORM);
    builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"sfile\"; filename=\"a.jpg\""), RequestBody.create(MEDIA_TYPE_JPEG, image));
    if (uss) {
        builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"fs_similar\""), RequestBody.create(null, "on"));
    }
    if (osc) {
        builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"fs_covers\""), RequestBody.create(null, "on"));
    }
    if (se) {
        builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"fs_exp\""), RequestBody.create(null, "on"));
    }
    builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"f_sfile\""), RequestBody.create(null, "File Search"));
    String url = EhUrl.getImageSearchUrl();
    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;
    GalleryListParser.Result result;
    int code = -1;
    try {
        Response response = call.execute();
        Log.d(TAG, "" + response.request().url().toString());
        code = response.code();
        headers = response.headers();
        body = response.body().string();
        result = GalleryListParser.parse(body);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
    // Filter title and uploader
    List<GalleryInfo> list = result.galleryInfoList;
    for (int i = 0, n = list.size(); i < n; i++) {
        GalleryInfo info = list.get(i);
        if (!sEhFilter.filterTitle(info) || !sEhFilter.filterUploader(info)) {
            list.remove(i);
            i--;
            n--;
        }
    }
    if (list.size() > 0 && (Settings.getShowJpnTitle() || sEhFilter.needCallApi())) {
        // Fill by api
        fillGalleryListByApi(task, okHttpClient, list);
        // Filter tag
        for (int i = 0, n = list.size(); i < n; i++) {
            GalleryInfo info = list.get(i);
            if (!sEhFilter.filterTag(info) || !sEhFilter.filterTagNamespace(info)) {
                list.remove(i);
                i--;
                n--;
            }
        }
    }
    for (GalleryInfo info : list) {
        info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
    }
    return result;
}
Also used : Call(okhttp3.Call) Headers(okhttp3.Headers) Request(okhttp3.Request) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) 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) Response(okhttp3.Response) MultipartBody(okhttp3.MultipartBody) GalleryListParser(com.hippo.ehviewer.client.parser.GalleryListParser)

Example 33 with Headers

use of com.amazonaws.services.s3.Headers in project EhViewer by seven332.

the class EhEngine method getGalleryDetail.

public static GalleryDetail getGalleryDetail(@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url) throws Exception {
    Log.d(TAG, url);
    Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).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();
        return GalleryDetailParser.parse(body);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Headers(okhttp3.Headers) 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 34 with Headers

use of com.amazonaws.services.s3.Headers in project EhViewer by seven332.

the class EhEngine method getFavorites.

public static FavoritesParser.Result getFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url, boolean callApi) throws Exception {
    Log.d(TAG, url);
    Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
    Call call = okHttpClient.newCall(request);
    // Put call
    if (null != task) {
        task.setCall(call);
    }
    String body = null;
    Headers headers = null;
    FavoritesParser.Result result;
    int code = -1;
    try {
        Response response = call.execute();
        code = response.code();
        headers = response.headers();
        body = response.body().string();
        result = FavoritesParser.parse(body);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
    if (callApi && result.galleryInfoList.size() > 0) {
        fillGalleryListByApi(task, okHttpClient, result.galleryInfoList);
    }
    for (GalleryInfo info : result.galleryInfoList) {
        info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
    }
    return result;
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Headers(okhttp3.Headers) FavoritesParser(com.hippo.ehviewer.client.parser.FavoritesParser) Request(okhttp3.Request) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) 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 35 with Headers

use of com.amazonaws.services.s3.Headers in project EhViewer by seven332.

the class EhEngine method voteComment.

public static VoteCommentParser.Result voteComment(@Nullable EhClient.Task task, OkHttpClient okHttpClient, long apiUid, String apiKey, long gid, String token, long commentId, int commentVote) throws Exception {
    final JSONObject json = new JSONObject();
    json.put("method", "votecomment");
    json.put("apiuid", apiUid);
    json.put("apikey", apiKey);
    json.put("gid", gid);
    json.put("token", token);
    json.put("comment_id", commentId);
    json.put("comment_vote", commentVote);
    final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString());
    String url = EhUrl.getApiUrl();
    Log.d(TAG, url);
    Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).post(requestBody).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();
        return VoteCommentParser.parse(body, commentVote);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) JSONObject(org.json.JSONObject) Headers(okhttp3.Headers) 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) RequestBody(okhttp3.RequestBody)

Aggregations

Headers (okhttp3.Headers)128 Request (okhttp3.Request)61 Response (okhttp3.Response)54 Test (org.junit.Test)40 IOException (java.io.IOException)32 Call (okhttp3.Call)30 RequestBody (okhttp3.RequestBody)25 CancelledException (com.hippo.ehviewer.client.exception.CancelledException)20 EhException (com.hippo.ehviewer.client.exception.EhException)20 NoHAtHClientException (com.hippo.ehviewer.client.exception.NoHAtHClientException)20 ParseException (com.hippo.ehviewer.client.exception.ParseException)20 StatusCodeException (com.hippo.network.StatusCodeException)20 ResponseBody (okhttp3.ResponseBody)18 HttpHeaders (okhttp3.internal.http.HttpHeaders)18 MediaType (okhttp3.MediaType)15 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)14 HeaderResponseBoolHeaders (fixtures.header.models.HeaderResponseBoolHeaders)14 HeaderResponseByteHeaders (fixtures.header.models.HeaderResponseByteHeaders)14 HeaderResponseDateHeaders (fixtures.header.models.HeaderResponseDateHeaders)14 HeaderResponseDatetimeHeaders (fixtures.header.models.HeaderResponseDatetimeHeaders)14