Search in sources :

Example 21 with NetworkResponse

use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.

the class Theme method votePost.

public String votePost(int postId, boolean type) throws Exception {
    NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/zka.php?i=".concat(Integer.toString(postId)).concat("&v=").concat(type ? "1" : "-1"));
    String result = null;
    Matcher m = Pattern.compile("ok:\\s*?((?:\\+|\\-)?\\d+)").matcher(response.getBody());
    if (m.find()) {
        int code = Integer.parseInt(m.group(1));
        switch(code) {
            case 0:
                result = "Ошибка: Вы уже голосовали за это сообщение";
                break;
            case 1:
                result = "Репутация поста повышена";
                break;
            case -1:
                result = "Репутация поста понижена";
                break;
        }
    }
    if (result == null)
        result = "Ошибка изменения репутации поста";
    return result;
}
Also used : Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 22 with NetworkResponse

use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.

the class Theme method deletePost.

public Boolean deletePost(int postId) throws Exception {
    String url = "https://4pda.ru/forum/index.php?act=zmod&auth_key=".concat(Api.getWebClient().getAuthKey()).concat("&code=postchoice&tact=delete&selectedpids=").concat(Integer.toString(postId));
    NetworkResponse response = Api.getWebClient().request(new NetworkRequest.Builder().url(url).xhrHeader().build());
    return response.getBody().equals("ok");
}
Also used : NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 23 with NetworkResponse

use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.

the class EditPost method deleteFiles.

public List<AttachmentItem> deleteFiles(int postId, List<AttachmentItem> items) throws Exception {
    NetworkResponse response;
    Matcher matcher;
    for (AttachmentItem item : items) {
        response = Api.getWebClient().get("https://4pda.ru/forum/index.php?&act=attach&code=attach_upload_remove&attach_rel_id=".concat(postId == 0 ? "" : Integer.toString(postId)).concat("&attach_id=").concat(Integer.toString(item.getId())));
        matcher = statusInfo.matcher(response.getBody());
        if (matcher.find())
            fillAttachmentStatus(item, matcher);
    }
    return items;
}
Also used : Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Example 24 with NetworkResponse

use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.

the class EditPost method uploadFilesV2.

public List<AttachmentItem> uploadFilesV2(int postId, List<RequestFile> files, List<AttachmentItem> pending) throws Exception {
    NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=attach").xhrHeader().formHeader("index", "1").formHeader("relId", Integer.toString(postId)).formHeader("maxSize", "134217728").formHeader("allowExt", "").formHeader("forum-attach-files", "").formHeader("code", "check");
    NetworkResponse response;
    Matcher matcher = null;
    for (int i = 0; i < files.size(); i++) {
        RequestFile file = files.get(i);
        AttachmentItem item = pending.get(i);
        file.setRequestName("FILE_UPLOAD[]");
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
        byte[] targetArray = new byte[file.getFileStream().available()];
        file.getFileStream().read(targetArray);
        InputStream is1 = new ByteArrayInputStream(targetArray);
        file.getFileStream().close();
        file.setFileStream(is1);
        messageDigest.update(targetArray);
        byte[] hash = messageDigest.digest();
        String md5 = ByteArraytoHexString(hash);
        builder.formHeader("md5", md5).formHeader("size", "" + file.getFileStream().available()).formHeader("name", file.getFileName());
        response = Api.getWebClient().request(builder.build());
        if (response.getBody().equals("0")) {
            NetworkRequest.Builder uploadRequest = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=attach").xhrHeader().formHeader("index", "1").formHeader("relId", Integer.toString(postId)).formHeader("maxSize", "134217728").formHeader("allowExt", "").formHeader("forum-attach-files", "").formHeader("code", "upload").file(file);
            response = Api.getWebClient().request(uploadRequest.build(), item.getProgressListener());
        }
        if (matcher == null) {
            matcher = attachmentsPattern.matcher(response.getBody());
        } else {
            matcher = matcher.reset(response.getBody());
        }
        if (matcher.find()) {
            fillAttachmentV2(item, matcher);
        }
        item.setStatus(AttachmentItem.STATUS_UPLOADED);
    }
    return pending;
}
Also used : Matcher(java.util.regex.Matcher) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem) ByteArrayInputStream(java.io.ByteArrayInputStream) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) RequestFile(forpdateam.ru.forpda.api.RequestFile) MessageDigest(java.security.MessageDigest)

Example 25 with NetworkResponse

use of forpdateam.ru.forpda.api.NetworkResponse in project ForPDA by RadiationX.

the class EditPost method loadForm.

public EditPostForm loadForm(int postId) throws Exception {
    EditPostForm form = new EditPostForm();
    String url = "https://4pda.ru/forum/index.php?act=post&do=edit_post&p=".concat(Integer.toString(postId));
    // url = url.concat("&t=").concat(Integer.toString(topicId)).concat("&f=").concat(Integer.toString(forumId));
    NetworkResponse response = Api.getWebClient().get(url);
    if (response.getBody().equals("nopermission")) {
        form.setErrorCode(EditPostForm.ERROR_NO_PERMISSION);
        return form;
    }
    Matcher matcher = postPattern.matcher(response.getBody());
    if (matcher.find()) {
        form.setMessage(ApiUtils.fromHtml(ApiUtils.escapeNewLine(matcher.group(1))));
        form.setEditReason(matcher.group(2));
    }
    matcher = pollInfoPattern.matcher(response.getBody());
    if (matcher.find()) {
        EditPoll poll = createPoll(matcher);
        form.setPoll(poll);
        EditPost.printPoll(poll);
    }
    response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=attach&index=1&relId=" + postId + "&maxSize=134217728&allowExt=&code=init&unlinked=");
    matcher = attachmentsPattern.matcher(response.getBody());
    while (matcher.find()) {
        form.addAttachment(fillAttachmentV2(new AttachmentItem(), matcher));
    }
    return form;
}
Also used : EditPostForm(forpdateam.ru.forpda.api.theme.editpost.models.EditPostForm) Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) EditPoll(forpdateam.ru.forpda.api.theme.editpost.models.EditPoll) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Aggregations

NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)44 Matcher (java.util.regex.Matcher)27 NetworkRequest (forpdateam.ru.forpda.api.NetworkRequest)25 ArrayList (java.util.ArrayList)8 AttachmentItem (forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)6 Bundle (android.os.Bundle)3 RequestFile (forpdateam.ru.forpda.api.RequestFile)3 Context (android.content.Context)2 Uri (android.net.Uri)2 App (forpdateam.ru.forpda.App)2 R (forpdateam.ru.forpda.R)2 QmsMessage (forpdateam.ru.forpda.api.qms.models.QmsMessage)2 Client (forpdateam.ru.forpda.client.Client)2 Observable (io.reactivex.Observable)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Schedulers (io.reactivex.schedulers.Schedulers)2 Activity (android.app.Activity)1 DownloadManager (android.app.DownloadManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1