4 releases
0.1.3 | Jun 3, 2019 |
---|---|
0.1.2 | May 27, 2019 |
0.1.1 | May 27, 2019 |
0.1.0 | May 27, 2019 |
#39 in #reddit
34KB
625 lines
redbot
(Unofficial) Rust bindings for Reddit's API.
Reddit's API documentation can be found here and endpoint documentation can be found here.
Usage
Example
use redbot::{Api, Config, Value};
fn main() {
let config = Config::load_config("config.json").expect("Could not load confiog");
let mut api = Api::new(config);
api.do_login().expect("Could not perform login");
let mut resp = match api.query("GET", "api/v1/me/karma", None, None) {
Ok(resp) => resp,
Err(err) => panic!(err),
};
let karma_breakdown: Value = match resp.json() {
Ok(data) => data,
Err(err) => panic!(err),
};
println!("{:?}", karma_breakdown);
}
lib.rs
:
This crate is used to query the Reddit API.
First, create a Config
struct. Then, use it to create an
Api
struct, which exposes several methods for querying
the API, including the models
module, which contains structs
that map to Reddit objects, simplifying the interaction with the
Reddit API.
Example
use redbot::{Api, Config, Value};
fn main() {
let config = Config::load_config("config.json").expect("Could not load confiog");
let mut api = Api::new(config);
api.do_login().expect("Could not perform login");
let mut resp = match api.query("GET", "api/v1/me/karma", None, None) {
Ok(resp) => resp,
Err(err) => panic!(err),
};
let karma_breakdown: Value = match resp.json() {
Ok(data) => data,
Err(err) => panic!(err),
};
println!("{:?}", karma_breakdown);
}
Dependencies
~20MB
~417K SLoC