Exemplo n.º 1
0
  /**
   * 関連キーワード設定/解除
   *
   * @param isRelate true:設定/false:解除
   * @param keyword1 対象キーワード1
   * @param keyword2 対象キーワード2
   * @return 関連キーワードを設定/解除後のキーワード1のキーワード情報
   * @throws HatenaHaikuException
   * @since v0.0.1
   */
  private Keyword _modifyRelateKeyword(boolean isRelate, String keyword1, String keyword2)
      throws HatenaHaikuException {
    if (StringUtil.isSame(keyword1, keyword2)) {
      throw new HatenaHaikuException("対象キーワードに同じキーワードは指定できません。");
    }
    try {
      QueryParameter param = new QueryParameter();
      param.setWord1(keyword1);
      param.setWord2(keyword2);
      String resultXml =
          HttpUtil.doGet(
              loginUser,
              (isRelate ? URL_RELATE_KEYWORD_XML : URL_UNRELATE_KEYWORD_XML),
              param,
              isNeedHttpLog());
      return toKeyword(XmlUtil.getRootElement(resultXml));

    } catch (ParserConfigurationException e) {
      throw new HatenaHaikuException("ParserConfigurationException発生。", e);

    } catch (SAXException e) {
      throw new HatenaHaikuException("SAXException発生。", e);

    } catch (IOException e) {
      throw new HatenaHaikuException("IOException発生。", e);
    }
  }
Exemplo n.º 2
0
  /**
   * 認証したユーザをフォローしているユーザのリストを取得します。<br>
   * フォロワーはページ指定できず、一気に全員分取得されるようです。<br>
   * <i>http://h.hatena.ne.jp/api/statuses/followers.xml</i>
   *
   * @see <a href="http://h.hatena.ne.jp/api#statuses-followers">statuses/followers</a>
   * @param op 集合操作
   * @return 認証したユーザをフォローしているユーザのリスト
   * @throws HatenaHaikuException
   * @since v1.1.0
   */
  public <T> T getFollowersList(ReduceOp<User, T> op) throws HatenaHaikuException {
    try {
      String resultXml = HttpUtil.doGet(loginUser, URL_FOLLOWERS_LIST_XML, null, isNeedHttpLog());
      return toUserList(op, XmlUtil.getRootElement(resultXml));

    } catch (ParserConfigurationException e) {
      throw new HatenaHaikuException("ParserConfigurationException発生。", e);

    } catch (SAXException e) {
      throw new HatenaHaikuException("SAXException発生。", e);

    } catch (IOException e) {
      throw new HatenaHaikuException("IOException発生。", e);
    }
  }
Exemplo n.º 3
0
  /**
   * はてなハイクに投稿します。<br>
   * <i>http://h.hatena.ne.jp/api/statuses/update.xml</i>
   *
   * @see <a href="http://h.hatena.ne.jp/api#statuses-update">statuses/update</a>
   * @param params 更新パラメータ
   * @return 投稿結果のステータス情報
   * @throws HatenaHaikuException
   * @since v0.0.1
   */
  private Status _updateStatus(UpdateParameter param) throws HatenaHaikuException {
    try {
      String resultXml = HttpUtil.doPost(loginUser, URL_UPDATE_STATUS_XML, param, isNeedHttpLog());
      return toStatus(XmlUtil.getRootElement(resultXml));

    } catch (ParserConfigurationException e) {
      throw new HatenaHaikuException("ParserConfigurationException発生。", e);

    } catch (SAXException e) {
      throw new HatenaHaikuException("SAXException発生。", e);

    } catch (IOException e) {
      throw new HatenaHaikuException("IOException発生。", e);
    }
  }
Exemplo n.º 4
0
  /**
   * 指定したステータスIDのエントリを削除します。<br>
   * <i>http://h.hatena.ne.jp/api/statuses/destroy/<font color="red">ステータスID</font>.xml</i>
   *
   * @see <a href="http://h.hatena.ne.jp/api#statuses-destroy">statuses/destroy</a>
   * @param statusId ステータスID
   * @return 削除したステータス情報
   * @throws HatenaHaikuException
   * @since v0.0.1
   */
  public Status deleteEntry(String statusId) throws HatenaHaikuException {
    try {
      String resultXml =
          HttpUtil.doGet(loginUser, URL_DELETE_STATUS + statusId + EXT_XML, null, isNeedHttpLog());
      return toStatus(XmlUtil.getRootElement(resultXml));

    } catch (ParserConfigurationException e) {
      throw new HatenaHaikuException("ParserConfigurationException発生。", e);

    } catch (SAXException e) {
      throw new HatenaHaikuException("SAXException発生。", e);

    } catch (IOException e) {
      throw new HatenaHaikuException("IOException発生。", e);
    }
  }
Exemplo n.º 5
0
  /**
   * 認証したユーザがフォローしているユーザのリストを100件取得します。(指定ページ)<br>
   * <i>http://h.hatena.ne.jp/api/statuses/friends.xml&page=<font color="red">ページ</font></i>
   *
   * @see <a href="http://h.hatena.ne.jp/api#statuses-friends">statuses/friends</a>
   * @param op 集合操作
   * @param page ページ
   * @return 認証したユーザがフォローしているユーザのリスト(指定ページ)
   * @throws HatenaHaikuException
   * @since v1.1.0
   */
  public <T> T getFollowingList(ReduceOp<User, T> op, int page) throws HatenaHaikuException {
    try {
      QueryParameter param = new QueryParameter();
      param.setPage(page);
      String resultXml = HttpUtil.doGet(loginUser, URL_FOLLOWING_LIST_XML, param, isNeedHttpLog());
      return toUserList(op, XmlUtil.getRootElement(resultXml));

    } catch (ParserConfigurationException e) {
      throw new HatenaHaikuException("ParserConfigurationException発生。", e);

    } catch (SAXException e) {
      throw new HatenaHaikuException("SAXException発生。", e);

    } catch (IOException e) {
      throw new HatenaHaikuException("IOException発生。", e);
    }
  }
Exemplo n.º 6
0
  /**
   * ユーザのフォローしたりやめたりします。<br>
   * <i>http://h.hatena.ne.jp/api/friendships/destroy/<font color="red">ユーザID</font>.xml</i>
   *
   * @see <a href="http://h.hatena.ne.jp/api#friendships-destroy">friendships/destroy</a>
   * @param isFollow true:フォローする/false:フォローをやめる
   * @param userId ユーザID
   * @return フォローしたりやめたりしたユーザ情報
   * @throws HatenaHaikuException
   * @since v0.0.1
   */
  private User _modifyFollowUser(boolean isFollow, String userId) throws HatenaHaikuException {
    try {
      String resultXml =
          HttpUtil.doGet(
              loginUser,
              (isFollow ? URL_FOLLOW_USER : URL_UNFOLLOW_USER) + userId + EXT_XML,
              null,
              isNeedHttpLog());
      return toUser(XmlUtil.getRootElement(resultXml));

    } catch (ParserConfigurationException e) {
      throw new HatenaHaikuException("ParserConfigurationException発生。", e);

    } catch (SAXException e) {
      throw new HatenaHaikuException("SAXException発生。", e);

    } catch (IOException e) {
      throw new HatenaHaikuException("IOException発生。", e);
    }
  }
Exemplo n.º 7
0
  /**
   * 指定したエントリのスターを一つ増やしたり減らしたりします。<br>
   * <i>http://h.hatena.ne.jp/api/favorites/destroy/<font color="red">ステータスID</font>.xml</i>
   *
   * @see <a href="http://h.hatena.ne.jp/api#favorites-destroy">favorites/destroy</a>
   * @param isAdd true:一つ増やす/false:一つ減らす
   * @param statusId ステータスID
   * @return スターを一つ増やしたり減らしたりした結果のステータス情報
   * @throws HatenaHaikuException
   * @since v0.0.1
   */
  private Status _modifyStar(boolean isAdd, String statusId) throws HatenaHaikuException {
    try {
      String resultXml =
          HttpUtil.doGet(
              loginUser,
              (isAdd ? URL_ADD_STAR : URL_DELETE_STAR) + statusId + EXT_XML,
              null,
              isNeedHttpLog());
      return toStatus(XmlUtil.getRootElement(resultXml));

    } catch (ParserConfigurationException e) {
      throw new HatenaHaikuException("ParserConfigurationException発生。", e);

    } catch (SAXException e) {
      throw new HatenaHaikuException("SAXException発生。", e);

    } catch (IOException e) {
      throw new HatenaHaikuException("IOException発生。", e);
    }
  }
Exemplo n.º 8
0
  /**
   * 認証したユーザのフレンドタイムラインを取得します。<br>
   * <i>http://h.hatena.ne.jp/api/statuses/friends_timeline.xml</i>
   *
   * @see <a
   *     href="http://h.hatena.ne.jp/api#statuses-friends_timeline">statuses/friends_timeline</a>
   * @param op 集合操作
   * @param page 取得するページです。最大数は100です。
   * @param count 取得数を指定します。最大数は 200 です。
   * @param since その日時よりも新しい投稿のみに絞り込むための日時を指定します。
   * @return 認証したユーザのフレンドタイムライン
   * @throws HatenaHaikuException
   * @since v1.1.0
   */
  public <T> T getFriendsTimeline(ReduceOp<Status, T> op, int page, int count, Date since)
      throws HatenaHaikuException {
    try {
      QueryParameter param = new QueryParameter();
      param.setPage(page);
      param.setCount(count);
      param.setSince(since);
      String resultXml =
          HttpUtil.doGet(loginUser, URL_FRIENDS_TIMELINE_XML, param, isNeedHttpLog());
      return toStatusList(op, XmlUtil.getRootElement(resultXml));

    } catch (ParserConfigurationException e) {
      throw new HatenaHaikuException("ParserConfigurationException発生。", e);

    } catch (SAXException e) {
      throw new HatenaHaikuException("SAXException発生。", e);

    } catch (IOException e) {
      throw new HatenaHaikuException("IOException発生。", e);
    }
  }
Exemplo n.º 9
0
  /**
   * キーワードのフォローしたり、やめたりします。<br>
   * <i>http://h.hatena.ne.jp/api/keywords/destroy/<font color="red">キーワード</font>.xml</i>
   *
   * @see <a href="http://h.hatena.ne.jp/api#keywords-destroy">keywords/destroy</a>
   * @param isFollow true:フォローする/false:フォローをやめる
   * @param keyword キーワード
   * @return フォローした/やめたキーワード情報
   * @throws HatenaHaikuException
   * @since v0.0.1
   */
  private Keyword _modifyFollowKeyword(boolean isFollow, String keyword)
      throws HatenaHaikuException {
    try {
      String resultXml =
          HttpUtil.doGet(
              loginUser,
              (isFollow ? URL_FOLLOW_KEYWORD : URL_UNFOLLOW_KEYWORD)
                  + StringUtil.encode(keyword)
                  + EXT_XML,
              null,
              isNeedHttpLog());
      return toKeyword(XmlUtil.getRootElement(resultXml));

    } catch (ParserConfigurationException e) {
      throw new HatenaHaikuException("ParserConfigurationException発生。", e);

    } catch (SAXException e) {
      throw new HatenaHaikuException("SAXException発生。", e);

    } catch (IOException e) {
      throw new HatenaHaikuException("IOException発生。", e);
    }
  }
Exemplo n.º 10
0
  /**
   * 認証したユーザのユーザタイムラインを取得します。<br>
   * <i>http://h.hatena.ne.jp/api/statuses/user_timeline.xml</i>
   *
   * @see <a href="http://h.hatena.ne.jp/api#statuses-user_timeline">statuses/user_timeline</a>
   * @param op 集合操作
   * @param page 取得するページです。最大数は100です。
   * @param count 取得数を指定します。最大数は 200 です。
   * @param since その日時よりも新しい投稿のみに絞り込むための日時を指定します。
   * @param isHot 人気順取得用かどうか
   * @return 認証したユーザのユーザタイムライン
   * @throws HatenaHaikuException
   * @since v1.0.0
   */
  private <T> T _getUserTimeline(
      ReduceOp<Status, T> op, int page, int count, Date since, boolean isHot)
      throws HatenaHaikuException {
    try {
      QueryParameter param = new QueryParameter();
      if (isHot) {
        param.setSort(QueryParameter.HOT); // 人気順
      }
      param.setPage(page);
      param.setCount(count);
      param.setSince(since);
      String resultXml = HttpUtil.doGet(loginUser, URL_USER_TIMELINE_XML, param, isNeedHttpLog());
      return toStatusList(op, XmlUtil.getRootElement(resultXml));

    } catch (ParserConfigurationException e) {
      throw new HatenaHaikuException("ParserConfigurationException発生。", e);

    } catch (SAXException e) {
      throw new HatenaHaikuException("SAXException発生。", e);

    } catch (IOException e) {
      throw new HatenaHaikuException("IOException発生。", e);
    }
  }