use crate::client::SlackClient;
use crate::error::Result;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub struct EmojiApi {
client: SlackClient,
}
impl EmojiApi {
pub(crate) fn new(client: SlackClient) -> Self {
Self { client }
}
pub async fn list(&self) -> Result<EmojiListResponse> {
let params: [(&str, &str); 0] = [];
self.client.get("emoji.list", ¶ms).await
}
pub async fn add(&self, name: &str, url: &str) -> Result<EmojiAddResponse> {
let params = EmojiAddRequest {
name: name.to_string(),
url: url.to_string(),
};
self.client.post("admin.emoji.add", ¶ms).await
}
pub async fn add_alias(&self, name: &str, alias_for: &str) -> Result<EmojiAddResponse> {
let params = EmojiAddAliasRequest {
name: name.to_string(),
alias_for: alias_for.to_string(),
};
self.client.post("admin.emoji.addAlias", ¶ms).await
}
pub async fn remove(&self, name: &str) -> Result<EmojiRemoveResponse> {
let params = EmojiRemoveRequest {
name: name.to_string(),
};
self.client.post("admin.emoji.remove", ¶ms).await
}
pub async fn rename(&self, name: &str, new_name: &str) -> Result<EmojiRenameResponse> {
let params = EmojiRenameRequest {
name: name.to_string(),
new_name: new_name.to_string(),
};
self.client.post("admin.emoji.rename", ¶ms).await
}
pub async fn admin_list(&self) -> Result<EmojiAdminListResponse> {
let params = EmojiAdminListRequest {
cursor: None,
limit: Some(100),
};
self.client.post("admin.emoji.list", ¶ms).await
}
}
#[derive(Debug, Deserialize)]
pub struct EmojiListResponse {
pub emoji: HashMap<String, String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cache_ts: Option<String>,
}
#[derive(Debug, Serialize)]
pub struct EmojiAddRequest {
pub name: String,
pub url: String,
}
#[derive(Debug, Deserialize)]
pub struct EmojiAddResponse {}
#[derive(Debug, Serialize)]
pub struct EmojiAddAliasRequest {
pub name: String,
pub alias_for: String,
}
#[derive(Debug, Serialize)]
pub struct EmojiRemoveRequest {
pub name: String,
}
#[derive(Debug, Deserialize)]
pub struct EmojiRemoveResponse {}
#[derive(Debug, Serialize)]
pub struct EmojiRenameRequest {
pub name: String,
pub new_name: String,
}
#[derive(Debug, Deserialize)]
pub struct EmojiRenameResponse {}
#[derive(Debug, Serialize)]
pub struct EmojiAdminListRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u32>,
}
#[derive(Debug, Deserialize)]
pub struct EmojiAdminListResponse {
pub emoji: Vec<AdminEmoji>,
#[serde(skip_serializing_if = "Option::is_none")]
pub response_metadata: Option<crate::types::ResponseMetadata>,
}
#[derive(Debug, Deserialize)]
pub struct AdminEmoji {
pub name: String,
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub date_created: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub uploaded_by: Option<String>,
}