mattermost_client/
client.rs1use crate::openapi::apis::configuration::Configuration;
2
3const DEFAULT_USER_AGENT: &str = concat!("mattermost-client/", env!("CARGO_PKG_VERSION"));
4
5pub struct Client {
11 configuration: Configuration,
12}
13
14impl Client {
15 pub fn new(base_url: impl Into<String>) -> Self {
16 let base_url: String = base_url.into();
17 let base_url = base_url.trim_end_matches("/");
18
19 Self {
20 configuration: Configuration {
21 base_path: base_url.to_owned(),
22 user_agent: Some(DEFAULT_USER_AGENT.into()),
23 ..Default::default()
24 },
25 }
26 }
27
28 pub fn with_user_agent(mut self, user_agent: impl Into<String>) -> Self {
29 self.set_user_agent(user_agent);
30 self
31 }
32
33 pub fn set_user_agent(&mut self, user_agent: impl Into<String>) -> &mut Self {
34 self.configuration.user_agent = Some(user_agent.into());
35 self
36 }
37
38 pub fn with_access_token(mut self, access_token: impl Into<String>) -> Self {
39 self.set_access_token(access_token);
40 self
41 }
42
43 pub fn set_access_token(&mut self, access_token: impl Into<String>) -> &mut Self {
44 self.configuration.bearer_access_token = Some(access_token.into());
45 self
46 }
47
48 pub fn configuration(&self) -> &Configuration {
49 &self.configuration
50 }
51
52 pub fn configuration_mut(&mut self) -> &mut Configuration {
53 &mut self.configuration
54 }
55}