use serde::Serialize;
use std::path::Path;
#[derive(Default, Serialize)]
pub struct UploadRequest<'a> {
pub access_token: &'a str,
pub url: Option<&'a str>,
pub project_id: Option<&'a str>,
pub name: Option<&'a str>,
pub description: Option<&'a str>,
pub contact_id: Option<&'a str>,
}
#[derive(Default, Clone)]
pub(crate) struct UploadUrlRequest<'a> {
pub url: &'a str,
pub project_id: Option<&'a str>,
pub name: Option<&'a str>,
pub description: Option<&'a str>,
pub contact_id: Option<&'a str>,
}
#[allow(unused)]
#[derive(Clone)]
pub(crate) struct UploadFileRequest<'a, P: AsRef<Path>> {
pub file_path: P,
pub project_id: Option<&'a str>,
pub name: Option<&'a str>,
pub description: Option<&'a str>,
pub contact_id: Option<&'a str>,
}
impl<'a, P: AsRef<Path>> UploadFileRequest<'a, P> {
#[allow(unused)]
pub(crate) fn new(file_path: P) -> Self {
Self {
file_path,
project_id: None,
name: None,
description: None,
contact_id: None,
}
}
}
#[allow(unused)]
#[derive(Clone)]
pub(crate) struct UploadStreamRequest<'a> {
pub file_name: &'a str,
pub project_id: Option<&'a str>,
pub name: Option<&'a str>,
pub description: Option<&'a str>,
pub contact_id: Option<&'a str>,
}
impl<'a> UploadStreamRequest<'a> {
#[allow(unused)]
pub(crate) fn new(file_path: &'a str) -> Self {
Self {
file_name: file_path,
project_id: None,
name: None,
description: None,
contact_id: None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use serde_urlencoded::to_string;
#[test]
fn test_it_works() {
let req = UploadRequest {
access_token: "abc123",
url: None,
project_id: None,
name: None,
description: None,
contact_id: None,
};
assert_eq!(to_string(req).unwrap(), "access_token=abc123");
}
#[test]
fn test_it_works_with_other_params() {
let req = UploadRequest {
access_token: "xyz123",
url: Some("https://test-url.com/my/path?key=\"hello world!@#$?%&\"&value="),
project_id: Some("abc321"),
name: None,
description: None,
contact_id: Some("my contact <abc@xyz.org>"),
};
assert_eq!(to_string(req).unwrap(), "access_token=xyz123&url=https%3A%2F%2Ftest-url.com%2Fmy%2Fpath%3Fkey%3D%22hello+world%21%40%23%24%3F%25%26%22%26value%3D&project_id=abc321&contact_id=my+contact+%3Cabc%40xyz.org%3E");
}
}