move Scopes to their own module
This commit is contained in:
+2
-89
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -102,13 +102,15 @@ pub mod page;
|
||||
pub mod registration;
|
||||
/// Requests
|
||||
pub mod requests;
|
||||
/// OAuth Scopes
|
||||
pub mod scopes;
|
||||
/// Constructing a status
|
||||
pub mod status_builder;
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
/// Automatically import the things you need
|
||||
pub mod prelude {
|
||||
pub use apps::Scopes;
|
||||
pub use scopes::Scopes;
|
||||
pub use Data;
|
||||
pub use Mastodon;
|
||||
pub use MastodonClient;
|
||||
|
||||
+2
-1
@@ -3,7 +3,8 @@ use std::borrow::Cow;
|
||||
use reqwest::{Client, RequestBuilder, Response};
|
||||
use try_from::TryInto;
|
||||
|
||||
use apps::{App, AppBuilder, Scopes};
|
||||
use apps::{App, AppBuilder};
|
||||
use scopes::Scopes;
|
||||
use http_send::{HttpSend, HttpSender};
|
||||
use Data;
|
||||
use Error;
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
use std::fmt;
|
||||
|
||||
/// 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, Hash, 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::*;
|
||||
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user