mastodon API rust lib elefren, fixed and updated. and also all ASYNC! NB. most examples are now wrong.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
elefren-fork/src/apps.rs

74 lines
2.1 KiB

use std::fmt;
/// Builder struct for defining your application.
/// ```
/// let app = AppBuilder {
/// client_name: "mammut_test",
/// redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
/// scopes: Scopes::Read,
/// website: None,
/// };
/// ```
8 years ago
#[derive(Debug, Default, Serialize)]
pub struct AppBuilder<'a> {
/// Name of the application. Will be displayed when the user is deciding to
/// grant permission.
8 years ago
pub client_name: &'a str,
/// Where the user should be redirected after authorization
/// (for no redirect, use `urn:ietf:wg:oauth:2.0:oob`)
8 years ago
pub redirect_uris: &'a str,
/// Permission scope of the application.
pub scopes: Scopes,
/// URL to the homepage of your application.
8 years ago
#[serde(skip_serializing_if="Option::is_none")]
pub website: Option<&'a str>,
}
/// Permission scope of the application.
/// [Details on what each permission provides](//github.com/tootsuite/documentation/blob/master/Using-the-API/OAuth-details.md)
8 years ago
#[derive(Debug, Clone, Copy, Serialize)]
pub enum Scopes {
/// All Permissions, equivalent to `read write follow`
8 years ago
#[serde(rename = "read write follow")]
All,
/// Only permission to add and remove followers.
8 years ago
#[serde(rename = "follow")]
Follow,
/// Read only permissions.
8 years ago
#[serde(rename = "read")]
Read,
/// Read & Follow permissions.
8 years ago
#[serde(rename = "read follow")]
ReadFollow,
/// Read & Write permissions.
8 years ago
#[serde(rename = "read write")]
ReadWrite,
/// Write only permissions.
8 years ago
#[serde(rename = "write")]
Write,
/// Write & Follow permissions.
8 years ago
#[serde(rename = "write follow")]
WriteFollow,
}
impl fmt::Display for Scopes {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Scopes::*;
write!(f, "{}", match *self {
All => "read%20write%20follow",
Follow => "follow",
Read => "read",
ReadFollow => "read%20follow",
ReadWrite => "read%20write",
Write => "write",
WriteFollow => "write%20follow"
})
}
}
impl Default for Scopes {
8 years ago
fn default() -> Self {
Scopes::Read
8 years ago
}
}