Skip to main content

RedditOAuth

Struct RedditOAuth 

Source
pub struct RedditOAuth {
    pub callback_url: String,
    pub oauth_state: OAuthState,
    pub error_string: Option<String>,
    pub state_string: String,
    pub client_credentials: RedditClientCredentials,
}

Fields§

§callback_url: String§oauth_state: OAuthState§error_string: Option<String>§state_string: String§client_credentials: RedditClientCredentials

Implementations§

Source§

impl RedditOAuth

Source

pub fn default() -> RedditOAuth

Source

pub fn state_string(self, state_string: &str) -> RedditOAuth

Set state_string

Source

pub fn oauth_state(self, oauth_state: OAuthState) -> RedditOAuth

Set oauth_state

Source

pub fn error_state(self, error_state: &str) -> RedditOAuth

Set `error_string’

Source

pub fn build(self) -> RedditOAuth

Validate RedditOAuth object. After calling, object is ready to use

Source

pub fn authorize_client( &mut self, scope: &str, duration: Option<AuthorizationTime>, ) -> Option<OAuthToken>

Authorize user by opening default browser and present reddit authorization dialog. This needs user interaction to receive Bearer Token

§Arguments
  • scope - String of concatenated scopes the bearer token should have authorization of
  • duration - AuthorizationTime::permanent or AuthorizationTime::temporary
§Returns

Option<OAuthToken> If authorization was successfull, OAuthToken is set, otherwise RedditOAuth.oauth_state=OAuthState::error with an error message in RedditOAuth.error_string If duration is permanent, bearer token will be invalid after one hour. The token has to be refreshed with the refresh_token

Source

pub fn refresh_token(&mut self, to_refresh: &OAuthToken) -> Option<OAuthToken>

Refresh bearer token when the previous one expired

§Arguments
  • to_refresh - Old bearer token which should be refreshed
§Returns

Option<OAuthToken> If authorization was successfull, OAuthToken is set, otherwise RedditOAuth.oauth_state=OAuthState::error with an error message in RedditOAuth.error_string If duration is permanent, bearer token will be invalid after one hour. The token has to be refreshed with the refresh_token

Source

pub fn revoke_token(&mut self, to_revoke: &OAuthToken) -> Result<(), String>

Revoke a token by hand.

§Arguments
  • to_revoke - Token to revoke its access
Source

pub fn get_initial_access_token(&self, state: &str) -> Option<OAuthToken>

Request access token

§Arguments
  • state - State string returned by reddit authorization process
§Returns

Option<OAuthToken> If authorization was successfull, OAuthToken is set, otherwise RedditOAuth.oauth_state=OAuthState::error with an error message in RedditOAuth.error_string If duration is permanent, bearer token will be invalid after one hour. The token has to be refreshed with the refresh_token

Trait Implementations§

Source§

impl Clone for RedditOAuth

Source§

fn clone(&self) -> RedditOAuth

Returns a duplicate 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 Debug for RedditOAuth

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RedditOAuth

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for RedditOAuth

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,