Skip to content

Commit bbadaef

Browse files
revenge pt.6
1 parent 53ba815 commit bbadaef

10 files changed

Lines changed: 36 additions & 44 deletions

File tree

inventium/src/curse/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Curse {
3535
}
3636

3737
async fn post<T: DeserializeOwned, B: Serialize>(&self, url: Url, body: B) -> Result<Response<T>> {
38-
let byte = self.request.post(url, &body).send().await?.error_for_status()?.bytes().await?;
38+
let byte = self.request.post(url, &body).await.send().await?.error_for_status()?.bytes().await?;
3939
Ok(serde_json::from_slice(&byte)?)
4040
}
4141
}

inventium/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::Serialize;
66

77
pub mod curse;
88
pub mod key;
9-
mod rinth;
9+
pub mod rinth;
1010

1111
pub enum Platform {
1212
CurseForge,
@@ -39,7 +39,7 @@ impl Request {
3939
self.key.insert(self.client.get(url))
4040
}
4141

42-
pub fn post<B: Serialize>(&self, url: impl IntoUrl, body: &B) -> RequestBuilder {
42+
pub async fn post<B: Serialize>(&self, url: impl IntoUrl, body: &B) -> RequestBuilder {
4343
self.key.insert(self.client.post(url).json(body))
4444
}
4545
}

inventium/src/rinth/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Rinth {
3737
}
3838

3939
async fn post<T: DeserializeOwned, B: Serialize>(&self, url: Url, body: B) -> Result<Response<T>> {
40-
let byte = self.request.post(url, &body).send().await?.error_for_status()?.bytes().await?;
40+
let byte = self.request.post(url, &body).await.send().await?.error_for_status()?.bytes().await?;
4141
Ok(serde_json::from_slice(&byte)?)
4242
}
4343
}

inventium/src/rinth/request.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,7 @@ fn check_rate_limit(response: Response) -> Result<Response> {
2525
if response.status() == StatusCode::GONE {
2626
Err(Error::msg("API Deprecated"))
2727
} else if response.status() == StatusCode::TOO_MANY_REQUESTS {
28-
Err(Error::msg("Rate limit exceeded").context(
29-
response
30-
.headers()
31-
.get("X-Ratelimit-Reset")
32-
.map(|header| {
33-
header
34-
.to_str()
35-
.expect("Corrupted ratelimit header")
36-
.parse()
37-
.expect("Corrupted ratelimit header")
38-
})
39-
.expect("Corrupted ratelimit header"),))
28+
Err(Error::msg("Rate limit exceeded"))
4029
} else {
4130
Ok(response)
4231
}

inventium/src/rinth/wrapper/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Rinth {
1212
pub async fn instance_statistics(&self) -> Result<Statistics> {
1313
self.request
1414
.get(self.base_url.join_all(vec!["statistics"]))
15-
.custom_send_json()
15+
.await.custom_send_json()
1616
.await
1717
}
1818
}

inventium/src/rinth/wrapper/project.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ use crate::rinth::url::{UrlJoinAll, UrlWithQuery};
88
use crate::rinth::wrapper::check_id_slug;
99
use crate::rinth::Rinth;
1010
use anyhow::Result;
11+
use crate::rinth::request::RequestBuilderCustomSend;
1112

1213
impl Rinth {
1314
pub async fn project_get(&self, project_id: &str) -> Result<Project> {
1415
check_id_slug(&[project_id])?;
1516
self.request
1617
.get(self.base_url.join_all(vec!["project", project_id]))
17-
.custom_send_json()
18+
.await.custom_send_json()
1819
.await
1920
}
2021

@@ -26,7 +27,7 @@ impl Rinth {
2627
.join_all(vec!["projects"])
2728
.with_query_json("ids", project_ids)?,
2829
)
29-
.custom_send_json()
30+
.await.custom_send_json()
3031
.await
3132
}
3233

@@ -37,7 +38,7 @@ impl Rinth {
3738
.join_all(vec!["projects_random"])
3839
.with_query("count", count),
3940
)
40-
.custom_send_json()
41+
.await.custom_send_json()
4142
.await
4243
}
4344

@@ -50,7 +51,7 @@ impl Rinth {
5051
let res: Response = self
5152
.request
5253
.get(self.base_url.join_all(vec!["project", project_id, "check"]))
53-
.custom_send_json()
54+
.await.custom_send_json()
5455
.await?;
5556
Ok(res.id)
5657
}
@@ -59,7 +60,7 @@ impl Rinth {
5960
check_id_slug(&[project_id])?;
6061
self.request
6162
.get(self.base_url.join_all(vec!["project", project_id, "dependencies"]))
62-
.custom_send_json()
63+
.await.custom_send_json()
6364
.await
6465
}
6566
}

inventium/src/rinth/wrapper/search.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use super::*;
21
use crate::rinth::structs::search::{Facet, Response, Sort};
32
use crate::rinth::structs::Int;
43
use crate::rinth::url::{UrlJoinAll, UrlWithQuery};
54
use crate::rinth::Rinth;
65
use anyhow::Result;
6+
use crate::rinth::request::RequestBuilderCustomSend;
77

88
impl Rinth {
99
pub async fn search_paged(
@@ -26,7 +26,7 @@ impl Rinth {
2626
url = url.with_query_json("facets", facets)?
2727
}
2828

29-
self.request.get(url).custom_send_json().await
29+
self.request.get(url).await.custom_send_json().await
3030
}
3131

3232
pub async fn search(
@@ -45,6 +45,6 @@ impl Rinth {
4545
url = url.with_query_json("facets", facets)?
4646
}
4747

48-
self.request.get(url).custom_send_json().await
48+
self.request.get(url).await.custom_send_json().await
4949
}
5050
}

inventium/src/rinth/wrapper/tag.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,48 @@ use crate::rinth::structs::tag::{Category, DonationPlatform, GameVersion, Licens
77
use crate::rinth::url::UrlJoinAll;
88
use crate::rinth::Rinth;
99
use anyhow::Result;
10+
use crate::rinth::request::RequestBuilderCustomSend;
1011

1112
impl Rinth {
1213
pub async fn tag_list_categories(&self) -> Result<Vec<Category>> {
1314
self.request
1415
.get(self.base_url.join_all(vec!["tag", "category"]))
15-
.custom_send_json()
16+
.await.custom_send_json()
1617
.await
1718
}
1819

1920
pub async fn tag_list_loaders(&self) -> Result<Vec<Loader>> {
2021
self.request
2122
.get(self.base_url.join_all(vec!["tag", "loader"]))
22-
.custom_send_json()
23+
.await.custom_send_json()
2324
.await
2425
}
2526

2627
pub async fn tag_list_game_versions(&self) -> Result<Vec<GameVersion>> {
2728
self.request
2829
.get(self.base_url.join_all(vec!["tag", "game_version"]))
29-
.custom_send_json()
30+
.await.custom_send_json()
3031
.await
3132
}
3233

3334
pub async fn tag_license_text_and_title(&self, id: &str) -> Result<License> {
3435
self.request
3536
.get(self.base_url.join_all(vec!["tag", "license", id]))
36-
.custom_send_json()
37+
.await.custom_send_json()
3738
.await
3839
}
3940

4041
pub async fn tag_list_donation_platforms(&self) -> Result<Vec<DonationPlatform>> {
4142
self.request
4243
.get(self.base_url.join_all(vec!["tag", "donation_platform"]))
43-
.custom_send_json()
44+
.await.custom_send_json()
4445
.await
4546
}
4647

4748
pub async fn tag_list_report_types(&self) -> Result<Vec<String>> {
4849
self.request
4950
.get(self.base_url.join_all(vec!["tag", "report_type"]))
50-
.custom_send_json()
51+
.await.custom_send_json()
5152
.await
5253
}
5354
}

inventium/src/rinth/wrapper/version.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ use crate::rinth::structs::version::Version;
77
use crate::rinth::url::{UrlJoinAll, UrlWithQuery};
88
use crate::rinth::Rinth;
99
use anyhow::Result;
10+
use crate::rinth::request::RequestBuilderCustomSend;
1011

1112
impl Rinth {
1213
pub async fn version_list(&self, project_id: &str) -> Result<Vec<Version>> {
1314
check_id_slug(&[project_id])?;
1415
self.request
1516
.get(self.base_url.join_all(vec!["project", project_id, "version"]))
16-
.custom_send_json()
17+
.await.custom_send_json()
1718
.await
1819
}
19-
20+
2021
pub async fn version_list_filtered(
2122
&self,
2223
project_id: &str,
@@ -35,25 +36,25 @@ impl Rinth {
3536
if let Some(featured) = featured {
3637
url = url.with_query_json("featured", featured)?;
3738
}
38-
self.request.get(url).custom_send_json().await
39+
self.request.get(url).await.custom_send_json().await
3940
}
40-
41+
4142
pub async fn version_get(&self, version_id: &str) -> Result<Version> {
4243
check_id_slug(&[version_id])?;
4344
self.request
4445
.get(self.base_url.join_all(vec!["version", version_id]))
45-
.custom_send_json()
46+
.await.custom_send_json()
4647
.await
4748
}
48-
49+
4950
pub async fn version_get_from_number(&self, project_id: &str, number: &str) -> Result<Version> {
5051
check_id_slug(&[project_id])?;
5152
self.request
5253
.get(self.base_url.join_all(vec!["project", project_id, "version", number]))
53-
.custom_send_json()
54+
.await.custom_send_json()
5455
.await
5556
}
56-
57+
5758
pub async fn version_get_multiple(&self, version_ids: &[&str]) -> Result<Vec<Version>> {
5859
check_id_slug(version_ids)?;
5960
self.request
@@ -62,7 +63,7 @@ impl Rinth {
6263
.join_all(vec!["versions"])
6364
.with_query_json("ids", version_ids)?,
6465
)
65-
.custom_send_json()
66+
.await.custom_send_json()
6667
.await
6768
}
6869
}

inventium/src/rinth/wrapper/version_file.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Rinth {
1212
check_sha1_hash(&[hash])?;
1313
self.request
1414
.get(self.base_url.join_all(vec!["version_file", hash]))
15-
.custom_send_json()
15+
.await.custom_send_json()
1616
.await
1717
}
1818

@@ -32,7 +32,7 @@ impl Rinth {
3232
hashes,
3333
algorithm: HashAlgorithm::SHA1,
3434
})
35-
.custom_send_json()
35+
.await.custom_send_json()
3636
.await
3737
}
3838

@@ -48,7 +48,7 @@ impl Rinth {
4848
.join_all(vec!["version_file", hash, "update"])
4949
.with_query_json("algorithm", HashAlgorithm::SHA1)?,
5050
filters)
51-
.custom_send_json()
51+
.await.custom_send_json()
5252
.await
5353
}
5454

@@ -65,7 +65,7 @@ impl Rinth {
6565
loaders: filters.loaders,
6666
game_versions: filters.game_versions,
6767
})
68-
.custom_send_json()
68+
.await.custom_send_json()
6969
.await
7070
}
7171
}

0 commit comments

Comments
 (0)