diff options
author | fxqnlr <[email protected]> | 2024-09-04 11:12:04 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-04 11:12:04 +0200 |
commit | 6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 (patch) | |
tree | ae04cf34582f57699d12ac7b5b486ab065bf8d19 /src/apis | |
parent | f5e070cdf6628a5ebd981d373929802317104e24 (diff) | |
download | modlist-6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043.tar modlist-6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043.tar.gz modlist-6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043.zip |
do nearly anything to shut clippy up
Diffstat (limited to 'src/apis')
-rw-r--r-- | src/apis/modrinth.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 5366f3d..75e65e6 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs | |||
@@ -3,7 +3,7 @@ use reqwest::Client; | |||
3 | use serde::{Deserialize, Serialize}; | 3 | use serde::{Deserialize, Serialize}; |
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | error::{ErrorType, MLError, MLE}, | 6 | error::{EType, MLErr, MLE}, |
7 | List, | 7 | List, |
8 | }; | 8 | }; |
9 | 9 | ||
@@ -130,6 +130,8 @@ pub enum GameVersionType { | |||
130 | beta, | 130 | beta, |
131 | } | 131 | } |
132 | 132 | ||
133 | /// # Errors | ||
134 | /// # Panics | ||
133 | async fn get( | 135 | async fn get( |
134 | api: &str, | 136 | api: &str, |
135 | path: &str, | 137 | path: &str, |
@@ -153,6 +155,8 @@ async fn get( | |||
153 | Ok(data) | 155 | Ok(data) |
154 | } | 156 | } |
155 | 157 | ||
158 | /// # Errors | ||
159 | /// # Panics | ||
156 | pub async fn project(api: &str, name: &str) -> Project { | 160 | pub async fn project(api: &str, name: &str) -> Project { |
157 | let url = format!("project/{name}"); | 161 | let url = format!("project/{name}"); |
158 | let data = get(api, &url).await.unwrap().unwrap(); | 162 | let data = get(api, &url).await.unwrap().unwrap(); |
@@ -160,6 +164,8 @@ pub async fn project(api: &str, name: &str) -> Project { | |||
160 | serde_json::from_slice(&data).unwrap() | 164 | serde_json::from_slice(&data).unwrap() |
161 | } | 165 | } |
162 | 166 | ||
167 | /// # Errors | ||
168 | /// # Panics | ||
163 | pub async fn projects(api: &str, ids: Vec<String>) -> Vec<Project> { | 169 | pub async fn projects(api: &str, ids: Vec<String>) -> Vec<Project> { |
164 | let all = ids.join(r#"",""#); | 170 | let all = ids.join(r#"",""#); |
165 | let url = format!(r#"projects?ids=["{all}"]"#); | 171 | let url = format!(r#"projects?ids=["{all}"]"#); |
@@ -170,6 +176,8 @@ pub async fn projects(api: &str, ids: Vec<String>) -> Vec<Project> { | |||
170 | } | 176 | } |
171 | 177 | ||
172 | ///Get applicable versions from `mod_id` with list context | 178 | ///Get applicable versions from `mod_id` with list context |
179 | /// # Errors | ||
180 | /// # Panics | ||
173 | pub async fn versions(api: &str, id: String, list: List) -> Vec<Version> { | 181 | pub async fn versions(api: &str, id: String, list: List) -> Vec<Version> { |
174 | let url = format!( | 182 | let url = format!( |
175 | r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, | 183 | r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, |
@@ -185,6 +193,8 @@ pub async fn versions(api: &str, id: String, list: List) -> Vec<Version> { | |||
185 | } | 193 | } |
186 | 194 | ||
187 | ///Get version with the version ids | 195 | ///Get version with the version ids |
196 | /// # Errors | ||
197 | /// # Panics | ||
188 | pub async fn get_raw_versions( | 198 | pub async fn get_raw_versions( |
189 | api: &str, | 199 | api: &str, |
190 | versions: Vec<String>, | 200 | versions: Vec<String>, |
@@ -196,9 +206,10 @@ pub async fn get_raw_versions( | |||
196 | serde_json::from_slice(&data).unwrap() | 206 | serde_json::from_slice(&data).unwrap() |
197 | } | 207 | } |
198 | 208 | ||
209 | /// # Errors | ||
199 | pub fn extract_current_version(versions: Vec<Version>) -> MLE<String> { | 210 | pub fn extract_current_version(versions: Vec<Version>) -> MLE<String> { |
200 | match versions.len() { | 211 | match versions.len() { |
201 | 0 => Err(MLError::new(ErrorType::ModError, "NO_VERSIONS_AVAILABLE")), | 212 | 0 => Err(MLErr::new(EType::ModError, "NO_VERSIONS_AVAILABLE")), |
202 | 1.. => { | 213 | 1.. => { |
203 | let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![]; | 214 | let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![]; |
204 | for ver in versions { | 215 | for ver in versions { |
@@ -209,10 +220,11 @@ pub fn extract_current_version(versions: Vec<Version>) -> MLE<String> { | |||
209 | times.reverse(); | 220 | times.reverse(); |
210 | Ok(times[0].0.to_string()) | 221 | Ok(times[0].0.to_string()) |
211 | } | 222 | } |
212 | _ => panic!("available_versions should never be negative"), | ||
213 | } | 223 | } |
214 | } | 224 | } |
215 | 225 | ||
226 | /// # Errors | ||
227 | /// # Panics | ||
216 | pub async fn get_game_versions() -> Vec<GameVersion> { | 228 | pub async fn get_game_versions() -> Vec<GameVersion> { |
217 | let data = get("https://api.modrinth.com/v2/", "tag/game_version") | 229 | let data = get("https://api.modrinth.com/v2/", "tag/game_version") |
218 | .await | 230 | .await |