Struct rraw::Client

source ·
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>

source

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

source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

pub async fn re_login(&self) -> Result<bool, Error>

source§

impl<A: Authorized> Client<A>

source

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(())
}
source

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§

source§

impl<A: Clone + Authenticator> Clone for Client<A>

source§

fn clone(&self) -> Client<A>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<A: Authenticator> Debug for Client<A>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more