chore: modularized it better
This commit is contained in:
parent
d7bc0fd914
commit
3a619ecfb0
4 changed files with 77 additions and 53 deletions
|
@ -1,5 +1,4 @@
|
|||
// mod proto;
|
||||
// mod model;
|
||||
mod model;
|
||||
mod collector;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
|
46
src/model/collector.rs
Normal file
46
src/model/collector.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use postman_collection::{PostmanCollection, v1_0_0, v2_0_0, v2_1_0};
|
||||
|
||||
pub trait CollectRequests {
|
||||
fn from_self(&self) -> Vec<reqwest::Request>;
|
||||
}
|
||||
|
||||
impl CollectRequests for v1_0_0::Spec {
|
||||
fn from_self(&self) -> Vec<reqwest::Request> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl CollectRequests for v2_0_0::Spec {
|
||||
fn from_self(&self) -> &reqwest::Request {
|
||||
let mut requests = Vec::new();
|
||||
if let Some(r) = root.request {
|
||||
let clazz = match r {
|
||||
v2_0_0::RequestUnion::String(url) => v2_0_0::RequestClass {
|
||||
auth: None,
|
||||
body: None,
|
||||
certificate: None,
|
||||
description: None,
|
||||
header: None,
|
||||
method: None,
|
||||
proxy: None,
|
||||
url: Some(v2_0_0::Url::String(url)),
|
||||
},
|
||||
v2_0_0::RequestUnion::RequestClass(r) => r,
|
||||
};
|
||||
requests.push(clazz.make_request());
|
||||
}
|
||||
if let Some(sub) = root.item {
|
||||
for item in sub {
|
||||
requests.append(&mut self.from_self());
|
||||
}
|
||||
|
||||
}
|
||||
requests
|
||||
}
|
||||
}
|
||||
|
||||
impl CollectRequests for v2_1_0::Spec {
|
||||
fn from_self(&self) -> Vec<reqwest::Request> {
|
||||
todo!()
|
||||
}
|
||||
}
|
|
@ -1,5 +1,10 @@
|
|||
mod request;
|
||||
mod collector;
|
||||
|
||||
use postman_collection::{PostmanCollection, v1_0_0, v2_0_0, v2_1_0};
|
||||
|
||||
use self::collector::CollectRequests;
|
||||
|
||||
pub struct PostWomanCollection {
|
||||
collection: PostmanCollection
|
||||
}
|
||||
|
@ -39,66 +44,17 @@ impl PostWomanCollection {
|
|||
PostmanCollection::V2_0_0(spec) => {
|
||||
let mut out = Vec::new();
|
||||
for item in spec.item {
|
||||
out.append(&mut collect_requests_2_0_0_r(&item));
|
||||
out.append(&mut spec.from_self());
|
||||
}
|
||||
out
|
||||
},
|
||||
PostmanCollection::V2_1_0(spec) => {
|
||||
let mut out = Vec::new();
|
||||
for item in spec.item {
|
||||
out.append(&mut collect_requests_2_1_0_r(&item));
|
||||
out.append(&mut spec.from_self());
|
||||
}
|
||||
out
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collect_requests_1_0_0_r(root: &v1_0_0::Spec) -> Vec<reqwest::Request> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub trait IntoRequest {
|
||||
fn make_request(&self) -> reqwest::Request;
|
||||
}
|
||||
|
||||
impl IntoRequest for v2_0_0::RequestClass {
|
||||
fn make_request(&self) -> reqwest::Request {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CollectRequests {
|
||||
fn from_self(&self) -> &reqwest::Request;
|
||||
}
|
||||
|
||||
pub fn collect_requests_2_0_0_r(root: &v2_0_0::Items) -> Vec<reqwest::Request> {
|
||||
let mut requests = Vec::new();
|
||||
if let Some(r) = root.request {
|
||||
let clazz = match r {
|
||||
v2_0_0::RequestUnion::String(url) => v2_0_0::RequestClass {
|
||||
auth: None,
|
||||
body: None,
|
||||
certificate: None,
|
||||
description: None,
|
||||
header: None,
|
||||
method: None,
|
||||
proxy: None,
|
||||
url: Some(v2_0_0::Url::String(url)),
|
||||
},
|
||||
v2_0_0::RequestUnion::RequestClass(r) => r,
|
||||
};
|
||||
requests.push(clazz.make_request());
|
||||
}
|
||||
if let Some(sub) = root.item {
|
||||
for item in sub {
|
||||
requests.append(&mut collect_requests_2_0_0_r(&item));
|
||||
}
|
||||
|
||||
}
|
||||
requests
|
||||
}
|
||||
|
||||
pub fn collect_requests_2_1_0_r(root: &v2_1_0::Items) -> Vec<reqwest::Request> {
|
||||
todo!()
|
||||
}
|
23
src/model/request.rs
Normal file
23
src/model/request.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use postman_collection::{PostmanCollection, v1_0_0, v2_0_0, v2_1_0};
|
||||
|
||||
pub trait IntoRequest {
|
||||
fn make_request(&self) -> reqwest::Request;
|
||||
}
|
||||
|
||||
impl IntoRequest for v2_0_0::RequestClass {
|
||||
fn make_request(&self) -> reqwest::Request {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoRequest for v2_1_0::RequestClass {
|
||||
fn make_request(&self) -> reqwest::Request {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoRequest for v1_0_0::RequestClass {
|
||||
fn make_request(&self) -> reqwest::Request {
|
||||
todo!()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue