2个版本

使用旧的Rust 2015

0.1.1 2016年8月3日
0.1.0 2016年8月2日

#17 in #comment

26 每月下载量
用于 hello-rs

MIT 许可证

115KB
2K SLoC

rawr

Build Status Gitter Documentation Crates.io

欢迎来到rawr,这是Reddit的Rust API包装器。此库提供简单、无痛苦地访问Reddit API的接口。如果您想创建Reddit机器人、从API抓取数据或创建由Reddit API驱动的Web应用程序,rawr可以帮助您轻松有效地完成这些任务。

特性

  • 支持基于密码的认证(带有OAuth支持,因此您的应用更具未来性!)和匿名认证。
  • 可迭代的帖子列表和评论列表,会根据需要自动从API获取数据。
  • '流'用于获取最新的线程/评论/消息,会通过轮询API自动更新——非常适合响应新帖子的机器人。

示例

extern crate rawr;
use rawr::prelude::*;
    
fn main() {
    // Creates a new client to access the reddit API. You need to set a user agent so Reddit knows
    // who is using this client.
    let client = RedditClient::new("your user agent here", AnonymousAuthenticator::new());
    // Access the subreddit /r/rust.
    let subreddit = client.subreddit("rust");
    // Gets the hot listing of /r/rust. If the API request fails, we will panic with `expect`.
    let mut hot_listing = subreddit.hot(ListingOptions::default()).expect("Could not fetch post listing!");
    // Iterates through the top 50 posts of /r/rust. If you do not `take(n)`, this iterator will
    // continue forever!
    for post in hot_listing.take(50) {
        println!("{}", post.title());
    }
}

依赖项

~6.5MB
~156K SLoC