Search in sources :

Example 1 with NetworkResponse

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

the class Mentions method getMentions.

public MentionsData getMentions(int st) throws Exception {
    MentionsData data = new MentionsData();
    NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=mentions&st=".concat(Integer.toString(st)));
    Matcher matcher = mentionsPattern.matcher(response.getBody());
    while (matcher.find()) {
        MentionItem item = new MentionItem();
        item.setState(matcher.group(1).equals("read") ? MentionItem.STATE_READ : MentionItem.STATE_UNREAD);
        item.setType(matcher.group(2).equalsIgnoreCase("Форум") ? MentionItem.TYPE_TOPIC : MentionItem.TYPE_NEWS);
        item.setLink(matcher.group(3));
        item.setTitle(ApiUtils.fromHtml(matcher.group(4)));
        item.setDesc(ApiUtils.fromHtml(matcher.group(5)));
        item.setDate(matcher.group(6));
        item.setNick(ApiUtils.fromHtml(matcher.group(7)));
        data.addItem(item);
    }
    data.setPagination(Pagination.parseForum(response.getBody()));
    return data;
}
Also used : MentionsData(forpdateam.ru.forpda.api.mentions.models.MentionsData) MentionItem(forpdateam.ru.forpda.api.mentions.models.MentionItem) Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Example 2 with NetworkResponse

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

the class NewsApi method replyComment.

public Comment replyComment(DetailsPage article, int commentId, String comment) throws Exception {
    try {
        comment = URLEncoder.encode(comment, "Windows-1251");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/wp-comments-post.php").formHeader("comment_post_ID", Integer.toString(article.getId())).formHeader("comment_reply_ID", Integer.toString(commentId)).formHeader("comment_reply_dp", commentId == 0 ? "0" : "1").formHeader("comment", comment, true);
    NetworkResponse response = Api.getWebClient().request(builder.build());
    DetailsPage newArticle = parseArticle(response.getBody());
    return updateComments(article, newArticle);
}
Also used : DetailsPage(forpdateam.ru.forpda.api.news.models.DetailsPage) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with NetworkResponse

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

the class Qms method sendMessage.

public ArrayList<QmsMessage> sendMessage(int userId, int themeId, String text) throws Exception {
    ArrayList<QmsMessage> messages = new ArrayList<>();
    NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php").formHeader("act", "qms-xhr").formHeader("action", "send-message").formHeader("message", text).formHeader("mid", Integer.toString(userId)).formHeader("t", Integer.toString(themeId));
    NetworkResponse response = Api.getWebClient().request(builder.build());
    Matcher matcher = chatPattern.matcher(response.getBody());
    QmsMessage item = new QmsMessage();
    if (matcher.find()) {
        if (matcher.group(1) == null && matcher.group(7) != null) {
            item.setIsDate(true);
            item.setDate(matcher.group(7).trim());
        } else {
            item.setMyMessage(!matcher.group(1).isEmpty());
            item.setId(Integer.parseInt(matcher.group(2)));
            if (item.isMyMessage()) {
                item.setReadStatus(!matcher.group(3).equals("1"));
            } else {
                item.setReadStatus(true);
            }
            item.setTime(matcher.group(4));
            item.setAvatar(matcher.group(5));
            item.setContent(matcher.group(6).trim());
        }
        messages.add(item);
    } else {
        matcher = Pattern.compile("class=\"list-group-item[^\"]*?error\"[\\s\\S]*?<\\/a>([\\s\\S]*?)<\\/div>").matcher(response.getBody());
        if (matcher.find()) {
            throw new Exception(matcher.group(1).trim());
        }
    }
    return messages;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) QmsMessage(forpdateam.ru.forpda.api.qms.models.QmsMessage)

Example 4 with NetworkResponse

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

the class Qms method uploadFiles.

public List<AttachmentItem> uploadFiles(List<RequestFile> files, List<AttachmentItem> pending) throws Exception {
    String baseUrl = "https://ru.imgbb.com/";
    String uploadUrl = "https://ru.imgbb.com/json";
    String authToken = "null";
    NetworkResponse baseResponse = Api.getWebClient().get(baseUrl);
    Matcher baseMatcher = imgBbPattern.matcher(baseResponse.getBody());
    if (baseMatcher.find()) {
        uploadUrl = baseMatcher.group(1);
        authToken = baseMatcher.group(2);
    }
    HashMap<String, String> headers = new HashMap<>();
    headers.put("type", "file");
    headers.put("action", "upload");
    headers.put("privacy", "undefined");
    headers.put("timestamp", Long.toString(System.currentTimeMillis()));
    headers.put("auth_token", authToken);
    headers.put("nsfw", "0");
    // Matcher matcher = null;
    for (int i = 0; i < files.size(); i++) {
        RequestFile file = files.get(i);
        AttachmentItem item = pending.get(i);
        file.setRequestName("source");
        NetworkRequest.Builder builder = new NetworkRequest.Builder().url(uploadUrl).formHeaders(headers).file(file);
        NetworkResponse response = Api.getWebClient().request(builder.build(), item.getItemProgressListener());
        JSONObject responseJson = new JSONObject(response.getBody());
        forpdateam.ru.forpda.common.Utils.longLog(responseJson.toString(4));
        if (responseJson.getInt("status_code") == 200) {
            JSONObject imageJson = responseJson.getJSONObject("image");
            item.setName(imageJson.getString("filename"));
            item.setId(0);
            item.setExtension(imageJson.getString("extension"));
            item.setWeight(imageJson.getString("size_formatted"));
            item.setTypeFile(AttachmentItem.TYPE_IMAGE);
            item.setLoadState(AttachmentItem.STATE_LOADED);
            item.setImageUrl(imageJson.getJSONObject("medium").getString("url"));
            item.setUrl(imageJson.getJSONObject("image").getString("url"));
        }
    }
    return pending;
}
Also used : JSONObject(org.json.JSONObject) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) 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 5 with NetworkResponse

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

the class Qms method getMessagesFromWs.

public ArrayList<QmsMessage> getMessagesFromWs(int themeId, int messageId, int afterMessageId) throws Exception {
    NetworkRequest.Builder messInfoBuilder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=qms-xhr&").formHeader("action", "message-info").formHeader("t", Integer.toString(themeId)).formHeader("msg-id", Integer.toString(messageId));
    NetworkResponse messInfoResponse = Api.getWebClient().request(messInfoBuilder.build());
    Matcher matcher = messageInfoPattern.matcher(messInfoResponse.getBody());
    int userId = 0;
    if (matcher.find()) {
        userId = Integer.parseInt(matcher.group(1));
    }
    return getMessagesAfter(userId, themeId, afterMessageId);
}
Also used : Matcher(java.util.regex.Matcher) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) 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