-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_url.rs
More file actions
48 lines (38 loc) · 1.41 KB
/
Copy pathsave_url.rs
File metadata and controls
48 lines (38 loc) · 1.41 KB
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
// Copyright 2018 Samuel Walladge <samuel@swalladge.net>
// SPDX-License-Identifier: Apache-2.0 OR MIT
use std::env;
use std::result::Result;
use wallabag_api::types::{Config, NewEntry};
use wallabag_api::Client;
async fn run_example() -> Result<(), ()> {
let config = Config {
client_id: env::var("WALLABAG_CLIENT_ID").expect("WALLABAG_CLIENT_ID not set"),
client_secret: env::var("WALLABAG_CLIENT_SECRET").expect("WALLABAG_CLIENT_SECRET not set"),
username: env::var("WALLABAG_USERNAME").expect("WALLABAG_USERNAME not set"),
password: env::var("WALLABAG_PASSWORD").expect("WALLABAG_PASSWORD not set"),
base_url: env::var("WALLABAG_URL").expect("WALLABAG_URL not set"),
};
println!("{:#?}", config);
let mut client = Client::new(config);
let url = std::env::args().nth(1).ok_or_else(|| {
println!("Usage: save_url <url>");
})?;
let entry = NewEntry::new_with_url(url);
// entry.tags = Some(vec!["wat,thing".to_owned(), "console".to_owned()]);
// entry.archive = Some(true);
let res = client.create_entry(&entry).await;
match res {
Err(e) => {
println!("Failed to add entry: {:?}", e);
Err(())
}
Ok(entry) => {
println!("Success!");
println!("{:#?}", entry);
Ok(())
}
}
}
fn main() -> Result<(), ()> {
async_std::task::block_on(run_example())
}