1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//! API calls related to versions
//!
//! [documentation](https://docs.modrinth.com/api-spec/#tag/versions)
use super::*;
use crate::structures::{version::*, UtcTime};
impl Ferinth<Authenticated> {
/**
Delete the version of `version_id`
```no_run
# tokio_test::block_on(async {
# let modrinth = ferinth::Ferinth::<ferinth::Authenticated>::new(
# env!("CARGO_CRATE_NAME"),
# Some(env!("CARGO_PKG_VERSION")),
# None,
# env!("MODRINTH_TOKEN"),
# )?;
modrinth.version_delete("XXXXXXXX").await?;
# Ok::<_, ferinth::Error>(()) }).unwrap()
```
*/
pub async fn version_delete(&self, version_id: &str) -> Result<()> {
check_id_slug(&[version_id])?;
self.client
.delete(API_BASE_URL.join_all(vec!["version", version_id]))
.custom_send()
.await?;
Ok(())
}
/**
Schedule changing the status of version of `version_id` to `requested_status` at `time`
```no_run
# use ferinth::structures::version::RequestedStatus;
# use chrono::{Duration, offset::Utc};
# tokio_test::block_on(async {
# let modrinth = ferinth::Ferinth::<ferinth::Authenticated>::new(
# env!("CARGO_CRATE_NAME"),
# Some(env!("CARGO_PKG_VERSION")),
# None,
# env!("MODRINTH_TOKEN"),
# )?;
// Release the version of ID `xuWxRZPd` to the public in three hours
modrinth.version_schedule(
"xuWxRZPd",
&(Utc::now() + Duration::hours(3)),
&RequestedStatus::Listed
).await?;
# Ok::<_, ferinth::Error>(()) }).unwrap()
```
*/
pub async fn version_schedule(
&self,
version_id: &str,
time: &UtcTime,
status: &RequestedStatus,
) -> Result<()> {
check_id_slug(&[version_id])?;
self.client
.post(
API_BASE_URL
.join_all(vec!["version", version_id, "schedule"])
.with_query_json("time", time)?
.with_query_json("requested_status", status)?,
)
.custom_send()
.await?;
Ok(())
}
}
impl<T> Ferinth<T> {
/**
Get the versions of the project of `project_id`
## Example
```rust
# tokio_test::block_on(async {
# let modrinth = ferinth::Ferinth::default();
let sodium_versions = modrinth.version_list("AANobbMI").await?;
sodium_versions.iter().for_each(|v| assert_eq!(v.project_id, "AANobbMI"));
# Ok::<_, ferinth::Error>(()) }).unwrap()
```
*/
pub async fn version_list(&self, project_id: &str) -> Result<Vec<Version>> {
check_id_slug(&[project_id])?;
self.client
.get(API_BASE_URL.join_all(vec!["project", project_id, "version"]))
.custom_send_json()
.await
}
/**
Get the versions of the project of `project_id`, filtered based on
mod `loaders`, `game_versions`, and whether the version is `featured`
## Example
```rust
# tokio_test::block_on(async {
# let modrinth = ferinth::Ferinth::default();
let sodium_forge_versions = modrinth.version_list_filtered(
"AANobbMI",
Some(&["forge"]),
None,
None
).await?;
// Sodium is not made for Forge
assert!(sodium_forge_versions.is_empty());
# Ok::<_, ferinth::Error>(()) }).unwrap()
```
*/
pub async fn version_list_filtered(
&self,
project_id: &str,
loaders: Option<&[&str]>,
game_versions: Option<&[&str]>,
featured: Option<bool>,
) -> Result<Vec<Version>> {
check_id_slug(&[project_id])?;
let mut url = API_BASE_URL.join_all(vec!["project", project_id, "version"]);
if let Some(loaders) = loaders {
url = url.with_query_json("loaders", loaders)?;
}
if let Some(game_versions) = game_versions {
url = url.with_query_json("game_versions", game_versions)?;
}
if let Some(featured) = featured {
url = url.with_query_json("featured", featured)?;
}
self.client.get(url).custom_send_json().await
}
/**
Get the version of `version_id`
## Example
```rust
# tokio_test::block_on(async {
# let modrinth = ferinth::Ferinth::default();
let sodium_version = modrinth.version_get("xuWxRZPd").await?;
assert_eq!(sodium_version.project_id, "AANobbMI");
# Ok::<_, ferinth::Error>(()) }).unwrap()
```
*/
pub async fn version_get(&self, version_id: &str) -> Result<Version> {
check_id_slug(&[version_id])?;
self.client
.get(API_BASE_URL.join_all(vec!["version", version_id]))
.custom_send_json()
.await
}
/**
Get the version of the version `number` from the project of `project_id`
## Example
```rust
# tokio_test::block_on(async {
# let modrinth = ferinth::Ferinth::default();
let version = modrinth.version_get_from_number("sodium", "mc1.17.1-0.3.2").await?;
assert_eq!(version.id, "xuWxRZPd");
# Ok::<_, ferinth::Error>(()) }).unwrap()
```
*/
pub async fn version_get_from_number(&self, project_id: &str, number: &str) -> Result<Version> {
check_id_slug(&[project_id])?;
self.client
.get(API_BASE_URL.join_all(vec!["project", project_id, "version", number]))
.custom_send_json()
.await
}
/**
Get the versions of `version_ids`
## Example
```rust
# tokio_test::block_on(async {
# let modrinth = ferinth::Ferinth::default();
let versions = modrinth.version_get_multiple(&[
"sxWTUZpD",
"mgPpe4NY",
]).await?;
versions.iter().for_each(|v| assert_eq!(v.project_id, "of7wIinq"));
# Ok::<_, ferinth::Error>(()) }).unwrap()
```
*/
pub async fn version_get_multiple(&self, version_ids: &[&str]) -> Result<Vec<Version>> {
check_id_slug(version_ids)?;
self.client
.get(
API_BASE_URL
.join_all(vec!["versions"])
.with_query_json("ids", version_ids)?,
)
.custom_send_json()
.await
}
}