forked from MightyPork/elefren-fork
Implement a method for GET /api/v2/search
This commit is contained in:
+1
-1
@@ -43,7 +43,7 @@ pub mod prelude {
|
|||||||
notification::Notification,
|
notification::Notification,
|
||||||
relationship::Relationship,
|
relationship::Relationship,
|
||||||
report::Report,
|
report::Report,
|
||||||
search_result::SearchResult,
|
search_result::{SearchResult, SearchResultV2},
|
||||||
status::{Application, Emoji, Status},
|
status::{Application, Emoji, Status},
|
||||||
Empty,
|
Empty,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
//! A module containing info relating to a search result.
|
//! A module containing info relating to a search result.
|
||||||
|
|
||||||
use super::prelude::{Account, Status};
|
use super::{
|
||||||
|
prelude::{Account, Status},
|
||||||
|
status::Tag,
|
||||||
|
};
|
||||||
|
|
||||||
/// A struct containing results of a search.
|
/// A struct containing results of a search.
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
@@ -12,3 +15,15 @@ pub struct SearchResult {
|
|||||||
/// An array of matched hashtags, as strings.
|
/// An array of matched hashtags, as strings.
|
||||||
pub hashtags: Vec<String>,
|
pub hashtags: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A struct containing results of a search, with `Tag` objects in the
|
||||||
|
/// `hashtags` field
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct SearchResultV2 {
|
||||||
|
/// An array of matched Accounts.
|
||||||
|
pub accounts: Vec<Account>,
|
||||||
|
/// An array of matched Statuses.
|
||||||
|
pub statuses: Vec<Status>,
|
||||||
|
/// An array of matched hashtags, as `Tag` objects.
|
||||||
|
pub hashtags: Vec<Tag>,
|
||||||
|
}
|
||||||
|
|||||||
@@ -193,6 +193,10 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> {
|
|||||||
(post) clear_notifications: "notifications/clear" => Empty,
|
(post) clear_notifications: "notifications/clear" => Empty,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
route_v2! {
|
||||||
|
(get (q: &'a str, resolve: bool,)) search_v2: "search" => SearchResultV2,
|
||||||
|
}
|
||||||
|
|
||||||
route_id! {
|
route_id! {
|
||||||
(get) get_account: "accounts/{}" => Account,
|
(get) get_account: "accounts/{}" => Account,
|
||||||
(post) follow: "accounts/{}/follow" => Account,
|
(post) follow: "accounts/{}/follow" => Account,
|
||||||
|
|||||||
+49
-8
@@ -19,7 +19,7 @@ macro_rules! paged_routes {
|
|||||||
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
doc_comment! {
|
doc_comment! {
|
||||||
concat!(
|
concat!(
|
||||||
"Equivalent to `/api/v1/",
|
"Equivalent to `", stringify!($method), " /api/v1/",
|
||||||
$url,
|
$url,
|
||||||
"`\n# Errors\nIf `access_token` is not set.",
|
"`\n# Errors\nIf `access_token` is not set.",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -57,7 +57,7 @@ macro_rules! paged_routes {
|
|||||||
((get ($($(#[$m:meta])* $param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
((get ($($(#[$m:meta])* $param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
doc_comment! {
|
doc_comment! {
|
||||||
concat!(
|
concat!(
|
||||||
"Equivalent to `/api/v1/",
|
"Equivalent to `get /api/v1/",
|
||||||
$url,
|
$url,
|
||||||
"`\n# Errors\nIf `access_token` is not set."
|
"`\n# Errors\nIf `access_token` is not set."
|
||||||
),
|
),
|
||||||
@@ -101,12 +101,53 @@ macro_rules! paged_routes {
|
|||||||
() => {}
|
() => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! route_v2 {
|
||||||
|
((get ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
|
doc_comment! {
|
||||||
|
concat!(
|
||||||
|
"Equivalent to `get /api/v2/",
|
||||||
|
$url,
|
||||||
|
"`\n# Errors\nIf `access_token` is not set."
|
||||||
|
),
|
||||||
|
fn $name<'a>(&self, $($param: $typ,)*) -> Result<$ret> {
|
||||||
|
use serde_urlencoded;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct Data<'a> {
|
||||||
|
$(
|
||||||
|
$param: $typ,
|
||||||
|
)*
|
||||||
|
#[serde(skip)]
|
||||||
|
_marker: ::std::marker::PhantomData<&'a ()>,
|
||||||
|
}
|
||||||
|
|
||||||
|
let qs_data = Data {
|
||||||
|
$(
|
||||||
|
$param: $param,
|
||||||
|
)*
|
||||||
|
_marker: ::std::marker::PhantomData,
|
||||||
|
};
|
||||||
|
|
||||||
|
let qs = serde_urlencoded::to_string(&qs_data)?;
|
||||||
|
|
||||||
|
let url = format!(concat!("/api/v2/", $url, "?{}"), &qs);
|
||||||
|
|
||||||
|
Ok(self.get(self.route(&url))?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
route_v2!{$($rest)*}
|
||||||
|
};
|
||||||
|
|
||||||
|
() => {}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! route {
|
macro_rules! route {
|
||||||
|
|
||||||
((post multipart ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
((post multipart ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
doc_comment! {
|
doc_comment! {
|
||||||
concat!(
|
concat!(
|
||||||
"Equivalent to `/api/v1/",
|
"Equivalent to `post /api/v1/",
|
||||||
$url,
|
$url,
|
||||||
"`\n# Errors\nIf `access_token` is not set."),
|
"`\n# Errors\nIf `access_token` is not set."),
|
||||||
fn $name(&self, $($param: $typ,)*) -> Result<$ret> {
|
fn $name(&self, $($param: $typ,)*) -> Result<$ret> {
|
||||||
@@ -141,7 +182,7 @@ macro_rules! route {
|
|||||||
((get ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
((get ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
doc_comment! {
|
doc_comment! {
|
||||||
concat!(
|
concat!(
|
||||||
"Equivalent to `/api/v1/",
|
"Equivalent to `get /api/v1/",
|
||||||
$url,
|
$url,
|
||||||
"`\n# Errors\nIf `access_token` is not set."
|
"`\n# Errors\nIf `access_token` is not set."
|
||||||
),
|
),
|
||||||
@@ -178,7 +219,7 @@ macro_rules! route {
|
|||||||
(($method:ident ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
(($method:ident ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
doc_comment! {
|
doc_comment! {
|
||||||
concat!(
|
concat!(
|
||||||
"Equivalent to `/api/v1/",
|
"Equivalent to `", stringify!($method), " /api/v1/",
|
||||||
$url,
|
$url,
|
||||||
"`\n# Errors\nIf `access_token` is not set.",
|
"`\n# Errors\nIf `access_token` is not set.",
|
||||||
),
|
),
|
||||||
@@ -213,7 +254,7 @@ macro_rules! route {
|
|||||||
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
doc_comment! {
|
doc_comment! {
|
||||||
concat!(
|
concat!(
|
||||||
"Equivalent to `/api/v1/",
|
"Equivalent to `", stringify!($method), " /api/v1/",
|
||||||
$url,
|
$url,
|
||||||
"`\n# Errors\nIf `access_token` is not set.",
|
"`\n# Errors\nIf `access_token` is not set.",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -251,7 +292,7 @@ macro_rules! route_id {
|
|||||||
$(
|
$(
|
||||||
doc_comment! {
|
doc_comment! {
|
||||||
concat!(
|
concat!(
|
||||||
"Equivalent to `/api/v1/",
|
"Equivalent to `", stringify!($method), " /api/v1/",
|
||||||
$url,
|
$url,
|
||||||
"`\n# Errors\nIf `access_token` is not set.",
|
"`\n# Errors\nIf `access_token` is not set.",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -285,7 +326,7 @@ macro_rules! paged_routes_with_id {
|
|||||||
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
doc_comment! {
|
doc_comment! {
|
||||||
concat!(
|
concat!(
|
||||||
"Equivalent to `/api/v1/",
|
"Equivalent to `", stringify!($method), " /api/v1/",
|
||||||
$url,
|
$url,
|
||||||
"`\n# Errors\nIf `access_token` is not set.",
|
"`\n# Errors\nIf `access_token` is not set.",
|
||||||
"\n",
|
"\n",
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ pub trait MastodonClient<H: HttpSend = HttpSender> {
|
|||||||
fn search<'a>(&self, q: &'a str, resolve: bool) -> Result<SearchResult> {
|
fn search<'a>(&self, q: &'a str, resolve: bool) -> Result<SearchResult> {
|
||||||
unimplemented!("This method was not implemented");
|
unimplemented!("This method was not implemented");
|
||||||
}
|
}
|
||||||
|
/// GET /api/v2/search
|
||||||
|
fn search_v2<'a>(&self, q: &'a str, resolve: bool) -> Result<SearchResultV2> {
|
||||||
|
unimplemented!("This method was not implemented");
|
||||||
|
}
|
||||||
/// POST /api/v1/follows
|
/// POST /api/v1/follows
|
||||||
fn follows(&self, uri: Cow<'static, str>) -> Result<Account> {
|
fn follows(&self, uri: Cow<'static, str>) -> Result<Account> {
|
||||||
unimplemented!("This method was not implemented");
|
unimplemented!("This method was not implemented");
|
||||||
|
|||||||
Reference in New Issue
Block a user