1use serde_json::json;
2use crate::model::*;
3use crate::BumpClient;
4pub struct PostDiffsRequest<'a> {
8 pub(crate) client: &'a BumpClient,
9 pub url: Option<String>,
10 pub previous_url: Option<String>,
11 pub previous_definition: Option<String>,
12 pub previous_references: Option<Vec<Reference>>,
13 pub definition: Option<String>,
14 pub references: Option<Vec<Reference>>,
15 pub expires_at: Option<String>,
16}
17impl<'a> PostDiffsRequest<'a> {
18 pub async fn send(self) -> anyhow::Result<serde_json::Value> {
19 let mut r = self.client.client.post("/diffs");
20 if let Some(ref unwrapped) = self.url {
21 r = r.push_json(json!({ "url" : unwrapped }));
22 }
23 if let Some(ref unwrapped) = self.previous_url {
24 r = r.push_json(json!({ "previous_url" : unwrapped }));
25 }
26 if let Some(ref unwrapped) = self.previous_definition {
27 r = r.push_json(json!({ "previous_definition" : unwrapped }));
28 }
29 if let Some(ref unwrapped) = self.previous_references {
30 r = r.push_json(json!({ "previous_references" : unwrapped }));
31 }
32 if let Some(ref unwrapped) = self.definition {
33 r = r.push_json(json!({ "definition" : unwrapped }));
34 }
35 if let Some(ref unwrapped) = self.references {
36 r = r.push_json(json!({ "references" : unwrapped }));
37 }
38 if let Some(ref unwrapped) = self.expires_at {
39 r = r.push_json(json!({ "expires_at" : unwrapped }));
40 }
41 r = self.client.authenticate(r);
42 let res = r.send().await.unwrap().error_for_status();
43 match res {
44 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
45 Err(res) => {
46 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
47 Err(anyhow::anyhow!("{:?}", text))
48 }
49 }
50 }
51 pub fn url(mut self, url: &str) -> Self {
52 self.url = Some(url.to_owned());
53 self
54 }
55 pub fn previous_url(mut self, previous_url: &str) -> Self {
56 self.previous_url = Some(previous_url.to_owned());
57 self
58 }
59 pub fn previous_definition(mut self, previous_definition: &str) -> Self {
60 self.previous_definition = Some(previous_definition.to_owned());
61 self
62 }
63 pub fn previous_references(mut self, previous_references: Vec<Reference>) -> Self {
64 self.previous_references = Some(previous_references);
65 self
66 }
67 pub fn definition(mut self, definition: &str) -> Self {
68 self.definition = Some(definition.to_owned());
69 self
70 }
71 pub fn references(mut self, references: Vec<Reference>) -> Self {
72 self.references = Some(references);
73 self
74 }
75 pub fn expires_at(mut self, expires_at: &str) -> Self {
76 self.expires_at = Some(expires_at.to_owned());
77 self
78 }
79}
80pub struct GetDiffsByIdRequest<'a> {
84 pub(crate) client: &'a BumpClient,
85 pub id: String,
86 pub formats: Option<Vec<String>>,
87}
88impl<'a> GetDiffsByIdRequest<'a> {
89 pub async fn send(self) -> anyhow::Result<DiffForApi> {
90 let mut r = self.client.client.get(&format!("/diffs/{id}", id = self.id));
91 if let Some(ref unwrapped) = self.formats {
92 for item in unwrapped {
93 r = r.push_query("formats[]", &item.to_string());
94 }
95 }
96 r = self.client.authenticate(r);
97 let res = r.send().await.unwrap().error_for_status();
98 match res {
99 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
100 Err(res) => {
101 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
102 Err(anyhow::anyhow!("{:?}", text))
103 }
104 }
105 }
106 pub fn formats(
107 mut self,
108 formats: impl IntoIterator<Item = impl AsRef<str>>,
109 ) -> Self {
110 self
111 .formats = Some(
112 formats.into_iter().map(|s| s.as_ref().to_owned()).collect(),
113 );
114 self
115 }
116}
117pub struct GetHubsByHubIdOrSlugRequest<'a> {
121 pub(crate) client: &'a BumpClient,
122 pub hub_id_or_slug: String,
123}
124impl<'a> GetHubsByHubIdOrSlugRequest<'a> {
125 pub async fn send(self) -> anyhow::Result<Hub> {
126 let mut r = self
127 .client
128 .client
129 .get(
130 &format!("/hubs/{hub_id_or_slug}", hub_id_or_slug = self.hub_id_or_slug),
131 );
132 r = self.client.authenticate(r);
133 let res = r.send().await.unwrap().error_for_status();
134 match res {
135 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
136 Err(res) => {
137 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
138 Err(anyhow::anyhow!("{:?}", text))
139 }
140 }
141 }
142}
143pub struct PostVersionsRequest<'a> {
147 pub(crate) client: &'a BumpClient,
148 pub documentation: String,
149 pub hub: String,
150 pub documentation_name: String,
151 pub auto_create_documentation: bool,
152 pub definition: String,
153 pub references: Vec<Reference>,
154 pub branch_name: String,
155 pub previous_version_id: String,
156 pub unpublished: bool,
157}
158impl<'a> PostVersionsRequest<'a> {
159 pub async fn send(self) -> anyhow::Result<Version> {
160 let mut r = self.client.client.post("/versions");
161 r = r.push_json(json!({ "documentation" : self.documentation }));
162 r = r.push_json(json!({ "hub" : self.hub }));
163 r = r.push_json(json!({ "documentation_name" : self.documentation_name }));
164 r = r
165 .push_json(
166 json!({ "auto_create_documentation" : self.auto_create_documentation }),
167 );
168 r = r.push_json(json!({ "definition" : self.definition }));
169 r = r.push_json(json!({ "references" : self.references }));
170 r = r.push_json(json!({ "branch_name" : self.branch_name }));
171 r = r.push_json(json!({ "previous_version_id" : self.previous_version_id }));
172 r = r.push_json(json!({ "unpublished" : self.unpublished }));
173 r = self.client.authenticate(r);
174 let res = r.send().await.unwrap().error_for_status();
175 match res {
176 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
177 Err(res) => {
178 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
179 Err(anyhow::anyhow!("{:?}", text))
180 }
181 }
182 }
183}
184pub struct PostVersionsRequired<'a> {
185 pub documentation: &'a str,
186 pub hub: &'a str,
187 pub documentation_name: &'a str,
188 pub auto_create_documentation: bool,
189 pub definition: &'a str,
190 pub references: Vec<Reference>,
191 pub branch_name: &'a str,
192 pub previous_version_id: &'a str,
193 pub unpublished: bool,
194}
195impl<'a> PostVersionsRequired<'a> {}
196pub struct PostValidationsRequest<'a> {
200 pub(crate) client: &'a BumpClient,
201 pub documentation: String,
202 pub hub: String,
203 pub documentation_name: String,
204 pub auto_create_documentation: bool,
205 pub url: String,
206 pub definition: String,
207 pub references: Vec<Reference>,
208}
209impl<'a> PostValidationsRequest<'a> {
210 pub async fn send(self) -> anyhow::Result<Validation> {
211 let mut r = self.client.client.post("/validations");
212 r = r.push_json(json!({ "documentation" : self.documentation }));
213 r = r.push_json(json!({ "hub" : self.hub }));
214 r = r.push_json(json!({ "documentation_name" : self.documentation_name }));
215 r = r
216 .push_json(
217 json!({ "auto_create_documentation" : self.auto_create_documentation }),
218 );
219 r = r.push_json(json!({ "url" : self.url }));
220 r = r.push_json(json!({ "definition" : self.definition }));
221 r = r.push_json(json!({ "references" : self.references }));
222 r = self.client.authenticate(r);
223 let res = r.send().await.unwrap().error_for_status();
224 match res {
225 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
226 Err(res) => {
227 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
228 Err(anyhow::anyhow!("{:?}", text))
229 }
230 }
231 }
232}
233pub struct PostValidationsRequired<'a> {
234 pub documentation: &'a str,
235 pub hub: &'a str,
236 pub documentation_name: &'a str,
237 pub auto_create_documentation: bool,
238 pub url: &'a str,
239 pub definition: &'a str,
240 pub references: Vec<Reference>,
241}
242impl<'a> PostValidationsRequired<'a> {}
243pub struct PostPreviewsRequest<'a> {
247 pub(crate) client: &'a BumpClient,
248 pub definition: String,
249 pub references: Option<Vec<Reference>>,
250}
251impl<'a> PostPreviewsRequest<'a> {
252 pub async fn send(self) -> anyhow::Result<Preview> {
253 let mut r = self.client.client.post("/previews");
254 r = r.push_json(json!({ "definition" : self.definition }));
255 if let Some(ref unwrapped) = self.references {
256 r = r.push_json(json!({ "references" : unwrapped }));
257 }
258 r = self.client.authenticate(r);
259 let res = r.send().await.unwrap().error_for_status();
260 match res {
261 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
262 Err(res) => {
263 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
264 Err(anyhow::anyhow!("{:?}", text))
265 }
266 }
267 }
268 pub fn references(mut self, references: Vec<Reference>) -> Self {
269 self.references = Some(references);
270 self
271 }
272}
273pub struct PutPreviewsByPreviewIdRequest<'a> {
277 pub(crate) client: &'a BumpClient,
278 pub preview_id: String,
279 pub definition: String,
280 pub references: Option<Vec<Reference>>,
281}
282impl<'a> PutPreviewsByPreviewIdRequest<'a> {
283 pub async fn send(self) -> anyhow::Result<Preview> {
284 let mut r = self
285 .client
286 .client
287 .put(&format!("/previews/{preview_id}", preview_id = self.preview_id));
288 r = r.push_json(json!({ "definition" : self.definition }));
289 if let Some(ref unwrapped) = self.references {
290 r = r.push_json(json!({ "references" : unwrapped }));
291 }
292 r = self.client.authenticate(r);
293 let res = r.send().await.unwrap().error_for_status();
294 match res {
295 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
296 Err(res) => {
297 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
298 Err(anyhow::anyhow!("{:?}", text))
299 }
300 }
301 }
302 pub fn references(mut self, references: Vec<Reference>) -> Self {
303 self.references = Some(references);
304 self
305 }
306}
307pub struct GetVersionsByVersionIdRequest<'a> {
311 pub(crate) client: &'a BumpClient,
312 pub version_id: String,
313}
314impl<'a> GetVersionsByVersionIdRequest<'a> {
315 pub async fn send(self) -> anyhow::Result<serde_json::Value> {
316 let mut r = self
317 .client
318 .client
319 .get(&format!("/versions/{version_id}", version_id = self.version_id));
320 r = self.client.authenticate(r);
321 let res = r.send().await.unwrap().error_for_status();
322 match res {
323 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
324 Err(res) => {
325 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
326 Err(anyhow::anyhow!("{:?}", text))
327 }
328 }
329 }
330}
331pub struct GetPingRequest<'a> {
335 pub(crate) client: &'a BumpClient,
336}
337impl<'a> GetPingRequest<'a> {
338 pub async fn send(self) -> anyhow::Result<Pong> {
339 let mut r = self.client.client.get("/ping");
340 r = self.client.authenticate(r);
341 let res = r.send().await.unwrap().error_for_status();
342 match res {
343 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
344 Err(res) => {
345 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
346 Err(anyhow::anyhow!("{:?}", text))
347 }
348 }
349 }
350}