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;
}
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);
}
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;
}
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;
}
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);
}
Aggregations