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/status_builder.rs

84 lines
2.2 KiB

use std::fmt;
/// A builder pattern struct for constructing a status.
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
7 years ago
pub struct StatusBuilder {
/// The text of the status.
pub status: String,
/// Ids of accounts being replied to.
6 years ago
#[serde(skip_serializing_if = "Option::is_none")]
pub in_reply_to_id: Option<u64>,
/// Ids of media attachments being attached to the status.
6 years ago
#[serde(skip_serializing_if = "Option::is_none")]
pub media_ids: Option<Vec<u64>>,
/// Whether current status is sensitive.
6 years ago
#[serde(skip_serializing_if = "Option::is_none")]
pub sensitive: Option<bool>,
/// Text to precede the normal status text.
6 years ago
#[serde(skip_serializing_if = "Option::is_none")]
pub spoiler_text: Option<String>,
/// Visibility of the status, defaults to `Public`.
6 years ago
#[serde(skip_serializing_if = "Option::is_none")]
pub visibility: Option<Visibility>,
7 years ago
}
/// The visibility of a status.
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "lowercase")]
7 years ago
pub enum Visibility {
/// A Direct message to a user
7 years ago
Direct,
/// Only available to followers
7 years ago
Private,
/// Not shown in public timelines
7 years ago
Unlisted,
/// Posted to public timelines
7 years ago
Public,
}
impl StatusBuilder {
/// Create a new status with text.
/// ```
/// use elefren::prelude::*;
///
/// let status = StatusBuilder::new("Hello World!");
/// ```
pub fn new<D: fmt::Display>(status: D) -> Self {
7 years ago
StatusBuilder {
status: status.to_string(),
7 years ago
..Self::default()
}
}
}
impl Default for Visibility {
fn default() -> Self {
Visibility::Public
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new() {
let s = StatusBuilder::new("a status");
let expected = StatusBuilder {
status: "a status".to_string(),
in_reply_to_id: None,
media_ids: None,
sensitive: None,
spoiler_text: None,
visibility: None,
};
assert_eq!(s, expected);
}
#[test]
fn test_default_visibility() {
let v = Visibility::default();
assert_eq!(v, Visibility::Public);
}
}