Crate orca

source ·
Expand description

orca

orca is a library to make using the Reddit API from Rust easy

Features

orca has not yet implemented near all of the functionality available in the Reddit API, but enough has been implemented to make simple flexible scripts or apps. Some main functionality includes:

  • submitting self posts
  • automatic ratelimiting
  • commenting and replying
  • comment streams from subreddits
  • private messages
  • authorization as script or installed oauth app type
  • more stuff

Structure

All of the functionality necessary is available in the implementation of the App struct. Data structures are defined in orca::data. Networking code is present in the net module, which also contains OAuth authorization functionality.

Usage

To simply create a reddit app instance, do

let mut reddit = App::new(name, version, author).unwrap();

where name, version, and author are all &strs.

This instance can do actions that don’t require authorization, such as retrieving a stream of comments from a subreddit, but actions such as commenting require authorization, which can be done multiple ways. The most common way for clients to authorize is as scripts, which can be done by just providing a username and password as well as the id and secret of the app that can be registered on the desktop site. It looks like this in code (assuming you already have a mutable reddit instance):

reddit.authorize_script(id, secret, username, password).unwrap();

More info can be found in the documentation for the net module

Actually doing something is simple and similar to previous examples. To get info about the currently authorized user, simply call

reddit.get_self();

which will return a json value until the actual user data structure is implemented.

Re-exports

pub use app::App;
pub use errors::RedditError;
pub use net::auth;
pub use net::auth::InstalledAppError;
pub use net::auth::ResponseGenFn;
pub use net::auth::Scopes;
pub use net::Connection;
pub use net::LimitMethod;

Modules

Main entry point
Reddit data structures
Errors
Functionality for communication with reddit.com The module contains networking, http, ratelimiting, authorization and more functionality.

Enums

Sort type of a subreddit
Time parameter of a subreddit sort