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
//! The metadata API.
use http::request;
use crate::models::meta::{ApiRoot, Meta};
use crate::Octocrab;
/// Handler for GitHub's Meta API.
///
/// Created with [`Octocrab::meta`].
pub struct MetaHandler<'octo> {
crab: &'octo Octocrab,
}
impl<'octo> MetaHandler<'octo> {
pub(crate) fn new(crab: &'octo Octocrab) -> Self {
Self { crab }
}
/// Get Hypermedia links to resources accessible in GitHub's REST API.
///
/// See also: [GitHub API Root](https://docs.github.com/en/rest/meta/meta?apiVersion=2022-11-28#github-api-root)
///
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let root = octocrab::instance().meta().get_api_root().await?;
/// # Ok(())
/// # }
/// ```
pub async fn get_api_root(&self) -> crate::Result<ApiRoot> {
self.crab.get("/", None::<&()>).await
}
/// Returns meta information about GitHub, including a list of GitHub's IP addresses.
///
/// See also: [Get GitHub meta information](https://docs.github.com/en/rest/meta/meta?apiVersion=2022-11-28#get-github-meta-information)
///
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let info = octocrab::instance().meta().get_github_meta_information().await?;
/// # Ok(())
/// # }
/// ```
pub async fn get_github_meta_information(&self) -> crate::Result<Meta> {
self.crab.get("/meta", None::<&()>).await
}
/// Get the octocat as ASCII art.
///
/// # Arguments
///
/// * `s` - The words to show in Octocat's speech bubble.
///
/// See also: [Get Octocat](https://docs.github.com/en/rest/meta/meta?apiVersion=2022-11-28#get-octocat)
///
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let art = octocrab::instance().meta().get_octocat(Some("hello")).await?;
/// # Ok(())
/// # }
/// ```
pub async fn get_octocat(&self, s: Option<impl AsRef<str>>) -> crate::Result<String> {
let route = "/octocat";
#[derive(serde::Serialize)]
struct Query<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
s: Option<&'a str>,
}
let query = Query {
s: s.as_ref().map(|s| s.as_ref()),
};
let uri = self.crab.parameterized_uri(route, Some(&query))?;
let mut request = request::Builder::new().method("GET").uri(uri);
request = request.header(http::header::ACCEPT, "application/octocat-stream");
let request = self.crab.build_request(request, None::<&()>)?;
let response = self.crab.execute(request).await?;
self.crab.body_to_string(response).await
}
/// Get all supported GitHub API versions.
///
/// See also: [Get all API versions](https://docs.github.com/en/rest/meta/meta?apiVersion=2022-11-28#get-all-api-versions)
///
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let versions = octocrab::instance().meta().get_api_versions().await?;
/// # Ok(())
/// # }
/// ```
pub async fn get_api_versions(&self) -> crate::Result<Vec<String>> {
self.crab.get("/versions", None::<&()>).await
}
/// Get a random sentence from the Zen of GitHub.
///
/// See also: [Get the Zen of GitHub](https://docs.github.com/en/rest/meta/meta?apiVersion=2022-11-28#get-the-zen-of-github)
///
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let sentence = octocrab::instance().meta().zen().await?;
/// # Ok(())
/// # }
/// ```
pub async fn zen(&self) -> crate::Result<String> {
let uri = self.crab.parameterized_uri("/zen", None::<&()>)?;
let mut request = request::Builder::new().method("GET").uri(uri);
request = request.header(http::header::ACCEPT, "text/plain");
let request = self.crab.build_request(request, None::<&()>)?;
let response = self.crab.execute(request).await?;
self.crab.body_to_string(response).await
}
}