shrupl/src/sharry/api.rs

54 lines
1.2 KiB
Rust
Raw Normal View History

2025-05-22 17:34:44 +00:00
use log::debug;
use serde::{Deserialize, Serialize};
#[derive(Debug)]
pub struct SharryAPI {
protocol: String,
base_url: String,
}
impl SharryAPI {
pub fn new(protocol: Option<&str>, base_url: &str) -> Self {
Self {
protocol: protocol.unwrap_or("https").into(),
base_url: base_url.into(),
}
}
pub fn get_uri(&self, endpoint: &str) -> String {
let uri = format!("{}://{}/api/v2/{}", self.protocol, self.base_url, endpoint);
debug!("uri: {:?}", uri);
uri
}
}
#[derive(Serialize)]
#[allow(non_snake_case)]
pub struct NewShareRequest<'t> {
name: Option<&'t str>,
validity: u32,
description: &'t str,
maxViews: u32,
password: Option<&'t str>,
}
impl<'t> NewShareRequest<'t> {
pub fn new(name: Option<&'t str>, description: &'t str, max_views: u32) -> Self {
Self {
name: name,
validity: 0,
description: description,
maxViews: max_views,
password: None,
}
}
}
#[derive(Deserialize, Debug)]
pub struct NewShareResponse {
pub success: bool,
pub message: String,
pub id: String,
}