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(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<error::Error>> {
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);

View File

@ -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,
};

View File

@ -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<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
/// `hashtags` field
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SearchResultV2 {
pub struct SearchResult {
/// An array of matched Accounts.
pub accounts: Vec<Account>,
/// An array of matched Statuses.

View File

@ -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<TagHistory>,
/// Whether the current tokens authorized user is following this tag.
pub following: Option<bool>,
}
/// Application details.
@ -105,3 +109,14 @@ pub struct Application {
/// Homepage URL of the application.
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 (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<Status>,
(post (uri: Cow<'static, str>,)) follows: "follows" => Account,
(post multipart (file: impl AsRef<Path>,)) 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! {