paper_mc/
request.rs

1use serde_json::json;
2use crate::model::*;
3use crate::PaperMcClient;
4/**Create this with the associated client method.
5
6That method takes required values as arguments. Set optional values using builder methods on this struct.*/
7pub struct ProjectsRequest<'a> {
8    pub(crate) client: &'a PaperMcClient,
9}
10impl<'a> ProjectsRequest<'a> {
11    pub async fn send(self) -> anyhow::Result<ProjectsResponse> {
12        let mut r = self.client.client.get("/v2/projects");
13        let res = r.send().await.unwrap().error_for_status();
14        match res {
15            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
16            Err(res) => {
17                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
18                Err(anyhow::anyhow!("{:?}", text))
19            }
20        }
21    }
22}
23/**Create this with the associated client method.
24
25That method takes required values as arguments. Set optional values using builder methods on this struct.*/
26pub struct ProjectRequest<'a> {
27    pub(crate) client: &'a PaperMcClient,
28    pub project: String,
29}
30impl<'a> ProjectRequest<'a> {
31    pub async fn send(self) -> anyhow::Result<ProjectResponse> {
32        let mut r = self
33            .client
34            .client
35            .get(&format!("/v2/projects/{project}", project = self.project));
36        let res = r.send().await.unwrap().error_for_status();
37        match res {
38            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
39            Err(res) => {
40                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
41                Err(anyhow::anyhow!("{:?}", text))
42            }
43        }
44    }
45}
46/**Create this with the associated client method.
47
48That method takes required values as arguments. Set optional values using builder methods on this struct.*/
49pub struct VersionRequest<'a> {
50    pub(crate) client: &'a PaperMcClient,
51    pub project: String,
52    pub version: String,
53}
54impl<'a> VersionRequest<'a> {
55    pub async fn send(self) -> anyhow::Result<VersionResponse> {
56        let mut r = self
57            .client
58            .client
59            .get(
60                &format!(
61                    "/v2/projects/{project}/versions/{version}", project = self.project,
62                    version = self.version
63                ),
64            );
65        let res = r.send().await.unwrap().error_for_status();
66        match res {
67            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
68            Err(res) => {
69                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
70                Err(anyhow::anyhow!("{:?}", text))
71            }
72        }
73    }
74}
75/**Create this with the associated client method.
76
77That method takes required values as arguments. Set optional values using builder methods on this struct.*/
78pub struct BuildsRequest<'a> {
79    pub(crate) client: &'a PaperMcClient,
80    pub project: String,
81    pub version: String,
82}
83impl<'a> BuildsRequest<'a> {
84    pub async fn send(self) -> anyhow::Result<BuildsResponse> {
85        let mut r = self
86            .client
87            .client
88            .get(
89                &format!(
90                    "/v2/projects/{project}/versions/{version}/builds", project = self
91                    .project, version = self.version
92                ),
93            );
94        let res = r.send().await.unwrap().error_for_status();
95        match res {
96            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
97            Err(res) => {
98                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
99                Err(anyhow::anyhow!("{:?}", text))
100            }
101        }
102    }
103}
104/**Create this with the associated client method.
105
106That method takes required values as arguments. Set optional values using builder methods on this struct.*/
107pub struct BuildRequest<'a> {
108    pub(crate) client: &'a PaperMcClient,
109    pub project: String,
110    pub version: String,
111    pub build: i64,
112}
113impl<'a> BuildRequest<'a> {
114    pub async fn send(self) -> anyhow::Result<BuildResponse> {
115        let mut r = self
116            .client
117            .client
118            .get(
119                &format!(
120                    "/v2/projects/{project}/versions/{version}/builds/{build}", project =
121                    self.project, version = self.version, build = self.build
122                ),
123            );
124        let res = r.send().await.unwrap().error_for_status();
125        match res {
126            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
127            Err(res) => {
128                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
129                Err(anyhow::anyhow!("{:?}", text))
130            }
131        }
132    }
133}
134/**Create this with the associated client method.
135
136That method takes required values as arguments. Set optional values using builder methods on this struct.*/
137pub struct DownloadRequest<'a> {
138    pub(crate) client: &'a PaperMcClient,
139    pub project: String,
140    pub version: String,
141    pub build: i64,
142    pub download: String,
143}
144impl<'a> DownloadRequest<'a> {
145    pub async fn send(self) -> anyhow::Result<serde_json::Value> {
146        let mut r = self
147            .client
148            .client
149            .get(
150                &format!(
151                    "/v2/projects/{project}/versions/{version}/builds/{build}/downloads/{download}",
152                    project = self.project, version = self.version, build = self.build,
153                    download = self.download
154                ),
155            );
156        let res = r.send().await.unwrap().error_for_status();
157        match res {
158            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
159            Err(res) => {
160                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
161                Err(anyhow::anyhow!("{:?}", text))
162            }
163        }
164    }
165}
166pub struct DownloadRequired<'a> {
167    pub project: &'a str,
168    pub version: &'a str,
169    pub build: i64,
170    pub download: &'a str,
171}
172impl<'a> DownloadRequired<'a> {}
173/**Create this with the associated client method.
174
175That method takes required values as arguments. Set optional values using builder methods on this struct.*/
176pub struct FamilyRequest<'a> {
177    pub(crate) client: &'a PaperMcClient,
178    pub project: String,
179    pub family: String,
180}
181impl<'a> FamilyRequest<'a> {
182    pub async fn send(self) -> anyhow::Result<VersionFamilyResponse> {
183        let mut r = self
184            .client
185            .client
186            .get(
187                &format!(
188                    "/v2/projects/{project}/version_group/{family}", project = self
189                    .project, family = self.family
190                ),
191            );
192        let res = r.send().await.unwrap().error_for_status();
193        match res {
194            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
195            Err(res) => {
196                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
197                Err(anyhow::anyhow!("{:?}", text))
198            }
199        }
200    }
201}
202/**Create this with the associated client method.
203
204That method takes required values as arguments. Set optional values using builder methods on this struct.*/
205pub struct FamilyBuildsRequest<'a> {
206    pub(crate) client: &'a PaperMcClient,
207    pub project: String,
208    pub family: String,
209}
210impl<'a> FamilyBuildsRequest<'a> {
211    pub async fn send(self) -> anyhow::Result<VersionFamilyBuildsResponse> {
212        let mut r = self
213            .client
214            .client
215            .get(
216                &format!(
217                    "/v2/projects/{project}/version_group/{family}/builds", project =
218                    self.project, family = self.family
219                ),
220            );
221        let res = r.send().await.unwrap().error_for_status();
222        match res {
223            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
224            Err(res) => {
225                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
226                Err(anyhow::anyhow!("{:?}", text))
227            }
228        }
229    }
230}