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
use crate::{models::InstallationId, Octocrab};
use http::request::Builder;
use http::Method;
mod installations;
/// A client to [GitHub's apps API][apps-api].
///
/// Created with [`Octocrab::apps`].
///
/// [apps-api]: https://docs.github.com/en/rest/reference/apps
pub struct AppsRequestHandler<'octo> {
crab: &'octo Octocrab,
}
impl<'octo> AppsRequestHandler<'octo> {
pub(crate) fn new(crab: &'octo Octocrab) -> Self {
Self { crab }
}
/// Get an installation for the authenticated app
///
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// # let octocrab = octocrab::Octocrab::default();
/// use octocrab::models::InstallationId;
///
/// let installation = octocrab
/// .apps()
/// .installation(InstallationId(1))
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn installation(
&self,
installation_id: InstallationId,
) -> crate::Result<crate::models::Installation> {
let route = format!("/app/installations/{installation_id}",);
self.crab.get(&route, None::<&()>).await
}
/// Creates a new `InstallationsBuilder` that can be configured to filter
/// listing installations.
///
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// # let octocrab = octocrab::Octocrab::default();
/// use octocrab::params;
///
/// let page = octocrab
/// .apps()
/// .installations()
/// // Optional Parameters
/// .since(chrono::Utc::now() - chrono::Duration::days(1))
/// .per_page(100)
/// .page(5u32)
/// // Send the request
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn installations(&self) -> installations::InstallationsRequestBuilder<'_, '_> {
installations::InstallationsRequestBuilder::new(self)
}
pub(crate) async fn http_get<R, A, P>(
&self,
route: A,
parameters: Option<&P>,
) -> crate::Result<R>
where
A: AsRef<str>,
P: serde::Serialize + ?Sized,
R: crate::FromResponse,
{
let request = Builder::new()
.method(Method::GET)
.uri(self.crab.parameterized_uri(route, parameters)?);
let request = self.crab.build_request(request, None::<&()>)?;
R::from_response(crate::map_github_error(self.crab.execute(request).await?).await?).await
}
/// Get a repository installation for the authenticated app.
pub async fn get_repository_installation(
&self,
owner: impl AsRef<str>,
repo: impl AsRef<str>,
) -> crate::Result<crate::models::Installation> {
let route = format!(
"/repos/{owner}/{repo}/installation",
owner = owner.as_ref(),
repo = repo.as_ref(),
);
self.crab.get(&route, None::<&()>).await
}
/// Get an organization installation for the authenticated app.
pub async fn get_org_installation(
&self,
owner: impl AsRef<str>,
) -> crate::Result<crate::models::Installation> {
let route = format!("/orgs/{owner}/installation", owner = owner.as_ref(),);
self.crab.get(&route, None::<&()>).await
}
}