1use serde::{Deserialize, Serialize};
6
7use crate::{Future, Github};
8
9pub struct Keys {
10 github: Github,
11 owner: String,
12 repo: String,
13}
14
15impl Keys {
16 #[doc(hidden)]
17 pub fn new<O, R>(github: Github, owner: O, repo: R) -> Self
18 where
19 O: Into<String>,
20 R: Into<String>,
21 {
22 Keys {
23 github,
24 owner: owner.into(),
25 repo: repo.into(),
26 }
27 }
28
29 fn path(&self, more: &str) -> String {
30 format!("/repos/{}/{}/keys{}", self.owner, self.repo, more)
31 }
32
33 pub fn create(&self, key: &KeyOptions) -> Future<Key> {
34 self.github.post(&self.path(""), json!(key))
35 }
36
37 pub fn list(&self) -> Future<Vec<Key>> {
38 self.github.get(&self.path(""))
39 }
40
41 pub fn get(&self, id: u64) -> Future<Key> {
42 self.github.get(&self.path(&format!("/{}", id)))
43 }
44
45 pub fn delete(&self, id: u64) -> Future<()> {
46 self.github.delete(&self.path(&format!("/{}", id)))
47 }
48}
49
50#[derive(Debug, Deserialize)]
53pub struct Key {
54 pub id: u64,
55 pub key: String,
56 pub title: String,
57 pub verified: bool,
58 pub created_at: String,
59 pub read_only: bool,
60}
61
62#[derive(Debug, Serialize)]
63pub struct KeyOptions {
64 pub title: String,
65 pub key: String,
66 pub read_only: bool,
67}