-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
gists_create.rs
47 lines (42 loc) · 1.39 KB
/
gists_create.rs
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
use hubcaps::gists::{Content, GistOptions};
use hubcaps::{Credentials, Github};
use std::collections::HashMap;
use std::env;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
pretty_env_logger::init();
let token = env::var("GITHUB_TOKEN")?;
let github = Github::new(
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
Credentials::Token(token),
)?;
// create new gist
let mut files = HashMap::new();
files.insert("file1", "Hello World");
let options = GistOptions::new(Some("gist description"), false, files);
let gist = github.gists().create(&options).await?;
println!("{:#?}", gist);
// edit file1
let mut files = HashMap::new();
files.insert("file1", "Hello World!!");
let options = GistOptions::new(None as Option<String>, false, files);
let gist = github.gists().edit(&gist.id, &options).await?;
println!("{:#?}", gist);
// rename file1 to file2
let mut files = HashMap::new();
files.insert(
String::from("file1"),
Content::new(Some("file2"), "Hello World!!"),
);
let options = GistOptions {
description: None as Option<String>,
public: None,
files,
};
let gist = github.gists().edit(&gist.id, &options).await?;
println!("{:#?}", gist);
// delete gist
github.gists().delete(&gist.id).await?;
Ok(())
}