Skip to content

Commit 4b51492

Browse files
committed
implement start_analysis to hit the stable api's analysis endpoint
1 parent ac406d8 commit 4b51492

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

src/main.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ fn main() {
5151
}
5252

5353
println!();
54-
match client.test_upload().expect_success().expect_json::<ApiAnalysisJobResponse>() {
55-
Ok(response) => println!("wow a success response: {:?}", response),
56-
Err(e) => println!("Error uploading file: {:?}", e),
54+
let analysis_job_result = client.start_analysis(4, vec![
55+
Path::new("D:/CodeDx/data-sets/webgoat eval/bin-webgoat-r437.zip"),
56+
Path::new("D:/CodeDx/data-sets/webgoat eval/src-webgoat-r437.zip")
57+
]);
58+
match analysis_job_result {
59+
Ok(response) => println!("Started analysis: {:?}", response),
60+
Err(e) => println!("Couldn't start analysis: {:?}", e),
5761
}
5862

5963
println!();
@@ -202,18 +206,20 @@ impl ApiClient {
202206
.expect_json()
203207
}
204208

205-
fn test_upload(&self) -> ApiResponse {
206-
let file_path = Path::new("D:/CodeDx/data-sets/webgoat-r437/src-r437.zip");
207-
// let file_path = Path::new("./Cargo.toml");
208-
let form = reqwest::multipart::Form::new()
209-
.file("file1", file_path)
210-
.map_err(|e| ApiError::IO(e));
211-
212-
let foo = form.and_then(|form| {
213-
self.api_post(&["api", "projects", "4", "analysis"], form).get()
214-
});
209+
fn start_analysis(&self, project_id: u32, files: Vec<&Path>) -> ApiResult<ApiAnalysisJobResponse> {
210+
let form= files
211+
.iter()
212+
.enumerate()
213+
.fold(Ok(reqwest::multipart::Form::new()), |maybe_form, (index, file)| {
214+
maybe_form.and_then(|form| form.file(format!("file{}", index), file))
215+
})
216+
.map_err(ApiError::from);
215217

216-
ApiResponse::from(foo)
218+
form.and_then(|form| {
219+
self.api_post(&["api", "projects", &project_id.to_string(), "analysis"], form)
220+
.expect_success()
221+
.expect_json::<ApiAnalysisJobResponse>()
222+
})
217223
}
218224

219225
fn api_get(&self, path_segments: &[&str]) -> ApiResponse {

0 commit comments

Comments
 (0)