Ejemplo n.º 1
0
  /**
   * Retrieves all the top posts
   *
   * @param subreddit The subreddit that Posts will be returned from. Use "all" to return results
   *     from all subreddits.
   * @param sortMode The order that the Posts will be sorted by. Options are: "top" (ranked by
   *     upvotes minus downvotes), "best" (similar to top, except that it uses a more complicated
   *     algorithm to have good posts jump to the top and stay there, and bad comments to work their
   *     way down, see http://blog.reddit.com/2009/10/reddits-new-comment-sorting-system.html),
   *     "hot" (similar to "top", but weighted by time so that recent, popular posts are put near
   *     the top), "new" (posts will be sorted by creation time).
   * @param callback The listener that will be given the data (or error)
   */
  public void getPosts(
      String subreddit, String sortMode, final StructuredGetPostsListener callback) {

    jsonInstance.getPosts(
        subreddit,
        sortMode,
        new JsonGetPostsListener() {
          @Override
          public void getPostsFailed(Exception exception) {
            callback.getPostsFailed(exception);
          }

          @Override
          public void getPostsCompleted(String data) {
            callback.getPostsCompleted(gson.fromJson(data, ArrayList.class));
          }
        });
  }
Ejemplo n.º 2
0
 /**
  * Retrieves all the top posts
  *
  * @param subreddit The subreddit that Posts will be returned from. Use "all" to return results
  *     from all subreddits.
  * @param sortMode The order that the Posts will be sorted by. Options are: "top" (ranked by
  *     upvotes minus downvotes), "best" (similar to top, except that it uses a more complicated
  *     algorithm to have good posts jump to the top and stay there, and bad comments to work their
  *     way down, see http://blog.reddit.com/2009/10/reddits-new-comment-sorting-system.html),
  *     "hot" (similar to "top", but weighted by time so that recent, popular posts are put near
  *     the top), "new" (posts will be sorted by creation time).
  * @return HashMap<String, Object>
  */
 public HashMap<String, Object> getPosts(String subreddit, String sortMode) throws Exception {
   return gson.fromJson(jsonInstance.getPosts(subreddit, sortMode), LinkedHashMap.class);
 }