Update to use search v2; fix search example

Search v1 has been removed
This commit is contained in:
D. Scott Boggs 2022-12-22 12:37:52 -05:00
parent b232db9f97
commit ed05a7b337
5 changed files with 23 additions and 22 deletions

View File

@ -1,17 +1,15 @@
#![cfg_attr(not(feature = "toml"), allow(dead_code))] #![cfg_attr(not(feature = "toml"), allow(dead_code))]
#![cfg_attr(not(feature = "toml"), allow(unused_imports))] #![cfg_attr(not(feature = "toml"), allow(unused_imports))]
#[macro_use]
extern crate pretty_env_logger;
mod register; mod register;
use register::Mastodon; use elefren::Result;
use std::error;
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> { #[tokio::main]
let mastodon = register::get_mastodon_data()?; 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 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); println!("{:#?}", result);

View File

@ -54,7 +54,7 @@ pub mod prelude {
push::Subscription, push::Subscription,
relationship::Relationship, relationship::Relationship,
report::Report, report::Report,
search_result::{SearchResult, SearchResultV2}, search_result::SearchResult,
status::{Application, Emoji, Status}, status::{Application, Emoji, Status},
Empty, Empty,
}; };

View File

@ -7,21 +7,10 @@ use super::{
status::Tag, 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<Account>,
/// An array of matched Statuses.
pub statuses: Vec<Status>,
/// An array of matched hashtags, as strings.
pub hashtags: Vec<String>,
}
/// A struct containing results of a search, with `Tag` objects in the /// A struct containing results of a search, with `Tag` objects in the
/// `hashtags` field /// `hashtags` field
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SearchResultV2 { pub struct SearchResult {
/// An array of matched Accounts. /// An array of matched Accounts.
pub accounts: Vec<Account>, pub accounts: Vec<Account>,
/// An array of matched Statuses. /// An array of matched Statuses.

View File

@ -95,6 +95,10 @@ pub struct Tag {
pub name: String, pub name: String,
/// The URL of the hashtag. /// The URL of the hashtag.
pub url: String, pub url: String,
/// Usage statistics for given days (typically the past week).
pub history: Vec<TagHistory>,
/// Whether the current tokens authorized user is following this tag.
pub following: Option<bool>,
} }
/// Application details. /// Application details.
@ -105,3 +109,14 @@ pub struct Application {
/// Homepage URL of the application. /// Homepage URL of the application.
pub website: Option<String>, pub website: Option<String>,
} }
/// 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,
}

View File

@ -89,7 +89,6 @@ impl Mastodon {
(post (domain: String,)) block_domain: "domain_blocks" => Empty, (post (domain: String,)) block_domain: "domain_blocks" => Empty,
(post (id: &str,)) authorize_follow_request: "accounts/follow_requests/authorize" => Empty, (post (id: &str,)) authorize_follow_request: "accounts/follow_requests/authorize" => Empty,
(post (id: &str,)) reject_follow_request: "accounts/follow_requests/reject" => 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<Status>, (get (local: bool,)) get_public_timeline: "timelines/public" => Vec<Status>,
(post (uri: Cow<'static, str>,)) follows: "follows" => Account, (post (uri: Cow<'static, str>,)) follows: "follows" => Account,
(post multipart (file: impl AsRef<Path>,)) media: "media" => Attachment, (post multipart (file: impl AsRef<Path>,)) media: "media" => Attachment,
@ -102,7 +101,7 @@ impl Mastodon {
} }
route_v2! { route_v2! {
(get (q: &'a str, resolve: bool,)) search_v2: "search" => SearchResultV2, (get (q: &'a str, resolve: bool,)) search: "search" => SearchResult,
} }
route_id! { route_id! {