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
use snafu::ResultExt;
use crate::Octocrab;
pub struct GitignoreHandler<'octo> {
crab: &'octo Octocrab,
}
impl<'octo> GitignoreHandler<'octo> {
pub(crate) fn new(crab: &'octo Octocrab) -> Self {
Self { crab }
}
pub async fn list(&self) -> crate::Result<Vec<String>> {
self.crab.get("gitignore/templates", None::<&()>).await
}
pub async fn get(&self, name: impl AsRef<str>) -> crate::Result<String> {
let route = format!("gitignore/templates/{name}", name = name.as_ref());
let request = self
.crab
.client
.get(self.crab.absolute_url(route)?)
.header(reqwest::header::ACCEPT, crate::format_media_type("raw"));
self.crab
.execute(request)
.await?
.text()
.await
.context(crate::error::Http)
}
}