tweechat_datatypes/
lib.rs

1#![deny(clippy::cargo)]
2use serde::{Deserialize, Serialize};
3
4/// User object
5#[derive(Deserialize, Serialize, Clone, Debug)]
6pub struct User {
7    pub name: String,
8    pub id: u128,
9}
10
11/// May be returned for any endpoint when said endpoint has a failure
12#[derive(Deserialize, Serialize, Clone, Debug)]
13pub struct ApiError {
14    pub error: String,
15}
16
17/// Returned by the /auth/token and /auth/totp routes. Always use /auth/token first, you will be granted a temporary Bearer token if needs_totp is true, you can then call /auth/totp with the Bearer token and TOTP authcode.
18#[derive(Deserialize, Serialize, Clone, Debug)]
19pub struct LoginResponse {
20    pub token: String,
21    pub needs_totp: bool,
22}
23
24/// For requesting to the /auth/totp route. You must also have a temporary TOTP authtoken first!
25#[derive(Deserialize, Serialize, Clone, Debug)]
26pub struct TotpRequest {
27    pub code: String,
28}
29
30#[derive(Deserialize, Serialize, Clone, Debug)]
31pub struct MessageCreate {
32    pub contents: String,
33    pub author: User,
34    pub created: u64,
35}
36
37#[derive(Serialize, Deserialize)]
38pub struct UserCreate {
39    pub email: String,
40    pub name: String,
41    pub password: String,
42    pub pubkey: String,
43    pub privkey: String,
44    pub security_level: UserSecurityLevel,
45}
46
47#[derive(Serialize, Deserialize)]
48pub enum UserSecurityLevel {
49    Max,
50    Reasonable,
51    Low,
52}
53
54impl ToString for UserSecurityLevel {
55    fn to_string(&self) -> String {
56        match self {
57            Self::Max => "Max".to_string(),
58            Self::Reasonable => "Reasonable".to_string(),
59            Self::Low => "Low".to_string(),
60        }
61    }
62}