move Scopes to their own module

master
Paul Woolcock 6 years ago
parent 57cc44368c
commit af806b7856
  1. 91
      src/apps.rs
  2. 4
      src/lib.rs
  3. 3
      src/registration.rs
  4. 95
      src/scopes.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);
}
}

@ -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;

@ -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);
}
}
Loading…
Cancel
Save