forked from MightyPork/elefren-fork
change POST /search to GET /search
This commit is contained in:
@@ -2,6 +2,7 @@ use std::{error, fmt, io::Error as IoError};
|
||||
|
||||
use reqwest::{Error as HttpError, StatusCode};
|
||||
use serde_json::Error as SerdeError;
|
||||
use serde_urlencoded::ser::Error as UrlEncodedError;
|
||||
#[cfg(feature = "toml")]
|
||||
use tomlcrate::de::Error as TomlDeError;
|
||||
#[cfg(feature = "toml")]
|
||||
@@ -20,6 +21,8 @@ pub enum Error {
|
||||
/// Error deserialising to json. Typically represents a breaking change in
|
||||
/// the Mastodon API
|
||||
Serde(SerdeError),
|
||||
/// Error serializing to url-encoded string
|
||||
UrlEncoded(UrlEncodedError),
|
||||
/// Error encountered in the HTTP backend while requesting a route.
|
||||
Http(HttpError),
|
||||
/// Wrapper around the `std::io::Error` struct.
|
||||
@@ -64,6 +67,7 @@ impl error::Error for Error {
|
||||
.or(e.error.as_ref().map(|i| &**i))
|
||||
.unwrap_or("Unknown API Error"),
|
||||
Error::Serde(ref e) => e.description(),
|
||||
Error::UrlEncoded(ref e) => e.description(),
|
||||
Error::Http(ref e) => e.description(),
|
||||
Error::Io(ref e) => e.description(),
|
||||
Error::Url(ref e) => e.description(),
|
||||
@@ -110,6 +114,7 @@ from! {
|
||||
HttpError, Http,
|
||||
IoError, Io,
|
||||
SerdeError, Serde,
|
||||
UrlEncodedError, UrlEncoded,
|
||||
UrlError, Url,
|
||||
ApiError, Api,
|
||||
#[cfg(feature = "toml")] TomlSerError, TomlSer,
|
||||
@@ -121,6 +126,7 @@ mod tests {
|
||||
use super::*;
|
||||
use reqwest;
|
||||
use serde_json;
|
||||
use serde_urlencoded;
|
||||
use std::io;
|
||||
|
||||
macro_rules! assert_is {
|
||||
@@ -153,6 +159,13 @@ mod tests {
|
||||
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]
|
||||
fn from_url_error() {
|
||||
let err: UrlError = UrlError::EmptyHost;
|
||||
|
||||
+2
-1
@@ -49,6 +49,7 @@ extern crate serde_json;
|
||||
extern crate chrono;
|
||||
extern crate reqwest;
|
||||
extern crate serde;
|
||||
extern crate serde_urlencoded;
|
||||
extern crate try_from;
|
||||
extern crate url;
|
||||
|
||||
@@ -185,7 +186,7 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> {
|
||||
(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,
|
||||
(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 multipart (file: Cow<'static, str>,)) media: "media" => Attachment,
|
||||
(post) clear_notifications: "notifications/clear" => Empty,
|
||||
|
||||
@@ -94,6 +94,43 @@ macro_rules! route {
|
||||
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)*) => {
|
||||
doc_comment! {
|
||||
concat!(
|
||||
|
||||
@@ -91,8 +91,8 @@ pub trait MastodonClient<H: HttpSend = HttpSender> {
|
||||
fn reject_follow_request(&self, id: &str) -> Result<Empty> {
|
||||
unimplemented!("This method was not implemented");
|
||||
}
|
||||
/// POST /api/v1/search
|
||||
fn search(&self, q: String, resolve: bool) -> Result<SearchResult> {
|
||||
/// GET /api/v1/search
|
||||
fn search<'a>(&self, q: &'a str, resolve: bool) -> Result<SearchResult> {
|
||||
unimplemented!("This method was not implemented");
|
||||
}
|
||||
/// POST /api/v1/follows
|
||||
|
||||
Reference in New Issue
Block a user