Rust implementation of Telegraph API
Add dependency to the Cargo.toml
toml
[dependencies]
telegraph-api-rs = "0.2.0"
```rust use telegraphapirs::{Telegraph, Request};
let telegraph = Telegraph::new(); let account = telegraph.createaccount() .shortname("Short name") .author_name("Author name") .send() .unwrap(); ```
rust
let edited_account = telegraph.edit_account_info()
.access_token(token)
.author_name("Author name 2")
.send()
.unwrap();
rust
let account_info = telegraph.get_account_info()
.access_token(token)
.fields(vec![AccountField::ShortName, AccountField::AuthorUrl])
.send()
.unwrap();
rust
let account = telegraph.revoke_access_token()
.access_token(token)
.send()
.unwrap();
```rust 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.createpage() .accesstoken(token) .title("Hello world") .content(cont) .return_content(true) .send() .unwrap(); ```
```rust 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 newcont = buildcontent(new_content).unwrap();
let editedpage = telegraph.editpage() .accesstoken(token) .title(&page.title) .path(&page.path) .content(newcont) .return_content(true) .send() .unwrap(); ```
rust
let get_page = telegraph.get_page()
.path(&page.path)
.send()
.unwrap();
rust
let page_list = telegraph.get_page_list()
.access_token(token)
.limit(2)
.send()
.unwrap();
rust
let count = telegraph.get_views()
.path(&page_list.pages[0].path)
.year(2023)
.month(10)
.day(15)
.hour(24)
.send()
.unwrap();
```rust use telegraphapirs::Telegraph;
let telegraph = Telegraph::new();
let files = vec!["1.jpg", "2.png"];
let media = telegraph.upload(&files);
You can upload media with custom client
rust
use telegraphapirs::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