summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjakka <jakka@jakka.su>2025-09-17 23:08:01 +0300
committerjakka <jakka@jakka.su>2025-09-17 23:08:01 +0300
commit770f10da05c2a85f5b6934c9062fd7548b0c1e5b (patch)
treecd17e61ff3f7d9d3fabdb337d1f8fc873102d749 /src
parent2cea08a292a75abce7130c1d8522de7cb9739cb6 (diff)
moved more single-field json objects into reponse object
Diffstat (limited to 'src')
-rw-r--r--src/client.rs20
-rw-r--r--src/types.rs18
2 files changed, 16 insertions, 22 deletions
diff --git a/src/client.rs b/src/client.rs
index 28e3544..0b3f1c7 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -2,6 +2,7 @@ use std::{collections::HashMap, path::PathBuf};
use async_trait::async_trait;
use reqwest::{Body, RequestBuilder};
+use serde::Deserialize;
use tokio_util::codec::{BytesCodec, FramedRead};
use crate::{traits::*, types::*};
@@ -56,6 +57,17 @@ impl HydrusClient {
}
}
+#[derive(Deserialize, Debug)]
+struct HydrusResponse<T> {
+ #[serde(
+ alias = "service",
+ alias = "services",
+ alias = "access_key",
+ alias = "session_key"
+ )]
+ body: T,
+}
+
#[async_trait]
impl AccessManagement for HydrusClient {
async fn request_new_permissions(
@@ -81,9 +93,9 @@ impl AccessManagement for HydrusClient {
.get(req_url)
.send()
.await?
- .json::<AccessKey>()
+ .json::<HydrusResponse<String>>()
.await?
- .access_key)
+ .body)
}
async fn get_session_key(&self) -> Result<String> {
@@ -99,9 +111,9 @@ impl AccessManagement for HydrusClient {
Ok(request
.send()
.await?
- .json::<SessionKey>()
+ .json::<HydrusResponse<String>>()
.await?
- .session_key)
+ .body)
}
async fn verify_access_key(&self, key: &str) -> Result<KeyInfo> {
diff --git a/src/types.rs b/src/types.rs
index 8ea8350..e5e0606 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -32,14 +32,6 @@ impl From<reqwest::Error> for HydrusError {
}
}
-#[derive(Deserialize, Debug)]
-pub struct HydrusResponse<T> {
- #[serde(alias = "service", alias = "services")]
- pub body: T,
- pub version: u64,
- pub hydrus_version: u64,
-}
-
#[derive(PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum HydrusPermissions {
@@ -61,16 +53,6 @@ pub enum HydrusPermissions {
}
#[derive(Deserialize, Debug)]
-pub struct AccessKey {
- pub access_key: String,
-}
-
-#[derive(Deserialize, Debug)]
-pub struct SessionKey {
- pub session_key: String,
-}
-
-#[derive(Deserialize, Debug)]
pub struct KeyInfo {
pub name: String,
pub permits_everything: bool,