Crates.io | telegraph-api-rs |
lib.rs | telegraph-api-rs |
version | 0.2.0 |
source | src |
created_at | 2022-10-20 16:24:10.636733 |
updated_at | 2023-04-09 20:01:52.627468 |
description | Rust implementation of Telegraph API |
homepage | |
repository | https://github.com/heyyyoyy/telegraph-api-rs |
max_upload_size | |
id | 692668 |
size | 93,296 |
Rust implementation of Telegraph API
Add dependency to the Cargo.toml
[dependencies]
telegraph-api-rs = "0.2.0"
use telegraph_api_rs::{Telegraph, Request};
let telegraph = Telegraph::new();
let account = telegraph.create_account()
.short_name("Short name")
.author_name("Author name")
.send()
.unwrap();
let edited_account = telegraph.edit_account_info()
.access_token(token)
.author_name("Author name 2")
.send()
.unwrap();
let account_info = telegraph.get_account_info()
.access_token(token)
.fields(vec![AccountField::ShortName, AccountField::AuthorUrl])
.send()
.unwrap();
let account = telegraph.revoke_access_token()
.access_token(token)
.send()
.unwrap();
let content = r#"
[
{
"tag": "h3",
"children": ["Hello world"]
},
{
"tag": "h4",
"children": ["Title"]
},
{
"tag": "p",
"children": [
{
"tag": "ul",
"children": ["Some text"]
}
]
}
]
"#;
let cont = build_content(content).unwrap();
let page = telegraph.create_page()
.access_token(token)
.title("Hello world")
.content(cont)
.return_content(true)
.send()
.unwrap();
let new_content = r#"
[
{
"tag": "h3",
"children": ["Hello world"]
},
{
"tag": "h4",
"children": ["Title"]
},
{
"tag": "p",
"children": [
{
"tag": "ul",
"children": ["Some text"]
},
{
"tag": "ul",
"children": ["Some text 2"]
}
]
}
]
"#;
let new_cont = build_content(new_content).unwrap();
let edited_page = telegraph.edit_page()
.access_token(token)
.title(&page.title)
.path(&page.path)
.content(new_cont)
.return_content(true)
.send()
.unwrap();
let get_page = telegraph.get_page()
.path(&page.path)
.send()
.unwrap();
let page_list = telegraph.get_page_list()
.access_token(token)
.limit(2)
.send()
.unwrap();
let count = telegraph.get_views()
.path(&page_list.pages[0].path)
.year(2023)
.month(10)
.day(15)
.hour(24)
.send()
.unwrap();
use telegraph_api_rs::Telegraph;
let telegraph = Telegraph::new();
let files = vec!["1.jpg", "2.png"];
let media = telegraph.upload(&files);
You can upload media with custom client
use telegraph_api_rs::Telegraph;
use reqwest::blocking::Client;
let client = Client::new();
let files = vec!["1.jpg", "2.png"];
let media = Telegraph::upload_with(&client, &files);
More examples in the documentation