summaryrefslogtreecommitdiffstats
path: root/src/apps.rs
diff options
context:
space:
mode:
authorPaul Woolcock <paul@woolcock.us>2018-08-29 13:52:35 -0400
committerPaul Woolcock <paul@woolcock.us>2018-08-30 19:12:16 -0400
commitaf806b7856c974935046e18b627c6dd3e999b9fa (patch)
treed562429e3853e733e15b9c94f03a9ab614e95081 /src/apps.rs
parent57cc44368c46ab0c1b3d44d9aa843699c00fa130 (diff)
move Scopes to their own module
Diffstat (limited to 'src/apps.rs')
-rw-r--r--src/apps.rs91
1 files changed, 2 insertions, 89 deletions
diff --git a/src/apps.rs b/src/apps.rs
index 2607a21..c1bd06e 100644
--- a/src/apps.rs
+++ b/src/apps.rs
@@ -1,7 +1,8 @@
-use std::{borrow::Cow, fmt};
+use std::borrow::Cow;
use try_from::TryInto;
+use scopes::Scopes;
use errors::{Error, Result};
/// Represents an application that can be registered with a mastodon instance
@@ -144,59 +145,6 @@ impl<'a> TryInto<App> for AppBuilder<'a> {
}
}
-/// Permission scope of the application.
-/// [Details on what each permission provides][1]
-/// [1]: https://github.com/tootsuite/documentation/blob/master/Using-the-API/OAuth-details.md)
-#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
-pub enum Scopes {
- /// All Permissions, equivalent to `read write follow`
- #[serde(rename = "read write follow")]
- All,
- /// Only permission to add and remove followers.
- #[serde(rename = "follow")]
- Follow,
- /// Read only permissions.
- #[serde(rename = "read")]
- Read,
- /// Read & Follow permissions.
- #[serde(rename = "read follow")]
- ReadFollow,
- /// Read & Write permissions.
- #[serde(rename = "read write")]
- ReadWrite,
- /// Write only permissions.
- #[serde(rename = "write")]
- Write,
- /// Write & Follow permissions.
- #[serde(rename = "write follow")]
- WriteFollow,
-}
-
-impl fmt::Display for Scopes {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use self::Scopes::*;
- write!(
- f,
- "{}",
- match *self {
- All => "read%20write%20follow",
- Follow => "follow",
- Read => "read",
- ReadFollow => "read%20follow",
- ReadWrite => "read%20write",
- Write => "write",
- WriteFollow => "write%20follow",
- }
- )
- }
-}
-
-impl Default for Scopes {
- fn default() -> Self {
- Scopes::Read
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
@@ -283,39 +231,4 @@ mod tests {
assert_eq!(expected, result);
}
- #[test]
- fn test_scopes_display() {
- let values = [
- Scopes::All,
- Scopes::Follow,
- Scopes::Read,
- Scopes::ReadFollow,
- Scopes::ReadWrite,
- Scopes::Write,
- Scopes::WriteFollow,
- ];
-
- let expecteds = [
- "read%20write%20follow".to_string(),
- "follow".to_string(),
- "read".to_string(),
- "read%20follow".to_string(),
- "read%20write".to_string(),
- "write".to_string(),
- "write%20follow".to_string(),
- ];
-
- let tests = values.into_iter().zip(expecteds.into_iter());
-
- for (value, expected) in tests {
- let result = value.to_string();
- assert_eq!(&result, expected);
- }
- }
-
- #[test]
- fn test_scopes_default() {
- let default: Scopes = Default::default();
- assert_eq!(default, Scopes::Read);
- }
}