Crate telegraph_api_rs
source ·Expand description
Rust implementation of Telegraph API
Quick start
Create account
use telegraph_api_rs::Telegraph;
let telegraph = Telegraph::new();
let account = telegraph.create_account()
.short_name("Short name")
.author_name("Author name")
.send()
.unwrap();
Edit account
let edited_account = telegraph.edit_account_info()
.access_token(token)
.author_name("Author name 2")
.send()
.unwrap();
Get account info
let account_info = telegraph.get_account_info()
.access_token(token)
.fields(vec![AccountField::ShortName, AccountField::AuthorUrl])
.send()
.unwrap();
Revoke access token
let account = telegraph.revoke_access_token()
.access_token(token)
.send()
.unwrap();
Create page
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();
Edit page
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();
Get page
let get_page = telegraph.get_page()
.path(&page.path)
.send()
.unwrap();
Get page list
let page_list = telegraph.get_page_list()
.access_token(token)
.limit(2)
.send()
.unwrap();
Get views
let count = telegraph.get_views()
.path(&page_list.pages[0].path)
.year(2022)
.month(10)
.day(15)
.send()
.unwrap();
Telegraph
contains methods Telegraph API
Errors
Possible errors are described in TelegraphError
.
Re-exports
pub use crate::error::TelegraphError;
Modules
- Errors that occurred while working with the library
- Available methods
- Available types
Structs
Telegraph
for calling method builder
Functions
- Build page content from string