Search in sources :

Example 16 with NetworkResponse

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

the class Theme method reportPost.

public String reportPost(int topicId, int postId, String message) throws Exception {
    NetworkRequest request = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=report&send=1&t=" + Integer.toString(topicId) + "&p=" + Integer.toString(postId)).formHeader("message", URLEncoder.encode(message, "windows-1251"), true).build();
    NetworkResponse response = Api.getWebClient().request(request);
    Pattern p = Pattern.compile("<div class=\"errorwrap\">\n" + "\\s*<h4>Причина:</h4>\n" + "\\s*\n" + "\\s*<p>(.*)</p>", Pattern.MULTILINE);
    Matcher m = p.matcher(response.getBody());
    return m.find() ? "Ошибка отправки жалобы: ".concat(m.group(1)) : "Жалоба отправлена";
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 17 with NetworkResponse

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

the class EditPost method uploadFiles.

public List<AttachmentItem> uploadFiles(int postId, List<RequestFile> files) throws Exception {
    String url = "https://4pda.ru/forum/index.php?&act=attach&code=attach_upload_process&attach_rel_id=".concat(postId == 0 ? "" : Integer.toString(postId));
    List<AttachmentItem> items = new ArrayList<>();
    AttachmentItem item;
    NetworkResponse response;
    Matcher matcher;
    for (RequestFile file : files) {
        file.setRequestName("FILE_UPLOAD[]");
        item = new AttachmentItem();
        NetworkRequest.Builder builder = new NetworkRequest.Builder().url(url).file(file);
        response = Api.getWebClient().request(builder.build());
        matcher = loadedAttachments.matcher(response.getBody());
        if (matcher.find())
            item = fillAttachment(item, matcher);
        matcher = statusInfo.matcher(response.getBody());
        if (matcher.find())
            fillAttachmentStatus(item, matcher);
        items.add(item);
    }
    return items;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) RequestFile(forpdateam.ru.forpda.api.RequestFile) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Example 18 with NetworkResponse

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

the class EditPost method deleteFilesV2.

public List<AttachmentItem> deleteFilesV2(int postId, List<AttachmentItem> items) throws Exception {
    NetworkResponse response;
    for (AttachmentItem item : items) {
        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("code", "remove").formHeader("id", Integer.toString(item.getId()));
        response = Api.getWebClient().request(builder.build());
        // todo проверка на ошибки, я хз че еще может быть кроме 0
        if (response.getBody().equals("0")) {
            item.setStatus(AttachmentItem.STATUS_REMOVED);
            item.setError(false);
        }
    }
    return items;
}
Also used : NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Example 19 with NetworkResponse

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

the class Reputation method getReputation.

public RepData getReputation(RepData data) throws Exception {
    if (data == null)
        return null;
    NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=rep&view=history&mid=" + data.getId() + "&mode=" + data.getMode() + "&order=" + data.getSort() + "&st=" + data.getPagination().getSt());
    Matcher matcher = infoPattern.matcher(response.getBody());
    if (matcher.find()) {
        data.setId(Integer.parseInt(matcher.group(1)));
        data.setNick(ApiUtils.fromHtml(matcher.group(2)));
        if (matcher.group(3) != null) {
            data.setPositive(Integer.parseInt(matcher.group(3)));
        }
        if (matcher.group(4) != null) {
            data.setNegative(Integer.parseInt(matcher.group(4)));
        }
    }
    matcher = listPattern.matcher(response.getBody());
    String temp;
    data.getItems().clear();
    while (matcher.find()) {
        RepItem item = new RepItem();
        item.setUserId(Integer.parseInt(matcher.group(1)));
        item.setUserNick(ApiUtils.fromHtml(matcher.group(2)));
        temp = matcher.group(3);
        if (temp != null) {
            item.setSourceUrl(temp);
            item.setSourceTitle(ApiUtils.fromHtml(matcher.group(4)));
        }
        item.setTitle(ApiUtils.fromHtml(matcher.group(5)));
        item.setImage(matcher.group(6));
        item.setDate(matcher.group(7));
        data.addItem(item);
    }
    data.setPagination(Pagination.parseForum(data.getPagination(), response.getBody()));
    return data;
}
Also used : Matcher(java.util.regex.Matcher) RepItem(forpdateam.ru.forpda.api.reputation.models.RepItem) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 20 with NetworkResponse

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

the class Topics method getTopics.

public TopicsData getTopics(int id, int st) throws Exception {
    TopicsData data = new TopicsData();
    NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/index.php?showforum=".concat(Integer.toString(id)).concat("&st=").concat(Integer.toString(st)));
    Matcher matcher = titlePattern.matcher(response.getBody());
    if (matcher.find()) {
        data.setId(Integer.parseInt(matcher.group(1)));
        data.setTitle(ApiUtils.fromHtml(matcher.group(2)));
    } else {
        data.setId(id);
    }
    matcher = canNewTopicPattern.matcher(response.getBody());
    data.setCanCreateTopic(matcher.find());
    matcher = announcePattern.matcher(response.getBody());
    while (matcher.find()) {
        TopicItem item = new TopicItem();
        item.setAnnounce(true);
        item.setAnnounceUrl(matcher.group(1));
        item.setTitle(ApiUtils.fromHtml(matcher.group(2)));
        data.addAnnounceItem(item);
    }
    matcher = topicsPattern.matcher(response.getBody());
    while (matcher.find()) {
        TopicItem item = new TopicItem();
        item.setId(Integer.parseInt(matcher.group(1)));
        int p = 0;
        String tmp = matcher.group(2);
        item.setNew(tmp.contains("+"));
        item.setPoll(tmp.contains("^"));
        item.setClosed(tmp.contains("Х"));
        item.setPinned(matcher.group(3) != null);
        item.setTitle(ApiUtils.fromHtml(matcher.group(4)));
        tmp = matcher.group(5);
        if (tmp != null)
            item.setDesc(ApiUtils.fromHtml(tmp));
        item.setAuthorId(Integer.parseInt(matcher.group(6)));
        item.setAuthorNick(ApiUtils.fromHtml(matcher.group(7)));
        item.setLastUserId(Integer.parseInt(matcher.group(8)));
        item.setLastUserNick(ApiUtils.fromHtml(matcher.group(9)));
        item.setDate(matcher.group(10));
        tmp = matcher.group(11);
        if (tmp != null) {
            item.setCuratorId(Integer.parseInt(tmp));
            item.setCuratorNick(ApiUtils.fromHtml(matcher.group(12)));
        }
        if (item.isPinned()) {
            data.addPinnedItem(item);
        } else {
            data.addTopicItem(item);
        }
    }
    matcher = forumPattern.matcher(response.getBody());
    while (matcher.find()) {
        TopicItem topicItem = new TopicItem();
        topicItem.setId(Integer.parseInt(matcher.group(1)));
        topicItem.setTitle(ApiUtils.fromHtml(matcher.group(2)));
        topicItem.setForum(true);
        data.addForumItem(topicItem);
    }
    data.setPagination(Pagination.parseForum(response.getBody()));
    return data;
}
Also used : TopicItem(forpdateam.ru.forpda.api.topcis.models.TopicItem) TopicsData(forpdateam.ru.forpda.api.topcis.models.TopicsData) Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

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