From ab1e5f86f03d13d44541f2ccb444877346440392 Mon Sep 17 00:00:00 2001 From: TheBestJohn Date: Sat, 10 Feb 2018 13:22:30 -0500 Subject: [PATCH] Fixed the registration of new apps as well as url of statuses is now an Option (#23) * Changes IDs to Strings for compliance with APIv1 * - Changed Scope to Scopes to coencide with a quirk of the Mastodon API. Initial registration of the app asks for "Scopes" and authorization asks for "Scope" - Swapped spaces for urlencoded spaces in the scopes serde definition to prevent broken links - url of status is returned as a Map not a string" * Fixed tests and updated Version number * Fixed tests and verified now... learning experience --- Cargo.toml | 1 + README.md | 2 +- src/apps.rs | 22 +++++++++++----------- src/entities/status.rs | 2 +- src/lib.rs | 4 ++-- src/registration.rs | 11 +++++------ 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 336c0f2..1a3269e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "mammut" version = "0.9.1" + description = "A wrapper around the Mastodon API." authors = ["Aaron Power "] license = "MIT/Apache-2.0" diff --git a/README.md b/README.md index 1980e51..d5b23c4 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ fn run() -> mammut::Result<()> { let app = AppBuilder { client_name: "mammut_test", redirect_uris: "urn:ietf:wg:oauth:2.0:oob", - scopes: Scope::Read, + scopes: Scopes::Read, website: None, }; diff --git a/src/apps.rs b/src/apps.rs index 56fa321..8ac8dcd 100644 --- a/src/apps.rs +++ b/src/apps.rs @@ -5,7 +5,7 @@ use std::fmt; /// let app = AppBuilder { /// client_name: "mammut_test", /// redirect_uris: "urn:ietf:wg:oauth:2.0:oob", -/// scopes: Scope::Read, +/// scopes: Scopes::Read, /// website: None, /// }; /// ``` @@ -18,7 +18,7 @@ pub struct AppBuilder<'a> { /// (for no redirect, use `urn:ietf:wg:oauth:2.0:oob`) pub redirect_uris: &'a str, /// Permission scope of the application. - pub scopes: Scope, + pub scopes: Scopes, /// URL to the homepage of your application. #[serde(skip_serializing_if="Option::is_none")] pub website: Option<&'a str>, @@ -27,7 +27,7 @@ pub struct AppBuilder<'a> { /// Permission scope of the application. /// [Details on what each permission provides](//github.com/tootsuite/documentation/blob/master/Using-the-API/OAuth-details.md) #[derive(Debug, Clone, Copy, Serialize)] -pub enum Scope { +pub enum Scopes { /// All Permissions, equivalent to `read write follow` #[serde(rename = "read write follow")] All, @@ -51,23 +51,23 @@ pub enum Scope { WriteFollow, } -impl fmt::Display for Scope { +impl fmt::Display for Scopes { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use self::Scope::*; + use self::Scopes::*; write!(f, "{}", match *self { - All => "read write follow", + All => "read%20write%20follow", Follow => "follow", Read => "read", - ReadFollow => "read follow", - ReadWrite => "read write", + ReadFollow => "read%20follow", + ReadWrite => "read%20write", Write => "write", - WriteFollow => "write follow" + WriteFollow => "write%20follow" }) } } -impl Default for Scope { +impl Default for Scopes { fn default() -> Self { - Scope::Read + Scopes::Read } } diff --git a/src/entities/status.rs b/src/entities/status.rs index e78d7c7..fdd9d87 100644 --- a/src/entities/status.rs +++ b/src/entities/status.rs @@ -12,7 +12,7 @@ pub struct Status { /// A Fediverse-unique resource ID. pub uri: String, /// URL to the status page (can be remote) - pub url: String, + pub url: Option, /// The Account which posted the status. pub account: Account, /// The ID of the status this status is replying to, if the status is diff --git a/src/lib.rs b/src/lib.rs index eaaf837..cb0133b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,12 +10,12 @@ //! # } //! # fn try() -> mammut::Result<()> { //! use mammut::Registration; -//! use mammut::apps::{AppBuilder, Scope}; +//! use mammut::apps::{AppBuilder, Scopes}; //! //! let app = AppBuilder { //! client_name: "mammut_test", //! redirect_uris: "urn:ietf:wg:oauth:2.0:oob", -//! scopes: Scope::Read, +//! scopes: Scopes::Read, //! website: None, //! }; //! diff --git a/src/registration.rs b/src/registration.rs index 9c44326..3f3a8ea 100644 --- a/src/registration.rs +++ b/src/registration.rs @@ -1,7 +1,7 @@ use reqwest::Client; use super::{Error, Mastodon, Result}; -use apps::{AppBuilder, Scope}; +use apps::{AppBuilder, Scopes}; /// Handles registering your mastodon app to your instance. It is recommended /// you cache your data struct to avoid registering on every run. @@ -11,7 +11,7 @@ pub struct Registration { client_id: Option, client_secret: Option, redirect: Option, - scopes: Scope, + scopes: Scopes, } #[derive(Deserialize)] @@ -38,7 +38,7 @@ impl Registration { client_id: None, client_secret: None, redirect: None, - scopes: Scope::Read, + scopes: Scopes::Read, } } @@ -51,12 +51,12 @@ impl Registration { /// # } /// # fn try() -> mammut::Result<()> { /// use mammut::Registration; - /// use mammut::apps::{AppBuilder, Scope}; + /// use mammut::apps::{AppBuilder, Scopes}; /// /// let app = AppBuilder { /// client_name: "mammut_test", /// redirect_uris: "urn:ietf:wg:oauth:2.0:oob", - /// scopes: Scope::Read, + /// scopes: Scopes::Read, /// website: None, /// }; /// @@ -75,7 +75,6 @@ impl Registration { pub fn register(&mut self, app_builder: AppBuilder) -> Result<()> { let url = format!("{}/api/v1/apps", self.base); self.scopes = app_builder.scopes; - let app: OAuth = self.client.post(&url).form(&app_builder).send()?.json()?; self.client_id = Some(app.client_id);