slack_morphism/
token.rs

1use rsb_derive::Builder;
2use rvstruct::ValueStruct;
3use serde::{Deserialize, Serialize};
4use serde_with::skip_serializing_none;
5
6use crate::models::{SlackApiTokenScope, SlackTeamId};
7
8#[derive(Eq, PartialEq, Hash, Clone, Serialize, Deserialize, ValueStruct)]
9pub struct SlackApiTokenValue(pub String);
10
11impl std::fmt::Debug for SlackApiTokenValue {
12    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13        write!(f, "SlackApiTokenValue(len:{})", self.value().len())
14    }
15}
16
17#[derive(Eq, PartialEq, Hash, Clone, Serialize, Deserialize, ValueStruct)]
18pub struct SlackApiCookieValue(pub String);
19
20impl std::fmt::Debug for SlackApiCookieValue {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        write!(f, "SlackApiCookieValue(len:{})", self.value().len())
23    }
24}
25
26#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize)]
27pub enum SlackApiTokenType {
28    #[serde(rename = "bot")]
29    Bot,
30    #[serde(rename = "user")]
31    User,
32    #[serde(rename = "app")]
33    App,
34}
35
36#[allow(clippy::to_string_trait_impl)]
37impl ToString for SlackApiTokenType {
38    fn to_string(&self) -> String {
39        match self {
40            SlackApiTokenType::Bot => "bot".into(),
41            SlackApiTokenType::User => "user".into(),
42            SlackApiTokenType::App => "app".into(),
43        }
44    }
45}
46
47#[skip_serializing_none]
48#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Builder)]
49pub struct SlackApiToken {
50    pub token_value: SlackApiTokenValue,
51    pub cookie: Option<SlackApiCookieValue>,
52    pub team_id: Option<SlackTeamId>,
53    pub scope: Option<SlackApiTokenScope>,
54    pub token_type: Option<SlackApiTokenType>,
55}