change POST /search to GET /search
This commit is contained in:
@@ -17,6 +17,7 @@ reqwest = "0.8"
|
|||||||
serde = "1"
|
serde = "1"
|
||||||
serde_derive = "1"
|
serde_derive = "1"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
serde_urlencoded = "0.5.3"
|
||||||
url = "1"
|
url = "1"
|
||||||
try_from = "0.2.2"
|
try_from = "0.2.2"
|
||||||
toml = { version = "0.4.6", optional = true }
|
toml = { version = "0.4.6", optional = true }
|
||||||
|
|||||||
+2
-2
@@ -9,9 +9,9 @@ use std::error;
|
|||||||
fn main() -> Result<(), Box<error::Error>> {
|
fn main() -> Result<(), Box<error::Error>> {
|
||||||
let mastodon = register::get_mastodon_data()?;
|
let mastodon = register::get_mastodon_data()?;
|
||||||
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_accounts(&input, None, true)?;
|
let result = mastodon.search(&input, false)?;
|
||||||
|
|
||||||
println!("{:#?}", result.initial_items);
|
println!("{:#?}", result);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use std::{error, fmt, io::Error as IoError};
|
|||||||
|
|
||||||
use reqwest::{Error as HttpError, StatusCode};
|
use reqwest::{Error as HttpError, StatusCode};
|
||||||
use serde_json::Error as SerdeError;
|
use serde_json::Error as SerdeError;
|
||||||
|
use serde_urlencoded::ser::Error as UrlEncodedError;
|
||||||
#[cfg(feature = "toml")]
|
#[cfg(feature = "toml")]
|
||||||
use tomlcrate::de::Error as TomlDeError;
|
use tomlcrate::de::Error as TomlDeError;
|
||||||
#[cfg(feature = "toml")]
|
#[cfg(feature = "toml")]
|
||||||
@@ -20,6 +21,8 @@ pub enum Error {
|
|||||||
/// Error deserialising to json. Typically represents a breaking change in
|
/// Error deserialising to json. Typically represents a breaking change in
|
||||||
/// the Mastodon API
|
/// the Mastodon API
|
||||||
Serde(SerdeError),
|
Serde(SerdeError),
|
||||||
|
/// Error serializing to url-encoded string
|
||||||
|
UrlEncoded(UrlEncodedError),
|
||||||
/// Error encountered in the HTTP backend while requesting a route.
|
/// Error encountered in the HTTP backend while requesting a route.
|
||||||
Http(HttpError),
|
Http(HttpError),
|
||||||
/// Wrapper around the `std::io::Error` struct.
|
/// Wrapper around the `std::io::Error` struct.
|
||||||
@@ -64,6 +67,7 @@ impl error::Error for Error {
|
|||||||
.or(e.error.as_ref().map(|i| &**i))
|
.or(e.error.as_ref().map(|i| &**i))
|
||||||
.unwrap_or("Unknown API Error"),
|
.unwrap_or("Unknown API Error"),
|
||||||
Error::Serde(ref e) => e.description(),
|
Error::Serde(ref e) => e.description(),
|
||||||
|
Error::UrlEncoded(ref e) => e.description(),
|
||||||
Error::Http(ref e) => e.description(),
|
Error::Http(ref e) => e.description(),
|
||||||
Error::Io(ref e) => e.description(),
|
Error::Io(ref e) => e.description(),
|
||||||
Error::Url(ref e) => e.description(),
|
Error::Url(ref e) => e.description(),
|
||||||
@@ -110,6 +114,7 @@ from! {
|
|||||||
HttpError, Http,
|
HttpError, Http,
|
||||||
IoError, Io,
|
IoError, Io,
|
||||||
SerdeError, Serde,
|
SerdeError, Serde,
|
||||||
|
UrlEncodedError, UrlEncoded,
|
||||||
UrlError, Url,
|
UrlError, Url,
|
||||||
ApiError, Api,
|
ApiError, Api,
|
||||||
#[cfg(feature = "toml")] TomlSerError, TomlSer,
|
#[cfg(feature = "toml")] TomlSerError, TomlSer,
|
||||||
@@ -121,6 +126,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
use serde_urlencoded;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
macro_rules! assert_is {
|
macro_rules! assert_is {
|
||||||
@@ -153,6 +159,13 @@ mod tests {
|
|||||||
assert_is!(err, Error::Serde(..));
|
assert_is!(err, Error::Serde(..));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_url_encoded_error() {
|
||||||
|
let err: UrlEncodedError = serde_urlencoded::ser::Error::Custom("error".into());
|
||||||
|
let err: Error = Error::from(err);
|
||||||
|
assert_is!(err, Error::UrlEncoded(..));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_url_error() {
|
fn from_url_error() {
|
||||||
let err: UrlError = UrlError::EmptyHost;
|
let err: UrlError = UrlError::EmptyHost;
|
||||||
|
|||||||
+2
-1
@@ -49,6 +49,7 @@ extern crate serde_json;
|
|||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
extern crate reqwest;
|
extern crate reqwest;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
extern crate serde_urlencoded;
|
||||||
extern crate try_from;
|
extern crate try_from;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
|
|
||||||
@@ -185,7 +186,7 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> {
|
|||||||
(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,
|
||||||
(post (q: String, resolve: bool,)) search: "search" => SearchResult,
|
(get (q: &'a str, resolve: bool,)) search: "search" => SearchResult,
|
||||||
(post (uri: Cow<'static, str>,)) follows: "follows" => Account,
|
(post (uri: Cow<'static, str>,)) follows: "follows" => Account,
|
||||||
(post multipart (file: Cow<'static, str>,)) media: "media" => Attachment,
|
(post multipart (file: Cow<'static, str>,)) media: "media" => Attachment,
|
||||||
(post) clear_notifications: "notifications/clear" => Empty,
|
(post) clear_notifications: "notifications/clear" => Empty,
|
||||||
|
|||||||
@@ -94,6 +94,43 @@ macro_rules! route {
|
|||||||
route!{$($rest)*}
|
route!{$($rest)*}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
((get ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
|
doc_comment! {
|
||||||
|
concat!(
|
||||||
|
"Equivalent to `/api/v1/",
|
||||||
|
$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/v1/", $url, "?{}"), &qs);
|
||||||
|
|
||||||
|
Ok(self.get(self.route(&url))?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
route!{$($rest)*}
|
||||||
|
};
|
||||||
|
|
||||||
(($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!(
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ pub trait MastodonClient<H: HttpSend = HttpSender> {
|
|||||||
fn reject_follow_request(&self, id: &str) -> Result<Empty> {
|
fn reject_follow_request(&self, id: &str) -> Result<Empty> {
|
||||||
unimplemented!("This method was not implemented");
|
unimplemented!("This method was not implemented");
|
||||||
}
|
}
|
||||||
/// POST /api/v1/search
|
/// GET /api/v1/search
|
||||||
fn search(&self, q: String, 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");
|
||||||
}
|
}
|
||||||
/// POST /api/v1/follows
|
/// POST /api/v1/follows
|
||||||
|
|||||||
Reference in New Issue
Block a user