/** * Подписка на ответы в топике * * @param forumId - id форума (можно получить из TopicApi.getForumId) * @param authKey - ключ, возвращаемый при логине в параметре K_KEY * @param topicId - id топика * @param emailtype - способ уведомления (смотри константы TopicApi.SUBSCRIBE_EMAIL_TYPE_) */ public static ResultInfo subscribe( IHttpClient client, CharSequence forumId, CharSequence authKey, CharSequence topicId, String emailtype) throws IOException { Map<String, String> additionalHeaders = new HashMap<String, String>(); additionalHeaders.put("act", "usercp"); additionalHeaders.put("CODE", "end_subs"); additionalHeaders.put("method", "topic"); additionalHeaders.put("auth_key", authKey.toString()); additionalHeaders.put("tid", topicId.toString()); additionalHeaders.put("fid", forumId.toString()); additionalHeaders.put("st", "0"); additionalHeaders.put("emailtype", emailtype); String res = client.performPost("http://4pda.ru/forum/index.php", additionalHeaders); Pattern p = Pattern.compile( "<div class=\"errorwrap\">\n" + "\\s*<h4>Причина:</h4>\n" + "\\s*\n" + "\\s*<p>(.*)</p>", Pattern.MULTILINE); Matcher m = p.matcher(res); if (m.find()) { return new ResultInfo(false, "Ошибка подписки: " + m.group(1)); } return new ResultInfo(true, ""); }
/** * Отписка от темы * * @throws IOException */ public static ResultInfo unSubscribe(IHttpClient httpClient, CharSequence topicId) throws IOException { CharSequence subscribesId = getTopicSubscribedId(httpClient, topicId); if (subscribesId != null) { Map<String, String> additionalHeaders = new HashMap<String, String>(); additionalHeaders.put("act", "UserCP"); additionalHeaders.put("CODE", "27"); additionalHeaders.put("id-" + subscribesId, "yes"); additionalHeaders.put("trackchoice", "unsubscribe"); httpClient.performPost("http://4pda.ru/forum/index.php", additionalHeaders); return new ResultInfo(true, null); } return new ResultInfo(false, "Тема в подписках не найдена"); }