Search in sources :

Example 36 with Headers

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

the class EhEngine method signIn.

public static String signIn(@Nullable EhClient.Task task, OkHttpClient okHttpClient, String username, String password, String recaptchaChallenge, String recaptchaResponse) throws Exception {
    FormBody.Builder builder = new FormBody.Builder().add("UserName", username).add("PassWord", password).add("submit", "Log me in").add("CookieDate", "1").add("temporary_https", "off");
    if (!TextUtils.isEmpty(recaptchaChallenge) && !TextUtils.isEmpty(recaptchaResponse)) {
        builder.add("recaptcha_challenge_field", recaptchaChallenge);
        builder.add("recaptcha_response_field", recaptchaResponse);
    }
    String url = EhUrl.API_SIGN_IN;
    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();
        return SignInParser.parse(body);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
}
Also used : 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 37 with Headers

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

the class EhEngine method getProfileInternal.

private static ProfileParser.Result getProfileInternal(@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 ProfileParser.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 38 with Headers

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

the class EhEngine method modifyFavorites.

public static FavoritesParser.Result modifyFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url, long[] gidArray, int dstCat, boolean callApi) throws Exception {
    String catStr;
    if (dstCat == -1) {
        catStr = "delete";
    } else if (dstCat >= 0 && dstCat <= 9) {
        catStr = "fav" + dstCat;
    } else {
        throw new EhException("Invalid dstCat: " + dstCat);
    }
    FormBody.Builder builder = new FormBody.Builder();
    builder.add("ddact", catStr);
    for (long gid : gidArray) {
        builder.add("modifygids[]", Long.toString(gid));
    }
    builder.add("apply", "Apply");
    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;
    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 : Call(okhttp3.Call) Headers(okhttp3.Headers) FormBody(okhttp3.FormBody) 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) EhException(com.hippo.ehviewer.client.exception.EhException) Response(okhttp3.Response) FavoritesParser(com.hippo.ehviewer.client.parser.FavoritesParser)

Example 39 with Headers

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

the class EhEngine method getArchiveList.

public static Pair<String, Pair<String, String>[]> getArchiveList(@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;
    Pair<String, Pair<String, String>[]> result;
    int code = -1;
    try {
        Response response = call.execute();
        code = response.code();
        headers = response.headers();
        body = response.body().string();
        result = ArchiveParser.parse(body);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
    return result;
}
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 40 with Headers

use of com.amazonaws.services.s3.Headers in project instructure-android by instructure.

the class FileFolderAPI method uploadFileSynchronousNoRedirect.

@WorkerThread
public static /* Used to manually handle the last redirect */
RemoteFile uploadFileSynchronousNoRedirect(@NonNull RestBuilder adapter, String uploadUrl, Map<String, RequestBody> uploadParams, String mimeType, File file) throws IOException {
    RestParams params = new RestParams.Builder().withShouldIgnoreToken(true).withDomain(uploadUrl).withPerPageQueryParam(false).build();
    RequestBody fileBody = RequestBody.create(MediaType.parse(mimeType), file);
    Headers headers = adapter.buildNoRedirects(FilesFoldersInterface.class, params).uploadFile(uploadParams, fileBody).execute().headers();
    String redirect = headers.get("Location");
    String newFileUrl = redirect.split("/create_success")[0];
    // POST to the redirect... according to the docs we need to do this to finalize the file upload process
    RemoteFile newFile = adapter.build(FilesFoldersInterface.class, params).postNewlyCreatedFile(redirect).execute().body();
    // We weren't receiving a url in the response from the POST to the redirect - here we grab the full file info as a work around
    FileFolder fileFolder = FileFolderManager.getFileFolderFromURLSynchronous(newFileUrl);
    newFile.setUrl(fileFolder.getUrl());
    newFile.setThumbnailUrl(fileFolder.getThumbnailUrl());
    return newFile;
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) Headers(okhttp3.Headers) FileFolder(com.instructure.canvasapi2.models.FileFolder) UpdateFileFolder(com.instructure.canvasapi2.models.UpdateFileFolder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RemoteFile(com.instructure.canvasapi2.models.RemoteFile) RequestBody(okhttp3.RequestBody) WorkerThread(android.support.annotation.WorkerThread)

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