roctogen/endpoints/
meta.rs

1//! Method, error and parameter types for the Meta endpoint.
2#![allow(
3    clippy::all
4)]
5/* 
6 * GitHub v3 REST API
7 *
8 * GitHub's v3 REST API.
9 *
10 * OpenAPI spec version: 1.1.4
11 * 
12 * Generated by: https://github.com/swagger-api/swagger-codegen.git
13 */
14
15use serde::Deserialize;
16
17use roctokit::adapters::{AdapterError, Client, GitHubRequest, GitHubResponseExt};
18use crate::models::*;
19
20use super::PerPage;
21
22use std::collections::HashMap;
23use serde_json::value::Value;
24
25pub struct Meta<'api, C: Client> where AdapterError: From<<C as Client>::Err> {
26    client: &'api C
27}
28
29pub fn new<C: Client>(client: &C) -> Meta<C> where AdapterError: From<<C as Client>::Err> {
30    Meta { client }
31}
32
33/// Errors for the [Get GitHub meta information](Meta::get_async()) endpoint.
34#[derive(Debug, thiserror::Error)]
35pub enum MetaGetError {
36    #[error("Not modified")]
37    Status304,
38    #[error("Status code: {}", code)]
39    Generic { code: u16 },
40}
41
42impl From<MetaGetError> for AdapterError {
43    fn from(err: MetaGetError) -> Self {
44        let (description, status_code) = match err {
45            MetaGetError::Status304 => (String::from("Not modified"), 304),
46            MetaGetError::Generic { code } => (String::from("Generic"), code)
47        };
48
49        Self::Endpoint {
50            description,
51            status_code,
52            source: Some(Box::new(err))
53        }
54    }
55}
56
57/// Errors for the [Get all API versions](Meta::get_all_versions_async()) endpoint.
58#[derive(Debug, thiserror::Error)]
59pub enum MetaGetAllVersionsError {
60    #[error("Resource not found")]
61    Status404(BasicError),
62    #[error("Status code: {}", code)]
63    Generic { code: u16 },
64}
65
66impl From<MetaGetAllVersionsError> for AdapterError {
67    fn from(err: MetaGetAllVersionsError) -> Self {
68        let (description, status_code) = match err {
69            MetaGetAllVersionsError::Status404(_) => (String::from("Resource not found"), 404),
70            MetaGetAllVersionsError::Generic { code } => (String::from("Generic"), code)
71        };
72
73        Self::Endpoint {
74            description,
75            status_code,
76            source: Some(Box::new(err))
77        }
78    }
79}
80
81/// Errors for the [Get Octocat](Meta::get_octocat_async()) endpoint.
82#[derive(Debug, thiserror::Error)]
83pub enum MetaGetOctocatError {
84    #[error("Status code: {}", code)]
85    Generic { code: u16 },
86}
87
88impl From<MetaGetOctocatError> for AdapterError {
89    fn from(err: MetaGetOctocatError) -> Self {
90        let (description, status_code) = match err {
91            MetaGetOctocatError::Generic { code } => (String::from("Generic"), code)
92        };
93
94        Self::Endpoint {
95            description,
96            status_code,
97            source: Some(Box::new(err))
98        }
99    }
100}
101
102/// Errors for the [Get the Zen of GitHub](Meta::get_zen_async()) endpoint.
103#[derive(Debug, thiserror::Error)]
104pub enum MetaGetZenError {
105    #[error("Status code: {}", code)]
106    Generic { code: u16 },
107}
108
109impl From<MetaGetZenError> for AdapterError {
110    fn from(err: MetaGetZenError) -> Self {
111        let (description, status_code) = match err {
112            MetaGetZenError::Generic { code } => (String::from("Generic"), code)
113        };
114
115        Self::Endpoint {
116            description,
117            status_code,
118            source: Some(Box::new(err))
119        }
120    }
121}
122
123/// Errors for the [GitHub API Root](Meta::root_async()) endpoint.
124#[derive(Debug, thiserror::Error)]
125pub enum MetaRootError {
126    #[error("Status code: {}", code)]
127    Generic { code: u16 },
128}
129
130impl From<MetaRootError> for AdapterError {
131    fn from(err: MetaRootError) -> Self {
132        let (description, status_code) = match err {
133            MetaRootError::Generic { code } => (String::from("Generic"), code)
134        };
135
136        Self::Endpoint {
137            description,
138            status_code,
139            source: Some(Box::new(err))
140        }
141    }
142}
143
144
145/// Query parameters for the [Get Octocat](Meta::get_octocat_async()) endpoint.
146#[derive(Default, Serialize)]
147pub struct MetaGetOctocatParams<'req> {
148    /// The words to show in Octocat's speech bubble
149    s: Option<&'req str>
150}
151
152impl<'req> MetaGetOctocatParams<'req> {
153    pub fn new() -> Self {
154        Self::default()
155    }
156
157    /// The words to show in Octocat's speech bubble
158    pub fn s(self, s: &'req str) -> Self {
159        Self {
160            s: Some(s),
161        }
162    }
163}
164
165
166impl<'api, C: Client> Meta<'api, C> where AdapterError: From<<C as Client>::Err> {
167    /// ---
168    ///
169    /// # Get GitHub meta information
170    ///
171    /// Returns meta information about GitHub, including a list of GitHub's IP addresses. For more information, see "[About GitHub's IP addresses](https://docs.github.com/articles/about-github-s-ip-addresses/)."
172    /// 
173    /// The API's response also includes a list of GitHub's domain names.
174    /// 
175    /// The values shown in the documentation's response are example values. You must always query the API directly to get the latest values.
176    /// 
177    /// > [!NOTE]
178    /// > This endpoint returns both IPv4 and IPv6 addresses. However, not all features support IPv6. You should refer to the specific documentation for each feature to determine if IPv6 is supported.
179    ///
180    /// [GitHub API docs for get](https://docs.github.com/rest/meta/meta#get-apiname-meta-information)
181    ///
182    /// ---
183    pub async fn get_async(&self) -> Result<ApiOverview, AdapterError> {
184
185        let request_uri = format!("{}/meta", super::GITHUB_BASE_API_URL);
186
187
188        let req = GitHubRequest {
189            uri: request_uri,
190            body: None::<C::Body>,
191            method: "GET",
192            headers: vec![]
193        };
194
195        let request = self.client.build(req)?;
196
197        // --
198
199        let github_response = self.client.fetch_async(request).await?;
200
201        // --
202
203        if github_response.is_success() {
204            Ok(github_response.to_json_async().await?)
205        } else {
206            match github_response.status_code() {
207                304 => Err(MetaGetError::Status304.into()),
208                code => Err(MetaGetError::Generic { code }.into()),
209            }
210        }
211    }
212
213    /// ---
214    ///
215    /// # Get GitHub meta information
216    ///
217    /// Returns meta information about GitHub, including a list of GitHub's IP addresses. For more information, see "[About GitHub's IP addresses](https://docs.github.com/articles/about-github-s-ip-addresses/)."
218    /// 
219    /// The API's response also includes a list of GitHub's domain names.
220    /// 
221    /// The values shown in the documentation's response are example values. You must always query the API directly to get the latest values.
222    /// 
223    /// > [!NOTE]
224    /// > This endpoint returns both IPv4 and IPv6 addresses. However, not all features support IPv6. You should refer to the specific documentation for each feature to determine if IPv6 is supported.
225    ///
226    /// [GitHub API docs for get](https://docs.github.com/rest/meta/meta#get-apiname-meta-information)
227    ///
228    /// ---
229    #[cfg(not(target_arch = "wasm32"))]
230    pub fn get(&self) -> Result<ApiOverview, AdapterError> {
231
232        let request_uri = format!("{}/meta", super::GITHUB_BASE_API_URL);
233
234
235        let req = GitHubRequest {
236            uri: request_uri,
237            body: None,
238            method: "GET",
239            headers: vec![]
240        };
241
242        let request = self.client.build(req)?;
243
244        // --
245
246        let github_response = self.client.fetch(request)?;
247
248        // --
249
250        if github_response.is_success() {
251            Ok(github_response.to_json()?)
252        } else {
253            match github_response.status_code() {
254                304 => Err(MetaGetError::Status304.into()),
255                code => Err(MetaGetError::Generic { code }.into()),
256            }
257        }
258    }
259
260    /// ---
261    ///
262    /// # Get all API versions
263    ///
264    /// Get all supported GitHub API versions.
265    ///
266    /// [GitHub API docs for get_all_versions](https://docs.github.com/rest/meta/meta#get-all-api-versions)
267    ///
268    /// ---
269    pub async fn get_all_versions_async(&self) -> Result<Vec<chrono::DateTime<chrono::Utc>>, AdapterError> {
270
271        let request_uri = format!("{}/versions", super::GITHUB_BASE_API_URL);
272
273
274        let req = GitHubRequest {
275            uri: request_uri,
276            body: None::<C::Body>,
277            method: "GET",
278            headers: vec![]
279        };
280
281        let request = self.client.build(req)?;
282
283        // --
284
285        let github_response = self.client.fetch_async(request).await?;
286
287        // --
288
289        if github_response.is_success() {
290            Ok(github_response.to_json_async().await?)
291        } else {
292            match github_response.status_code() {
293                404 => Err(MetaGetAllVersionsError::Status404(github_response.to_json_async().await?).into()),
294                code => Err(MetaGetAllVersionsError::Generic { code }.into()),
295            }
296        }
297    }
298
299    /// ---
300    ///
301    /// # Get all API versions
302    ///
303    /// Get all supported GitHub API versions.
304    ///
305    /// [GitHub API docs for get_all_versions](https://docs.github.com/rest/meta/meta#get-all-api-versions)
306    ///
307    /// ---
308    #[cfg(not(target_arch = "wasm32"))]
309    pub fn get_all_versions(&self) -> Result<Vec<chrono::DateTime<chrono::Utc>>, AdapterError> {
310
311        let request_uri = format!("{}/versions", super::GITHUB_BASE_API_URL);
312
313
314        let req = GitHubRequest {
315            uri: request_uri,
316            body: None,
317            method: "GET",
318            headers: vec![]
319        };
320
321        let request = self.client.build(req)?;
322
323        // --
324
325        let github_response = self.client.fetch(request)?;
326
327        // --
328
329        if github_response.is_success() {
330            Ok(github_response.to_json()?)
331        } else {
332            match github_response.status_code() {
333                404 => Err(MetaGetAllVersionsError::Status404(github_response.to_json()?).into()),
334                code => Err(MetaGetAllVersionsError::Generic { code }.into()),
335            }
336        }
337    }
338
339    /// ---
340    ///
341    /// # Get Octocat
342    ///
343    /// Get the octocat as ASCII art
344    ///
345    /// [GitHub API docs for get_octocat](https://docs.github.com/rest/meta/meta#get-octocat)
346    ///
347    /// ---
348    pub async fn get_octocat_async(&self, query_params: Option<impl Into<MetaGetOctocatParams<'api>>>) -> Result<String, AdapterError> {
349
350        let mut request_uri = format!("{}/octocat", super::GITHUB_BASE_API_URL);
351
352        if let Some(params) = query_params {
353            request_uri.push_str("?");
354            request_uri.push_str(&serde_urlencoded::to_string(params.into())?);
355        }
356
357        let req = GitHubRequest {
358            uri: request_uri,
359            body: None::<C::Body>,
360            method: "GET",
361            headers: vec![]
362        };
363
364        let request = self.client.build(req)?;
365
366        // --
367
368        let github_response = self.client.fetch_async(request).await?;
369
370        // --
371
372        if github_response.is_success() {
373            Ok(github_response.to_json_async().await?)
374        } else {
375            match github_response.status_code() {
376                code => Err(MetaGetOctocatError::Generic { code }.into()),
377            }
378        }
379    }
380
381    /// ---
382    ///
383    /// # Get Octocat
384    ///
385    /// Get the octocat as ASCII art
386    ///
387    /// [GitHub API docs for get_octocat](https://docs.github.com/rest/meta/meta#get-octocat)
388    ///
389    /// ---
390    #[cfg(not(target_arch = "wasm32"))]
391    pub fn get_octocat(&self, query_params: Option<impl Into<MetaGetOctocatParams<'api>>>) -> Result<String, AdapterError> {
392
393        let mut request_uri = format!("{}/octocat", super::GITHUB_BASE_API_URL);
394
395        if let Some(params) = query_params {
396            request_uri.push_str("?");
397            let qp: MetaGetOctocatParams = params.into();
398            request_uri.push_str(&serde_urlencoded::to_string(qp)?);
399        }
400
401        let req = GitHubRequest {
402            uri: request_uri,
403            body: None,
404            method: "GET",
405            headers: vec![]
406        };
407
408        let request = self.client.build(req)?;
409
410        // --
411
412        let github_response = self.client.fetch(request)?;
413
414        // --
415
416        if github_response.is_success() {
417            Ok(github_response.to_json()?)
418        } else {
419            match github_response.status_code() {
420                code => Err(MetaGetOctocatError::Generic { code }.into()),
421            }
422        }
423    }
424
425    /// ---
426    ///
427    /// # Get the Zen of GitHub
428    ///
429    /// Get a random sentence from the Zen of GitHub
430    ///
431    /// [GitHub API docs for get_zen](https://docs.github.com/rest/meta/meta#get-the-zen-of-github)
432    ///
433    /// ---
434    pub async fn get_zen_async(&self) -> Result<String, AdapterError> {
435
436        let request_uri = format!("{}/zen", super::GITHUB_BASE_API_URL);
437
438
439        let req = GitHubRequest {
440            uri: request_uri,
441            body: None::<C::Body>,
442            method: "GET",
443            headers: vec![]
444        };
445
446        let request = self.client.build(req)?;
447
448        // --
449
450        let github_response = self.client.fetch_async(request).await?;
451
452        // --
453
454        if github_response.is_success() {
455            Ok(github_response.to_json_async().await?)
456        } else {
457            match github_response.status_code() {
458                code => Err(MetaGetZenError::Generic { code }.into()),
459            }
460        }
461    }
462
463    /// ---
464    ///
465    /// # Get the Zen of GitHub
466    ///
467    /// Get a random sentence from the Zen of GitHub
468    ///
469    /// [GitHub API docs for get_zen](https://docs.github.com/rest/meta/meta#get-the-zen-of-github)
470    ///
471    /// ---
472    #[cfg(not(target_arch = "wasm32"))]
473    pub fn get_zen(&self) -> Result<String, AdapterError> {
474
475        let request_uri = format!("{}/zen", super::GITHUB_BASE_API_URL);
476
477
478        let req = GitHubRequest {
479            uri: request_uri,
480            body: None,
481            method: "GET",
482            headers: vec![]
483        };
484
485        let request = self.client.build(req)?;
486
487        // --
488
489        let github_response = self.client.fetch(request)?;
490
491        // --
492
493        if github_response.is_success() {
494            Ok(github_response.to_json()?)
495        } else {
496            match github_response.status_code() {
497                code => Err(MetaGetZenError::Generic { code }.into()),
498            }
499        }
500    }
501
502    /// ---
503    ///
504    /// # GitHub API Root
505    ///
506    /// Get Hypermedia links to resources accessible in GitHub's REST API
507    ///
508    /// [GitHub API docs for root](https://docs.github.com/rest/meta/meta#github-api-root)
509    ///
510    /// ---
511    pub async fn root_async(&self) -> Result<Root, AdapterError> {
512
513        let request_uri = format!("{}/", super::GITHUB_BASE_API_URL);
514
515
516        let req = GitHubRequest {
517            uri: request_uri,
518            body: None::<C::Body>,
519            method: "GET",
520            headers: vec![]
521        };
522
523        let request = self.client.build(req)?;
524
525        // --
526
527        let github_response = self.client.fetch_async(request).await?;
528
529        // --
530
531        if github_response.is_success() {
532            Ok(github_response.to_json_async().await?)
533        } else {
534            match github_response.status_code() {
535                code => Err(MetaRootError::Generic { code }.into()),
536            }
537        }
538    }
539
540    /// ---
541    ///
542    /// # GitHub API Root
543    ///
544    /// Get Hypermedia links to resources accessible in GitHub's REST API
545    ///
546    /// [GitHub API docs for root](https://docs.github.com/rest/meta/meta#github-api-root)
547    ///
548    /// ---
549    #[cfg(not(target_arch = "wasm32"))]
550    pub fn root(&self) -> Result<Root, AdapterError> {
551
552        let request_uri = format!("{}/", super::GITHUB_BASE_API_URL);
553
554
555        let req = GitHubRequest {
556            uri: request_uri,
557            body: None,
558            method: "GET",
559            headers: vec![]
560        };
561
562        let request = self.client.build(req)?;
563
564        // --
565
566        let github_response = self.client.fetch(request)?;
567
568        // --
569
570        if github_response.is_success() {
571            Ok(github_response.to_json()?)
572        } else {
573            match github_response.status_code() {
574                code => Err(MetaRootError::Generic { code }.into()),
575            }
576        }
577    }
578
579}