1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#[allow(unused_imports)]
use std::collections::HashMap;
use std::convert::From;
use std::error::Error;
use std::fmt;
use serde_json;
use requests::SlackWebRequestSender;
pub fn list<R>(client: &R, token: &str) -> Result<ListResponse, ListError<R::Error>>
where R: SlackWebRequestSender
{
let params = &[("token", token)];
let url = ::get_slack_url_for_method("emoji.list");
client
.send(&url, ¶ms[..])
.map_err(|err| ListError::Client(err))
.and_then(|result| {
serde_json::from_str::<ListResponse>(&result)
.map_err(|e| ListError::MalformedResponse(e))
})
.and_then(|o| o.into())
}
#[derive(Clone, Debug, Deserialize)]
pub struct ListResponse {
pub emoji: Option<HashMap<String, bool>>,
error: Option<String>,
#[serde(default)]
ok: bool,
}
impl<E: Error> Into<Result<ListResponse, ListError<E>>> for ListResponse {
fn into(self) -> Result<ListResponse, ListError<E>> {
if self.ok {
Ok(self)
} else {
Err(self.error
.as_ref()
.map(String::as_ref)
.unwrap_or("")
.into())
}
}
}
#[derive(Debug)]
pub enum ListError<E: Error> {
NotAuthed,
InvalidAuth,
AccountInactive,
InvalidArgName,
InvalidArrayArg,
InvalidCharset,
InvalidFormData,
InvalidPostType,
MissingPostType,
TeamAddedToOrg,
RequestTimeout,
MalformedResponse(serde_json::error::Error),
Unknown(String),
Client(E),
}
impl<'a, E: Error> From<&'a str> for ListError<E> {
fn from(s: &'a str) -> Self {
match s {
"not_authed" => ListError::NotAuthed,
"invalid_auth" => ListError::InvalidAuth,
"account_inactive" => ListError::AccountInactive,
"invalid_arg_name" => ListError::InvalidArgName,
"invalid_array_arg" => ListError::InvalidArrayArg,
"invalid_charset" => ListError::InvalidCharset,
"invalid_form_data" => ListError::InvalidFormData,
"invalid_post_type" => ListError::InvalidPostType,
"missing_post_type" => ListError::MissingPostType,
"team_added_to_org" => ListError::TeamAddedToOrg,
"request_timeout" => ListError::RequestTimeout,
_ => ListError::Unknown(s.to_owned()),
}
}
}
impl<E: Error> fmt::Display for ListError<E> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl<E: Error> Error for ListError<E> {
fn description(&self) -> &str {
match self {
&ListError::NotAuthed => "not_authed: No authentication token provided.",
&ListError::InvalidAuth => "invalid_auth: Invalid authentication token.",
&ListError::AccountInactive => "account_inactive: Authentication token is for a deleted user or team.",
&ListError::InvalidArgName => "invalid_arg_name: The method was passed an argument whose name falls outside the bounds of common decency. This includes very long names and names with non-alphanumeric characters other than _. If you get this error, it is typically an indication that you have made a very malformed API call.",
&ListError::InvalidArrayArg => "invalid_array_arg: The method was passed a PHP-style array argument (e.g. with a name like foo[7]). These are never valid with the Slack API.",
&ListError::InvalidCharset => "invalid_charset: The method was called via a POST request, but the charset specified in the Content-Type header was invalid. Valid charset names are: utf-8 iso-8859-1.",
&ListError::InvalidFormData => "invalid_form_data: The method was called via a POST request with Content-Type application/x-www-form-urlencoded or multipart/form-data, but the form data was either missing or syntactically invalid.",
&ListError::InvalidPostType => "invalid_post_type: The method was called via a POST request, but the specified Content-Type was invalid. Valid types are: application/x-www-form-urlencoded multipart/form-data text/plain.",
&ListError::MissingPostType => "missing_post_type: The method was called via a POST request and included a data payload, but the request did not include a Content-Type header.",
&ListError::TeamAddedToOrg => "team_added_to_org: The team associated with your request is currently undergoing migration to an Enterprise Organization. Web API and other platform operations will be intermittently unavailable until the transition is complete.",
&ListError::RequestTimeout => "request_timeout: The method was called via a POST request, but the POST data was either missing or truncated.",
&ListError::MalformedResponse(ref e) => e.description(),
&ListError::Unknown(ref s) => s,
&ListError::Client(ref inner) => inner.description(),
}
}
fn cause(&self) -> Option<&Error> {
match self {
&ListError::MalformedResponse(ref e) => Some(e),
&ListError::Client(ref inner) => Some(inner),
_ => None,
}
}
}