summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorD. Scott Boggs <scott@tams.tech>2022-12-26 12:19:51 -0500
committerD. Scott Boggs <scott@tams.tech>2022-12-26 12:19:51 -0500
commit77ccc715c89f08e4b380bf89ca4acf92e9b251fa (patch)
tree2d62e3fe6795fa0493a9dd297f9c2743a396f872
parenta1e12dcfea9ae80b56f9135d31db368cad3c8701 (diff)
Fix discrepancy in server response formatsfix/tag-response
-rw-r--r--examples/post_status.rs43
-rw-r--r--examples/register/mod.rs21
-rw-r--r--examples/upload_photo.rs22
-rw-r--r--src/entities/status.rs7
4 files changed, 71 insertions, 22 deletions
diff --git a/examples/post_status.rs b/examples/post_status.rs
new file mode 100644
index 0000000..187d143
--- /dev/null
+++ b/examples/post_status.rs
@@ -0,0 +1,43 @@
+#![cfg_attr(not(feature = "toml"), allow(dead_code))]
+#![cfg_attr(not(feature = "toml"), allow(unused_imports))]
+mod register;
+
+use mastodon_async::{Language, Result, StatusBuilder, Visibility};
+
+#[cfg(feature = "toml")]
+#[tokio::main]
+async fn main() -> Result<()> {
+ let mastodon = register::get_mastodon_data().await?;
+ let status = StatusBuilder::new()
+ .status(register::read_line(
+ "Enter a status to post privately (enter to send): ",
+ )?)
+ .visibility(Visibility::Private)
+ .language(Language::Eng)
+ .build()?;
+
+ let status = mastodon.new_status(status).await?;
+
+ print!("Status posted");
+ if let Some(url) = status.url {
+ // this is the expected thing to happen
+ println!(", visible when logged in at: {}\n", url);
+ } else {
+ println!(". For some reason, the status URL was not returned from the server.");
+ println!("Maybe try here? {}/{}", status.account.url, status.id);
+ }
+ if register::bool_input("delete this post? (Y/n)", true)? {
+ mastodon.delete_status(&status.id).await?;
+ println!("ok, done")
+ }
+
+ Ok(())
+}
+
+#[cfg(not(feature = "toml"))]
+fn main() {
+ println!(
+ "examples require the `toml` feature, run this command for this example:\n\ncargo run \
+ --example post_status --features toml\n"
+ );
+}
diff --git a/examples/register/mod.rs b/examples/register/mod.rs
index 8daedb1..72802ae 100644
--- a/examples/register/mod.rs
+++ b/examples/register/mod.rs
@@ -54,5 +54,26 @@ pub fn read_line(message: impl AsRef<str>) -> Result<String> {
Ok(input.trim().to_string())
}
+#[cfg(feature = "toml")]
+pub fn bool_input(message: impl AsRef<str>, default: bool) -> Result<bool> {
+ let input = read_line(message.as_ref())?;
+ if let Some(first_char) = input.chars().next() {
+ match first_char {
+ 'Y' | 'y' => Ok(true),
+ 'N' | 'n' => Ok(false),
+ '\n' => Ok(default),
+ _ => {
+ print!(
+ "I didn't understand '{input}'. Please input something that begins with 'y' \
+ or 'n', case insensitive: "
+ );
+ bool_input(message, default)
+ },
+ }
+ } else {
+ Ok(default)
+ }
+}
+
#[cfg(not(feature = "toml"))]
fn main() {}
diff --git a/examples/upload_photo.rs b/examples/upload_photo.rs
index 62c9904..ddd2de6 100644
--- a/examples/upload_photo.rs
+++ b/examples/upload_photo.rs
@@ -4,29 +4,9 @@ mod register;
use mastodon_async::{Result, StatusBuilder, Visibility};
#[cfg(feature = "toml")]
-fn bool_input(message: impl AsRef<str>, default: bool) -> Result<bool> {
- let input = register::read_line(message.as_ref())?;
- if let Some(first_char) = input.chars().next() {
- match first_char {
- 'Y' | 'y' => Ok(true),
- 'N' | 'n' => Ok(false),
- '\n' => Ok(default),
- _ => {
- print!(
- "I didn't understand '{input}'. Please input something that begins with 'y' \
- or 'n', case insensitive: "
- );
- bool_input(message, default)
- },
- }
- } else {
- Ok(default)
- }
-}
-
-#[cfg(feature = "toml")]
#[tokio::main]
async fn main() -> Result<()> {
+ use register::bool_input;
femme::with_level(femme::LevelFilter::Trace);
let mastodon = register::get_mastodon_data().await?;
let input = register::read_line("Enter the path to the photo you'd like to post: ")?;
diff --git a/src/entities/status.rs b/src/entities/status.rs
index a094b0c..44c9bd3 100644
--- a/src/entities/status.rs
+++ b/src/entities/status.rs
@@ -88,7 +88,11 @@ pub struct Emoji {
pub url: String,
}
-/// Hashtags in the status.
+/// Hashtags in the status. This functions both as a
+/// [`Status::Tag`](https://docs.joinmastodon.org/entities/Status/#Tag), and
+/// as a [`Tag`](https://docs.joinmastodon.org/entities/Tag/). In the case of
+/// the former, at the time of writing, the history field is always empty and
+/// the following field is always none.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Tag {
/// The hashtag, not including the preceding `#`.
@@ -96,6 +100,7 @@ pub struct Tag {
/// The URL of the hashtag.
pub url: String,
/// Usage statistics for given days (typically the past week).
+ #[serde(default = "Vec::new")]
pub history: Vec<TagHistory>,
/// Whether the current token’s authorized user is following this tag.
pub following: Option<bool>,