pub struct Client<A: Authenticator> {
pub oauth: bool,
/* private fields */
}
Expand description
This is who you are. This is your identity and you access point to the Reddit API
Fields§
§oauth: bool
Implementations§
source§impl<A: Authenticator> Client<A>
impl<A: Authenticator> Client<A>
sourcepub async fn login<S: Into<String>>(
auth: A,
user_agent: S
) -> Result<Client<A>, Error>
pub async fn login<S: Into<String>>( auth: A, user_agent: S ) -> Result<Client<A>, Error>
Creates a Instance of the Client. Complete Initial Login Steps
sourcepub async fn domain<T: Into<String>>(
&self,
name: T,
feed_options: Option<FeedOption>
) -> Result<SubmissionsResponse, Error>
pub async fn domain<T: Into<String>>( &self, name: T, feed_options: Option<FeedOption> ) -> Result<SubmissionsResponse, Error>
Loads a Domain listing
#[tokio::main]
async fn main() ->anyhow::Result<()>{
use log::LevelFilter;
use rraw::auth::AnonymousAuthenticator;
use rraw::Client;
env_logger::builder().is_test(true).filter_level(LevelFilter::Trace).try_init();
let client = Client:: login(AnonymousAuthenticator::new(), "RRAW Test (by u/KingTuxWH)").await?;
let subreddit = client.domain("rust-lang.org",None);
Ok(())
}
sourcepub async fn subreddit<T: Into<String>>(
&self,
name: T
) -> Result<Subreddit<'_, A>, Error>
pub async fn subreddit<T: Into<String>>( &self, name: T ) -> Result<Subreddit<'_, A>, Error>
Loads SubReddit
#[tokio::main]
async fn main() ->anyhow::Result<()>{
use log::LevelFilter;
use rraw::auth::AnonymousAuthenticator;
use rraw::Client;
env_logger::builder().is_test(true).filter_level(LevelFilter::Trace).try_init();
let client = Client:: login(AnonymousAuthenticator::new(), "RRAW Test (by u/KingTuxWH)").await?;
let subreddit = client.subreddit("rust");
Ok(())
}
sourcepub async fn user<T: Into<String>>(&self, name: T) -> Result<User<'_, A>, Error>
pub async fn user<T: Into<String>>(&self, name: T) -> Result<User<'_, A>, Error>
Creates a User struct.
#[tokio::main]
async fn main() ->anyhow::Result<()>{
use log::LevelFilter;
use rraw::auth::AnonymousAuthenticator;
use rraw::Client;
env_logger::builder().is_test(true).filter_level(LevelFilter::Trace).try_init();
let client = Client:: login(AnonymousAuthenticator::new(), "RRAW Test (by u/KingTuxWH)").await?;
let subreddit = client.user("KingTuxWH").await?;
Ok(())
}
sourcepub async fn search_subreddits<S: Into<String>>(
&self,
name: S,
limit: Option<u64>,
feed: Option<FeedOption>
) -> Result<Subreddits>
pub async fn search_subreddits<S: Into<String>>( &self, name: S, limit: Option<u64>, feed: Option<FeedOption> ) -> Result<Subreddits>
Searches for Subreddits by name
#[tokio::main]
async fn main() ->anyhow::Result<()>{
use log::LevelFilter;
use rraw::auth::AnonymousAuthenticator;
use rraw::Client;
env_logger::builder().is_test(true).filter_level(LevelFilter::Trace).try_init();
let client = Client:: login(AnonymousAuthenticator::new(), "RRAW Test (by u/KingTuxWH)").await?;
let subreddits = client.search_subreddits("rust", None, None).await?;
Ok(())
}
sourcepub async fn search_users<S: Into<String>>(
&self,
name: S,
limit: Option<u64>,
feed: Option<FeedOption>
) -> Result<Users>
pub async fn search_users<S: Into<String>>( &self, name: S, limit: Option<u64>, feed: Option<FeedOption> ) -> Result<Users>
Searches for Subreddits by name
#[tokio::main]
async fn main() ->anyhow::Result<()>{
use log::LevelFilter;
use rraw::auth::AnonymousAuthenticator;
use rraw::Client;
env_logger::builder().is_test(true).filter_level(LevelFilter::Trace).try_init();
let client = Client:: login(AnonymousAuthenticator::new(), "RRAW Test (by u/KingTuxWH)").await?;
let users = client.search_users("King", None, None).await?;
Ok(())
}
pub async fn re_login(&self) -> Result<bool, Error>
source§impl<A: Authorized> Client<A>
impl<A: Authorized> Client<A>
sourcepub async fn me(&self) -> Result<Me<'_, A>, Error>
pub async fn me(&self) -> Result<Me<'_, A>, Error>
Gets the User Inbox Struct
#[tokio::main]
async fn main() ->anyhow::Result<()>{
use std::env;
use log::LevelFilter;
use rraw::auth::{ PasswordAuthenticator};
use rraw::Client;
env_logger::builder().is_test(true).filter_level(LevelFilter::Trace).try_init();
let client = Client:: login(PasswordAuthenticator::new(env::var("CLIENT_ID")?,env::var("CLIENT_SECRET")?,env::var("USERNAME")?,env::var("PASSWORD")?), "RRAW Test (by u/KingTuxWH)").await?;
let me = client.me().await?;
Ok(())
}
sourcepub fn refresh_token(&self) -> Option<String>
pub fn refresh_token(&self) -> Option<String>
Gets the Refresh Token if exist
Note: Refresh Token only will be exist when using CodeAuthenticator with an Permanent Duration Authorization Code. The Refresh Token must be stored in a secure manner such as using the platform’s Secret/Keyring service for future use.
#[tokio::main]
async fn main() ->anyhow::Result<()>{
use std::env;
use log::LevelFilter;
use rraw::auth::{ CodeAuthenticator};
use rraw::Client;
env_logger::builder().is_test(true).filter_level(LevelFilter::Trace).try_init();
let client = Client:: login(CodeAuthenticator::new(env::var("CLIENT_ID")?,env::var("CLIENT_SECRET")?,env::var("CODE")?,env::var("REDIRECT_URI")?), "RRAW Test (by u/KingTuxWH)").await?;
let refresh_token = client.refresh_token();
if refresh_token.is_some() {
println!("Refresh Token Is: {}", refresh_token.unwrap());
} else {
println!("Refresh Token Not Exist!");
}
Ok(())
}
Trait Implementations§
Auto Trait Implementations§
impl<A> !RefUnwindSafe for Client<A>
impl<A> Send for Client<A>
impl<A> Sync for Client<A>
impl<A> Unpin for Client<A>
impl<A> !UnwindSafe for Client<A>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more