// Constructor
 public Twitter() {
   config = Configuration.getInstance();
   twitterConfig = config.getTwitterConfig("twitter"); // HACK
   token = twitterConfig.getToken();
   twitter.setOAuthConsumer(
       twitterConfig.getToken().getToken(), twitterConfig.getToken().getTokenSecret());
   earlier = new Date(System.currentTimeMillis() - config.getDelta());
 }
  @Override
  public boolean execute() {
    Twitter main = new Twitter();
    logger.info(
        "WARNING!!!!!!  Once authorized, this will delete EVERY tweet you ever posted, that is older then 2 weeks.\n"
            + "Do not continue unless you are absolutely certain you want to do this.");
    logger.info(
        "\n\nNote: Twitter rate limits us to 350 actions per hour.  If your twitter stream is very active, this will "
            + "most likely break and you'll need to re-run this application a few times over to do a proper cleanup.");
    Scanner scanner = new Scanner(System.in);
    logger.info("Do you wish to continue? (y/n)?");
    String ans = scanner.nextLine();

    if (ans.toLowerCase().charAt(0) != 'y') {
      logger.info("Exciting application....");
      System.exit(0);
    }

    AccessToken token = main.requestToken();
    main.twitter.setOAuthAccessToken(token);

    Configuration globalConfig = Configuration.getInstance();
    TwitterConfig config = globalConfig.getTwitterConfig("twitter");

    if (config.isCleanDirectMessages()) main.deleteDirectMessages();
    if (config.isCleanLists()) main.removeLists();
    if (config.isCleanTweets()) main.deleteTweets();
    if (config.isCleanFavorites()) main.removeFavorites();
    if (config.isCleanReTweets()) main.removeRetweets();
    if (config.isCleanFriendships()) main.removeFriendships();

    return true;
  }
  /**
   * remove any direct messages (dm in twitter slang) that were sent and received by the user prior
   * to a certain date)
   */
  public void deleteDirectMessages() {
    try {
      boolean found = true;
      int start = 1;
      int increment = twitterConfig.getIncrementCount();
      // Removing messages sent to user
      while (found) {
        found = false;
        ResponseList<DirectMessage> responses =
            twitter.getDirectMessages(new Paging(start, start + increment));
        for (DirectMessage dm : responses) {
          if (earlier.getTime() > dm.getCreatedAt().getTime()) {
            twitter.destroyDirectMessage(dm.getId());
            logger.debug("delete dm: " + dm.getId());
            found = true;
          }
        }
      }
      found = true;
      start = 1;
      increment = twitterConfig.getIncrementCount();
      // Removing messages sent by user.
      while (found) {
        found = false;
        ResponseList<DirectMessage> responses =
            twitter.getSentDirectMessages(new Paging(start, start + increment));
        for (DirectMessage dm : responses) {
          if (earlier.getTime() > dm.getCreatedAt().getTime()) {
            twitter.destroyDirectMessage(dm.getId());
            logger.debug("delete dm: " + dm.getId());
            found = true;
          }
        }
      }

    } catch (TwitterException e) {
      logger.error("Twitter exception occurred", e);
    }
  }
 /** Remove any favorited tweets that occured prior to delta given. */
 private void removeFavorites() {
   try {
     boolean found = true;
     int start = 1;
     int increment = twitterConfig.getIncrementCount();
     while (found) {
       found = false;
       ResponseList<Status> responses = twitter.getFavorites(new Paging(start, start + increment));
       for (Status status : responses) {
         if (earlier.getTime() > status.getCreatedAt().getTime()) {
           twitter.destroyFavorite(status.getId());
           logger.debug("delete dm: " + status.getId());
           found = true;
         }
       }
     }
   } catch (TwitterException e) {
     logger.error("Twitter exception occurred", e);
   }
 }
 /**
  * Delete normal tweets sent by the users that match the delta requirements. (ie. delete tweets
  * older then 2 weeks. Default )
  */
 public void deleteTweets() {
   try {
     boolean found = true;
     int start = 1;
     int increment = twitterConfig.getIncrementCount();
     while (found) {
       found = false;
       List<Status> status = twitter.getUserTimeline(new Paging(start, start + increment));
       for (Status s : status) {
         if (earlier.getTime() > s.getCreatedAt().getTime()) {
           found = true;
           twitter.destroyStatus(s.getId());
           logger.debug("removing tweeit with id: {}", s.getId());
         }
       }
       logger.debug("size of status batch is: {} ", status.size());
     }
   } catch (TwitterException e) {
     logger.error("Twitter exception occurred", e);
   }
 }