2023-05-22 00:43:26 +02:00
|
|
|
use serde::{Serialize, Deserialize};
|
|
|
|
|
2023-06-07 15:31:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
2023-05-22 00:43:26 +02:00
|
|
|
pub struct PostWomanCollection {
|
|
|
|
pub variables: Vec<String>, // TODO these sure aren't just strings for sure...
|
|
|
|
pub info: CollectionInfo,
|
|
|
|
pub item: Vec<Item>,
|
|
|
|
}
|
|
|
|
|
2023-06-07 15:31:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
2023-05-22 00:43:26 +02:00
|
|
|
pub struct CollectionInfo {
|
|
|
|
pub name: String,
|
2023-05-26 15:26:55 +02:00
|
|
|
pub description: Option<String>,
|
2023-05-22 00:43:26 +02:00
|
|
|
}
|
|
|
|
|
2023-06-07 15:31:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
2023-05-22 00:43:26 +02:00
|
|
|
pub struct Item {
|
|
|
|
pub name: String,
|
|
|
|
pub event: Option<Vec<Event>>,
|
2023-05-26 15:26:55 +02:00
|
|
|
pub request: Option<Request>,
|
2023-06-07 15:31:22 +02:00
|
|
|
pub response: Option<Vec<Response>>,
|
2023-05-26 15:26:55 +02:00
|
|
|
pub item: Option<Vec<Item>>,
|
2023-05-22 00:43:26 +02:00
|
|
|
}
|
|
|
|
|
2023-06-07 15:31:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
|
|
pub struct Response {
|
|
|
|
pub name: String,
|
|
|
|
pub code: u16,
|
|
|
|
pub header: String,
|
|
|
|
// pub cookie: Vec<String>,
|
|
|
|
pub body: Body,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
2023-05-22 00:43:26 +02:00
|
|
|
pub struct Event {
|
|
|
|
pub listen: String,
|
|
|
|
pub script: Script,
|
|
|
|
}
|
|
|
|
|
2023-06-07 15:31:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
2023-05-22 00:43:26 +02:00
|
|
|
pub struct Script {
|
|
|
|
pub r#type: String,
|
|
|
|
pub exec: Vec<String>,
|
|
|
|
}
|
|
|
|
|
2023-06-07 15:31:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
|
|
#[serde(untagged)]
|
|
|
|
pub enum Request {
|
|
|
|
Object {
|
|
|
|
url: Url,
|
|
|
|
method: String,
|
|
|
|
header: Option<Vec<Header>>,
|
|
|
|
body: Option<Body>,
|
|
|
|
description: Option<String>,
|
|
|
|
},
|
|
|
|
String(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToString for Request {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
match self {
|
|
|
|
Self::String(x) => x.clone(),
|
|
|
|
Self::Object {
|
|
|
|
url,
|
|
|
|
method: _, header: _, body: _, description: _
|
|
|
|
} => url.to_string(),
|
|
|
|
}
|
|
|
|
}
|
2023-05-22 00:43:26 +02:00
|
|
|
}
|
|
|
|
|
2023-06-07 15:31:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
2023-05-22 00:43:26 +02:00
|
|
|
pub struct Header {
|
|
|
|
pub key: String,
|
|
|
|
pub value: String,
|
|
|
|
}
|
|
|
|
|
2023-06-07 15:31:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
2023-05-22 00:43:26 +02:00
|
|
|
pub struct Query {
|
|
|
|
pub key: String,
|
|
|
|
pub value: String,
|
|
|
|
pub equals: bool,
|
|
|
|
pub description: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToString for Query {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
format!("{}={}", self.key, self.value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-07 15:31:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
2023-05-22 00:43:26 +02:00
|
|
|
#[serde(untagged)]
|
|
|
|
pub enum Body {
|
2023-06-07 15:31:22 +02:00
|
|
|
Object(serde_json::Value),
|
|
|
|
String(String),
|
2023-05-22 00:43:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ToString for Body {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
match self {
|
2023-06-07 15:31:22 +02:00
|
|
|
Body::Object(v) => serde_json::to_string(v).unwrap(),
|
|
|
|
Body::String(s) => s.clone(),
|
2023-05-22 00:43:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-07 15:31:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
2023-05-22 00:43:26 +02:00
|
|
|
#[serde(untagged)]
|
|
|
|
pub enum Url {
|
|
|
|
Object {
|
|
|
|
raw: Option<String>,
|
|
|
|
protocol: String,
|
|
|
|
host: Vec<String>,
|
|
|
|
path: Vec<String>,
|
|
|
|
query: Option<Vec<Query>>,
|
|
|
|
variable: Option<Vec<String>>, // TODO surely aren't just strings
|
|
|
|
},
|
|
|
|
String(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToString for Url {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
match self {
|
|
|
|
Url::String(s) => s.clone(),
|
|
|
|
Url::Object {
|
|
|
|
raw, protocol,
|
|
|
|
host,path, query,
|
|
|
|
variable: _
|
|
|
|
} => {
|
|
|
|
match &raw {
|
|
|
|
Some(s) => s.clone(),
|
|
|
|
None => {
|
|
|
|
let mut url = String::new();
|
|
|
|
url.push_str(&protocol);
|
|
|
|
url.push_str("://");
|
|
|
|
url.push_str(&host.join("."));
|
|
|
|
url.push_str("/");
|
|
|
|
url.push_str(&path.join("/"));
|
|
|
|
|
|
|
|
if let Some(query) = &query {
|
|
|
|
url.push_str("?");
|
|
|
|
let q : Vec<String> = query.iter().map(|x| x.to_string()).collect();
|
|
|
|
url.push_str(&q.join("&"));
|
|
|
|
}
|
|
|
|
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// barebones custom error
|
|
|
|
|
2023-06-07 15:31:22 +02:00
|
|
|
// #[derive(Debug, Clone)]
|
2023-05-22 00:43:26 +02:00
|
|
|
// pub struct PostWomanError {
|
|
|
|
// msg : String,
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// impl PostWomanError {
|
|
|
|
// pub fn throw(msg: impl ToString) -> Box<dyn std::error::Error> {
|
|
|
|
// Box::new(
|
|
|
|
// PostWomanError {
|
|
|
|
// msg: msg.to_string(),
|
|
|
|
// }
|
|
|
|
// )
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// impl std::fmt::Display for PostWomanError {
|
|
|
|
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
// write!(f, "PostWomanError({})", self.msg)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// impl std::error::Error for PostWomanError {}
|