Skip to content

Commit

Permalink
adding fetch_github_list function
Browse files Browse the repository at this point in the history
  • Loading branch information
robinsteuteville committed Jan 3, 2024
1 parent 1ff4316 commit 474df42
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions rust/fastsim-core/src/vehicle_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,33 @@ pub fn import_and_save_all_vehicles(
Ok(())
}

#[derive(Deserialize)]
pub struct GitVehicleInfo {
pub name: String,
pub path: String,
pub sha: String,
pub size: i64,
pub url: String,
pub html_url: String,
pub git_url: String,
pub download_url: String,
#[serde(rename = "type")]
pub url_type: String,
pub links: Vec<String>,
}

const VEHICLE_REPO_LIST_URL: &'static str = &"https://api.github.com/repos/NREL/fastsim-vehicles/contents/public";

pub fn fetch_github_list() -> anyhow::Result<Vec<String>> {
let response = ureq::get(VEHICLE_REPO_LIST_URL).call()?.into_reader();
let github_list: HashMap<i64, GitVehicleInfo> = serde_json::from_reader(response).with_context(||"Cannot parse github vehicle list.")?;
let mut vehicle_name_list: Vec<String> = Vec::new();
for (key, value) in github_list.iter() {
vehicle_name_list.push(value.name.to_owned())
}
Ok(vehicle_name_list)
}

#[cfg(test)]
mod vehicle_utils_tests {
use super::*;
Expand Down

0 comments on commit 474df42

Please sign in to comment.