telegraph_rs/types.rs
1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4/// This object represents a Telegraph account.
5#[derive(Debug, Clone, Deserialize)]
6pub struct Account {
7 /// Account name, helps users with several accounts remember which they are currently using.
8 ///
9 /// Displayed to the user above the "Edit/Publish" button on Telegra.ph, other users don't see this name.
10 pub short_name: Option<String>,
11 /// Default author name used when creating new articles.
12 pub author_name: Option<String>,
13 /// Profile link, opened when users click on the author's name below the title.
14 ///
15 /// Can be any link, not necessarily to a Telegram profile or channel.
16 pub author_url: Option<String>,
17 /// Optional. Only returned by the createAccount and revokeAccessToken method.
18 ///
19 /// Access token of the Telegraph account.
20 pub access_token: Option<String>,
21 /// Optional. URL to authorize a browser on telegra.ph and connect it to a Telegraph account.
22 ///
23 /// This URL is valid for only one use and for 5 minutes only.
24 pub auth_url: Option<String>,
25 /// Optional. Number of pages belonging to the Telegraph account.
26 pub page_count: Option<i32>,
27}
28
29/// This object represents a list of Telegraph articles belonging to an account. Most recently created articles first.
30#[derive(Debug, Clone, Deserialize)]
31pub struct PageList {
32 /// Total number of pages belonging to the target Telegraph account.
33 pub total_count: i32,
34 /// Requested pages of the target Telegraph account.
35 pub pages: Vec<Page>,
36}
37
38/// This object represents a page on Telegraph.
39#[derive(Debug, Clone, Deserialize)]
40pub struct Page {
41 /// Path to the page.
42 pub path: String,
43 /// URL of the page.
44 pub url: String,
45 /// Title of the page.
46 pub title: String,
47 /// Description of the page.
48 pub description: String,
49 /// Optional. Name of the author, displayed below the title.
50 pub author_name: Option<String>,
51 /// Optional. Profile link, opened when users click on the author's name below the title.
52 ///
53 /// Can be any link, not necessarily to a Telegram profile or channel.
54 pub author_url: Option<String>,
55 /// Optional. Image URL of the page.
56 pub image_url: Option<String>,
57 /// Optional. Content of the page.
58 pub content: Option<Vec<Node>>,
59 /// Number of page views for the page.
60 pub views: i32,
61 /// Optional. Only returned if access_token passed.
62 ///
63 /// True, if the target Telegraph account can edit the page.
64 pub can_edit: Option<bool>,
65}
66
67/// This object represents the number of page views for a Telegraph article.
68#[derive(Debug, Clone, Deserialize)]
69pub struct PageViews {
70 /// Number of page views for the target page.
71 pub views: i32,
72}
73
74/// This abstract object represents a DOM Node.
75///
76/// It can be a String which represents a DOM text node or a NodeElement object.
77#[derive(Debug, Clone, Deserialize, Serialize)]
78#[serde(untagged)]
79pub enum Node {
80 Text(String),
81 NodeElement(NodeElement),
82}
83
84/// This object represents a DOM element node.
85#[derive(Debug, Clone, Deserialize, Serialize)]
86pub struct NodeElement {
87 /// Name of the DOM element.
88 /// Available tags: a, aside, b, blockquote, br, code, em, figcaption, figure, h3, h4, hr, i, iframe, img, li, ol, p, pre, s, strong, u, ul, video.
89 pub tag: String,
90 /// Optional. Attributes of the DOM element.
91 ///
92 /// Key of object represents name of attribute, value represents value of attribute.
93 ///
94 /// Available attributes: href, src.
95 #[serde(skip_serializing_if = "Option::is_none")]
96 pub attrs: Option<HashMap<String, Option<String>>>,
97 /// Optional. List of child nodes for the DOM element.
98 #[serde(skip_serializing_if = "Option::is_none")]
99 pub children: Option<Vec<Node>>,
100}
101
102/// This object represents the upload result
103#[derive(Debug, Clone, Deserialize)]
104#[serde(untagged)]
105pub enum UploadResult {
106 Error { error: String },
107 Source(Vec<ImageInfo>),
108}
109
110#[derive(Debug, Clone, Deserialize)]
111pub struct ImageInfo {
112 /// Path of the file uploaded.
113 pub src: String,
114}