rust_tdlib/types/
connected_website.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Contains information about one website the current user is logged in with Telegram
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct ConnectedWebsite {
8    #[doc(hidden)]
9    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10    extra: Option<String>,
11    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12    client_id: Option<i32>,
13    /// Website identifier
14
15    #[serde(
16        deserialize_with = "super::_common::number_from_string",
17        serialize_with = "super::_common::string_to_number"
18    )]
19    #[serde(default)]
20    id: i64,
21    /// The domain name of the website
22
23    #[serde(default)]
24    domain_name: String,
25    /// User identifier of a bot linked with the website
26
27    #[serde(default)]
28    bot_user_id: i64,
29    /// The version of a browser used to log in
30
31    #[serde(default)]
32    browser: String,
33    /// Operating system the browser is running on
34
35    #[serde(default)]
36    platform: String,
37    /// Point in time (Unix timestamp) when the user was logged in
38
39    #[serde(default)]
40    log_in_date: i32,
41    /// Point in time (Unix timestamp) when obtained authorization was last used
42
43    #[serde(default)]
44    last_active_date: i32,
45    /// IP address from which the user was logged in, in human-readable format
46
47    #[serde(default)]
48    ip: String,
49    /// Human-readable description of a country and a region, from which the user was logged in, based on the IP address
50
51    #[serde(default)]
52    location: String,
53}
54
55impl RObject for ConnectedWebsite {
56    #[doc(hidden)]
57    fn extra(&self) -> Option<&str> {
58        self.extra.as_deref()
59    }
60    #[doc(hidden)]
61    fn client_id(&self) -> Option<i32> {
62        self.client_id
63    }
64}
65
66impl ConnectedWebsite {
67    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
68        Ok(serde_json::from_str(json.as_ref())?)
69    }
70    pub fn builder() -> ConnectedWebsiteBuilder {
71        let mut inner = ConnectedWebsite::default();
72        inner.extra = Some(Uuid::new_v4().to_string());
73
74        ConnectedWebsiteBuilder { inner }
75    }
76
77    pub fn id(&self) -> i64 {
78        self.id
79    }
80
81    pub fn domain_name(&self) -> &String {
82        &self.domain_name
83    }
84
85    pub fn bot_user_id(&self) -> i64 {
86        self.bot_user_id
87    }
88
89    pub fn browser(&self) -> &String {
90        &self.browser
91    }
92
93    pub fn platform(&self) -> &String {
94        &self.platform
95    }
96
97    pub fn log_in_date(&self) -> i32 {
98        self.log_in_date
99    }
100
101    pub fn last_active_date(&self) -> i32 {
102        self.last_active_date
103    }
104
105    pub fn ip(&self) -> &String {
106        &self.ip
107    }
108
109    pub fn location(&self) -> &String {
110        &self.location
111    }
112}
113
114#[doc(hidden)]
115pub struct ConnectedWebsiteBuilder {
116    inner: ConnectedWebsite,
117}
118
119#[deprecated]
120pub type RTDConnectedWebsiteBuilder = ConnectedWebsiteBuilder;
121
122impl ConnectedWebsiteBuilder {
123    pub fn build(&self) -> ConnectedWebsite {
124        self.inner.clone()
125    }
126
127    pub fn id(&mut self, id: i64) -> &mut Self {
128        self.inner.id = id;
129        self
130    }
131
132    pub fn domain_name<T: AsRef<str>>(&mut self, domain_name: T) -> &mut Self {
133        self.inner.domain_name = domain_name.as_ref().to_string();
134        self
135    }
136
137    pub fn bot_user_id(&mut self, bot_user_id: i64) -> &mut Self {
138        self.inner.bot_user_id = bot_user_id;
139        self
140    }
141
142    pub fn browser<T: AsRef<str>>(&mut self, browser: T) -> &mut Self {
143        self.inner.browser = browser.as_ref().to_string();
144        self
145    }
146
147    pub fn platform<T: AsRef<str>>(&mut self, platform: T) -> &mut Self {
148        self.inner.platform = platform.as_ref().to_string();
149        self
150    }
151
152    pub fn log_in_date(&mut self, log_in_date: i32) -> &mut Self {
153        self.inner.log_in_date = log_in_date;
154        self
155    }
156
157    pub fn last_active_date(&mut self, last_active_date: i32) -> &mut Self {
158        self.inner.last_active_date = last_active_date;
159        self
160    }
161
162    pub fn ip<T: AsRef<str>>(&mut self, ip: T) -> &mut Self {
163        self.inner.ip = ip.as_ref().to_string();
164        self
165    }
166
167    pub fn location<T: AsRef<str>>(&mut self, location: T) -> &mut Self {
168        self.inner.location = location.as_ref().to_string();
169        self
170    }
171}
172
173impl AsRef<ConnectedWebsite> for ConnectedWebsite {
174    fn as_ref(&self) -> &ConnectedWebsite {
175        self
176    }
177}
178
179impl AsRef<ConnectedWebsite> for ConnectedWebsiteBuilder {
180    fn as_ref(&self) -> &ConnectedWebsite {
181        &self.inner
182    }
183}