[fractal] API: remove unused query macros and json_q
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] API: remove unused query macros and json_q
- Date: Thu, 2 Apr 2020 10:39:46 +0000 (UTC)
commit 94632ae16360a848f922c335a3af49f195a691a7
Author: Alejandro DomÃnguez <adomu net-c com>
Date: Tue Mar 10 09:42:03 2020 +0100
API: remove unused query macros and json_q
fractal-matrix-api/src/util.rs | 83 ------------------------------------------
1 file changed, 83 deletions(-)
---
diff --git a/fractal-matrix-api/src/util.rs b/fractal-matrix-api/src/util.rs
index 57f3280d..d90b2f06 100644
--- a/fractal-matrix-api/src/util.rs
+++ b/fractal-matrix-api/src/util.rs
@@ -27,8 +27,6 @@ use crate::r0::profile::get_profile::request as get_profile;
use crate::r0::profile::get_profile::Response as GetProfileResponse;
use crate::r0::AccessToken;
-use reqwest::header::CONTENT_LENGTH;
-
use crate::globals;
lazy_static! {
@@ -117,44 +115,6 @@ macro_rules! bkerror2 {
};
}
-#[macro_export]
-macro_rules! get {
- ($($args: expr),+) => {
- query!("get", $($args),+)
- };
-}
-
-#[macro_export]
-macro_rules! post {
- ($($args: expr),+) => {
- query!("post", $($args),+)
- };
-}
-
-#[macro_export]
-macro_rules! put {
- ($($args: expr),+) => {
- query!("put", $($args),+)
- };
-}
-
-#[macro_export]
-macro_rules! query {
- ($method: expr, $url: expr, $attrs: expr, $okcb: expr, $errcb: expr) => {
- thread::spawn(move || {
- let js = json_q($method, $url, $attrs);
-
- match js {
- Ok(r) => $okcb(r),
- Err(err) => $errcb(err),
- }
- });
- };
- ($method: expr, $url: expr, $okcb: expr, $errcb: expr) => {
- query!($method, $url, &json!(null), $okcb, $errcb)
- };
-}
-
pub enum ContentType {
Download,
Thumbnail(i32, i32),
@@ -273,49 +233,6 @@ pub fn download_file(url: Url, fname: String, dest: Option<&str>) -> Result<Stri
}
}
-pub fn json_q(method: &str, url: Url, attrs: &JsonValue) -> Result<JsonValue, Error> {
- let mut conn = match method {
- "post" => HTTP_CLIENT.get_client()?.post(url),
- "put" => HTTP_CLIENT.get_client()?.put(url),
- "delete" => HTTP_CLIENT.get_client()?.delete(url),
- _ => HTTP_CLIENT.get_client()?.get(url),
- };
-
- if !attrs.is_null() {
- conn = conn.json(attrs);
- } else if method == "post" {
- conn = conn.header(CONTENT_LENGTH, 0);
- }
-
- let res = conn.send()?;
-
- //let mut content = String::new();
- //res.read_to_string(&mut content);
- //cb(content);
-
- if !res.status().is_success() {
- return match res.json() {
- Ok(js) => Err(Error::MatrixError(js)),
- Err(err) => Err(Error::ReqwestError(err)),
- };
- }
-
- let json: Result<JsonValue, reqwest::Error> = res.json();
- match json {
- Ok(js) => {
- let js2 = js.clone();
- if let Some(error) = js.as_object() {
- if error.contains_key("errcode") {
- error!("{:#?}", js2);
- return Err(Error::MatrixError(js2));
- }
- }
- Ok(js)
- }
- Err(_) => Err(Error::BackendError),
- }
-}
-
pub fn get_user_avatar(base: &Url, user_id: &UserId) -> Result<(String, String), Error> {
let response = get_profile(base.clone(), user_id)
.map_err::<Error, _>(Into::into)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]