From ed05a7b337fc3020f2d696bdae35bb9f37afe322 Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Thu, 22 Dec 2022 12:37:52 -0500 Subject: [PATCH] Update to use search v2; fix search example Search v1 has been removed --- examples/search.rs | 12 +++++------- src/entities/mod.rs | 2 +- src/entities/search_result.rs | 13 +------------ src/entities/status.rs | 15 +++++++++++++++ src/mastodon.rs | 3 +-- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/examples/search.rs b/examples/search.rs index 4bd2756..a72d7ff 100644 --- a/examples/search.rs +++ b/examples/search.rs @@ -1,17 +1,15 @@ #![cfg_attr(not(feature = "toml"), allow(dead_code))] #![cfg_attr(not(feature = "toml"), allow(unused_imports))] -#[macro_use] -extern crate pretty_env_logger; mod register; -use register::Mastodon; -use std::error; +use elefren::Result; #[cfg(feature = "toml")] -fn main() -> Result<(), Box> { - let mastodon = register::get_mastodon_data()?; +#[tokio::main] +async fn main() -> Result<()> { + let mastodon = register::get_mastodon_data().await?; let input = register::read_line("Enter the term you'd like to search: ")?; - let result = mastodon.search(&input, false)?; + let result = mastodon.search(&input, false).await?; println!("{:#?}", result); diff --git a/src/entities/mod.rs b/src/entities/mod.rs index aef8121..f726abc 100644 --- a/src/entities/mod.rs +++ b/src/entities/mod.rs @@ -54,7 +54,7 @@ pub mod prelude { push::Subscription, relationship::Relationship, report::Report, - search_result::{SearchResult, SearchResultV2}, + search_result::SearchResult, status::{Application, Emoji, Status}, Empty, }; diff --git a/src/entities/search_result.rs b/src/entities/search_result.rs index 499af5f..e757f71 100644 --- a/src/entities/search_result.rs +++ b/src/entities/search_result.rs @@ -7,21 +7,10 @@ use super::{ status::Tag, }; -/// A struct containing results of a search. -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub struct SearchResult { - /// An array of matched Accounts. - pub accounts: Vec, - /// An array of matched Statuses. - pub statuses: Vec, - /// An array of matched hashtags, as strings. - pub hashtags: Vec, -} - /// A struct containing results of a search, with `Tag` objects in the /// `hashtags` field #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub struct SearchResultV2 { +pub struct SearchResult { /// An array of matched Accounts. pub accounts: Vec, /// An array of matched Statuses. diff --git a/src/entities/status.rs b/src/entities/status.rs index 2de5d26..a094b0c 100644 --- a/src/entities/status.rs +++ b/src/entities/status.rs @@ -95,6 +95,10 @@ pub struct Tag { pub name: String, /// The URL of the hashtag. pub url: String, + /// Usage statistics for given days (typically the past week). + pub history: Vec, + /// Whether the current token’s authorized user is following this tag. + pub following: Option, } /// Application details. @@ -105,3 +109,14 @@ pub struct Application { /// Homepage URL of the application. pub website: Option, } + +/// Usage statistics for given days (typically the past week). +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct TagHistory { + /// UNIX timestamp on midnight of the given day. + pub day: String, + /// The counted usage of the tag within that day. + pub uses: String, + /// The total of accounts using the tag within that day. + pub accounts: String, +} diff --git a/src/mastodon.rs b/src/mastodon.rs index 31adfa0..fc40e6f 100644 --- a/src/mastodon.rs +++ b/src/mastodon.rs @@ -89,7 +89,6 @@ impl Mastodon { (post (domain: String,)) block_domain: "domain_blocks" => Empty, (post (id: &str,)) authorize_follow_request: "accounts/follow_requests/authorize" => Empty, (post (id: &str,)) reject_follow_request: "accounts/follow_requests/reject" => Empty, - (get (q: &'a str, resolve: bool,)) search: "search" => SearchResult, (get (local: bool,)) get_public_timeline: "timelines/public" => Vec, (post (uri: Cow<'static, str>,)) follows: "follows" => Account, (post multipart (file: impl AsRef,)) media: "media" => Attachment, @@ -102,7 +101,7 @@ impl Mastodon { } route_v2! { - (get (q: &'a str, resolve: bool,)) search_v2: "search" => SearchResultV2, + (get (q: &'a str, resolve: bool,)) search: "search" => SearchResult, } route_id! {