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
extern crate serde_json;
use self::super::{Github, Result};
pub struct Keys<'a> {
github: &'a Github,
owner: String,
repo: String,
}
impl<'a> Keys<'a> {
pub fn new<O, R>(github: &'a Github, owner: O, repo: R) -> Keys<'a>
where O: Into<String>,
R: Into<String>
{
Keys {
github: github,
owner: owner.into(),
repo: repo.into(),
}
}
fn path(&self, more: &str) -> String {
format!("/repos/{}/{}/keys{}", self.owner, self.repo, more)
}
pub fn create(&self, key: &KeyOptions) -> Result<Key> {
let data = try!(serde_json::to_string::<KeyOptions>(key));
self.github.post::<Key>(&self.path(""), data.as_bytes())
}
pub fn list(&self) -> Result<Vec<Key>> {
self.github.get::<Vec<Key>>(&self.path(""))
}
pub fn get(&self, id: u64) -> Result<Key> {
self.github.get::<Key>(&self.path(&format!("/{}", id)))
}
pub fn delete(&self, id: u64) -> Result<()> {
self.github
.delete(&self.path(&format!("/{}", id)))
.map(|_| ())
}
}
#[derive(Debug, Deserialize)]
pub struct Key {
pub id: u64,
pub key: String,
pub title: String,
pub verified: bool,
pub created_at: String,
pub read_only: bool,
}
#[derive(Debug, Serialize)]
pub struct KeyOptions {
pub title: String,
pub key: String,
pub read_only: bool,
}