reddit 0.1.0+1 copy "reddit: ^0.1.0+1" to clipboard
reddit: ^0.1.0+1 copied to clipboard

outdatedDart 1 only

A Reddit library for Dart.

dart-reddit #

A Reddit library for Dart, inspired by reddit.js.

Documentation #

See the Dart documentation: TODO

Usage #

Add the following to your pubspec.yaml:

dependencies:
  reddit: any

Creating a client #

The top class Reddit takes a Client as parameter. This client can be constructed using thehttp package.

// in Dart VM
Reddit reddit = new Reddit(new Client());
// in browser
Reddit reddit = new Reddit(new BrowserClient());

Queries, filters and listings #

Most methods in the API construct a Query, which can be fetched to get a future with the results.

Most queries allow filtering. For the supported filters, we refer to the Reddit API docs or the API docs for this library.

// without filters
reddit.front.new().fetch().then(print);
// filtered
reddit.front.hot().limit(10).fetch().then(print);

A lot of queries also are listings. Listings allow for browsing through content across multiple queries.

// using the regular fetch() method (not recommended)
reddit.sub("dartlang").top("day").fetch().then((result) {
  print(result);
  if (notEnough) {
    result.fetchMore().then((result) {
      print(result);
      if (stillNotEnough) {
        result.fetchmore().then(print);
      }
    });
  }
});

// or using the dart:async API
reddit.sub("dartlang").top("month").listen((result) {
  print(result);
  if (notEnough) {
    result.fetchmore();
  }
})

Browsing Reddit #

You can use the standard read-only API to browse Reddit.

// the front page
reddit.front.hot().fetch().then(print);
// or subreddits
reddit.sub("dartlang").hot().fetch().then(print);

Some examples using filters:

reddit.sub("dartlang").top().t("day").limit(10).fetch().then(print);

Comments #

Fetching comments for a link:

reddit.sub("dartlang").comments("2ek93l").depth(3).fetch().then(print);

Or a single comment:

reddit.sub("dartlang").comments("2ek93l").comment("ck0mkcy").context(2).fetch().then(print);

Search through reddit:

reddit.sub("dartlang").search("reddit api").limit(5).sort("hot").fetch().then(print);

Subreddits #

Find subreddits:

reddit.newSubreddits().fetch().then(print);

reddit.popularSubreddits().fetch().then(print);

reddit.recommendedSubreddits(["dartlang", "reddit"]).fetch().then(print);

reddit.subredditsByTopic("programming").fetch().then(print);

Get information about a subreddit:

reddit.sub("dartlang").about().fetch().then(print);

Users #

Get information about a user:

reddit.user("sroose").about().fetch().then(print);

Get listings from users:

reddit.user("sroose").comments("month").listen(print);

reddit.user("sroose").submitted("week").sort("hot").listen(print);

Get a list of multi's from a user:

reddit.user("sroose").multis().fetch().then(print);
8
likes
0
pub points
7%
popularity

Publisher

unverified uploader

A Reddit library for Dart.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

http, json_object, logging

More

Packages that depend on reddit