summaryrefslogtreecommitdiff
path: root/src/apis
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2022-11-04 23:41:21 +0100
committerfxqnlr <[email protected]>2022-11-04 23:41:21 +0100
commit5d50f446a1a4612c0c931bdbc61f945760392f29 (patch)
tree44414994e19b41979a8a939b120ada0d1aa8a13a /src/apis
parent96cc5257de09682df345e768dc2a91303f9b36c9 (diff)
downloadmodlist-5d50f446a1a4612c0c931bdbc61f945760392f29.tar
modlist-5d50f446a1a4612c0c931bdbc61f945760392f29.tar.gz
modlist-5d50f446a1a4612c0c931bdbc61f945760392f29.zip
"finished" update, added some tests
Diffstat (limited to 'src/apis')
-rw-r--r--src/apis/modrinth.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs
index 0c3eca5..c71b47f 100644
--- a/src/apis/modrinth.rs
+++ b/src/apis/modrinth.rs
@@ -1,3 +1,5 @@
1use std::io::{Error, ErrorKind};
2use chrono::{DateTime, FixedOffset};
1use serde::Deserialize; 3use serde::Deserialize;
2 4
3use crate::{Modloader, List}; 5use crate::{Modloader, List};
@@ -153,3 +155,24 @@ pub async fn versions(api: String, id: String, list: List) -> Vec<Version> {
153 155
154 serde_json::from_slice(&data.await.unwrap()).unwrap() 156 serde_json::from_slice(&data.await.unwrap()).unwrap()
155} 157}
158
159pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> {
160 match versions.len() {
161 0 => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_VERSIONS_AVAILABLE"))),
162 //TODO compare publish dates
163 1.. => {
164 let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![];
165 for ver in versions {
166 let stamp = DateTime::parse_from_rfc3339(&ver.date_published)?;
167 times.push((ver.id, stamp))
168 }
169 dbg!(&times);
170 times.sort_by_key(|t| t.1);
171 times.reverse();
172 dbg!(&times);
173 println!("CW: {}", times[0].0);
174 Ok(times[0].0.to_string())
175 },
176 _ => panic!("available_versions should never be negative"),
177 }
178}