Fixed the registration of new apps as well as url of statuses is now an Option<String> (#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
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mammut"
|
name = "mammut"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
|
|
||||||
description = "A wrapper around the Mastodon API."
|
description = "A wrapper around the Mastodon API."
|
||||||
authors = ["Aaron Power <theaaronepower@gmail.com>"]
|
authors = ["Aaron Power <theaaronepower@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ fn run() -> mammut::Result<()> {
|
|||||||
let app = AppBuilder {
|
let app = AppBuilder {
|
||||||
client_name: "mammut_test",
|
client_name: "mammut_test",
|
||||||
redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
||||||
scopes: Scope::Read,
|
scopes: Scopes::Read,
|
||||||
website: None,
|
website: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -5,7 +5,7 @@ use std::fmt;
|
|||||||
/// let app = AppBuilder {
|
/// let app = AppBuilder {
|
||||||
/// client_name: "mammut_test",
|
/// client_name: "mammut_test",
|
||||||
/// redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
/// redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
||||||
/// scopes: Scope::Read,
|
/// scopes: Scopes::Read,
|
||||||
/// website: None,
|
/// website: None,
|
||||||
/// };
|
/// };
|
||||||
/// ```
|
/// ```
|
||||||
@@ -18,7 +18,7 @@ pub struct AppBuilder<'a> {
|
|||||||
/// (for no redirect, use `urn:ietf:wg:oauth:2.0:oob`)
|
/// (for no redirect, use `urn:ietf:wg:oauth:2.0:oob`)
|
||||||
pub redirect_uris: &'a str,
|
pub redirect_uris: &'a str,
|
||||||
/// Permission scope of the application.
|
/// Permission scope of the application.
|
||||||
pub scopes: Scope,
|
pub scopes: Scopes,
|
||||||
/// URL to the homepage of your application.
|
/// URL to the homepage of your application.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub website: Option<&'a str>,
|
pub website: Option<&'a str>,
|
||||||
@@ -27,7 +27,7 @@ pub struct AppBuilder<'a> {
|
|||||||
/// Permission scope of the application.
|
/// Permission scope of the application.
|
||||||
/// [Details on what each permission provides](//github.com/tootsuite/documentation/blob/master/Using-the-API/OAuth-details.md)
|
/// [Details on what each permission provides](//github.com/tootsuite/documentation/blob/master/Using-the-API/OAuth-details.md)
|
||||||
#[derive(Debug, Clone, Copy, Serialize)]
|
#[derive(Debug, Clone, Copy, Serialize)]
|
||||||
pub enum Scope {
|
pub enum Scopes {
|
||||||
/// All Permissions, equivalent to `read write follow`
|
/// All Permissions, equivalent to `read write follow`
|
||||||
#[serde(rename = "read write follow")]
|
#[serde(rename = "read write follow")]
|
||||||
All,
|
All,
|
||||||
@@ -51,23 +51,23 @@ pub enum Scope {
|
|||||||
WriteFollow,
|
WriteFollow,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Scope {
|
impl fmt::Display for Scopes {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::Scope::*;
|
use self::Scopes::*;
|
||||||
write!(f, "{}", match *self {
|
write!(f, "{}", match *self {
|
||||||
All => "read write follow",
|
All => "read%20write%20follow",
|
||||||
Follow => "follow",
|
Follow => "follow",
|
||||||
Read => "read",
|
Read => "read",
|
||||||
ReadFollow => "read follow",
|
ReadFollow => "read%20follow",
|
||||||
ReadWrite => "read write",
|
ReadWrite => "read%20write",
|
||||||
Write => "write",
|
Write => "write",
|
||||||
WriteFollow => "write follow"
|
WriteFollow => "write%20follow"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Scope {
|
impl Default for Scopes {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Scope::Read
|
Scopes::Read
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ pub struct Status {
|
|||||||
/// A Fediverse-unique resource ID.
|
/// A Fediverse-unique resource ID.
|
||||||
pub uri: String,
|
pub uri: String,
|
||||||
/// URL to the status page (can be remote)
|
/// URL to the status page (can be remote)
|
||||||
pub url: String,
|
pub url: Option<String>,
|
||||||
/// The Account which posted the status.
|
/// The Account which posted the status.
|
||||||
pub account: Account,
|
pub account: Account,
|
||||||
/// The ID of the status this status is replying to, if the status is
|
/// The ID of the status this status is replying to, if the status is
|
||||||
|
|||||||
+2
-2
@@ -10,12 +10,12 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! # fn try() -> mammut::Result<()> {
|
//! # fn try() -> mammut::Result<()> {
|
||||||
//! use mammut::Registration;
|
//! use mammut::Registration;
|
||||||
//! use mammut::apps::{AppBuilder, Scope};
|
//! use mammut::apps::{AppBuilder, Scopes};
|
||||||
//!
|
//!
|
||||||
//! let app = AppBuilder {
|
//! let app = AppBuilder {
|
||||||
//! client_name: "mammut_test",
|
//! client_name: "mammut_test",
|
||||||
//! redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
//! redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
||||||
//! scopes: Scope::Read,
|
//! scopes: Scopes::Read,
|
||||||
//! website: None,
|
//! website: None,
|
||||||
//! };
|
//! };
|
||||||
//!
|
//!
|
||||||
|
|||||||
+5
-6
@@ -1,7 +1,7 @@
|
|||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
|
||||||
use super::{Error, Mastodon, Result};
|
use super::{Error, Mastodon, Result};
|
||||||
use apps::{AppBuilder, Scope};
|
use apps::{AppBuilder, Scopes};
|
||||||
|
|
||||||
/// Handles registering your mastodon app to your instance. It is recommended
|
/// Handles registering your mastodon app to your instance. It is recommended
|
||||||
/// you cache your data struct to avoid registering on every run.
|
/// you cache your data struct to avoid registering on every run.
|
||||||
@@ -11,7 +11,7 @@ pub struct Registration {
|
|||||||
client_id: Option<String>,
|
client_id: Option<String>,
|
||||||
client_secret: Option<String>,
|
client_secret: Option<String>,
|
||||||
redirect: Option<String>,
|
redirect: Option<String>,
|
||||||
scopes: Scope,
|
scopes: Scopes,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@@ -38,7 +38,7 @@ impl Registration {
|
|||||||
client_id: None,
|
client_id: None,
|
||||||
client_secret: None,
|
client_secret: None,
|
||||||
redirect: None,
|
redirect: None,
|
||||||
scopes: Scope::Read,
|
scopes: Scopes::Read,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,12 +51,12 @@ impl Registration {
|
|||||||
/// # }
|
/// # }
|
||||||
/// # fn try() -> mammut::Result<()> {
|
/// # fn try() -> mammut::Result<()> {
|
||||||
/// use mammut::Registration;
|
/// use mammut::Registration;
|
||||||
/// use mammut::apps::{AppBuilder, Scope};
|
/// use mammut::apps::{AppBuilder, Scopes};
|
||||||
///
|
///
|
||||||
/// let app = AppBuilder {
|
/// let app = AppBuilder {
|
||||||
/// client_name: "mammut_test",
|
/// client_name: "mammut_test",
|
||||||
/// redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
/// redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
||||||
/// scopes: Scope::Read,
|
/// scopes: Scopes::Read,
|
||||||
/// website: None,
|
/// website: None,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
@@ -75,7 +75,6 @@ impl Registration {
|
|||||||
pub fn register(&mut self, app_builder: AppBuilder) -> Result<()> {
|
pub fn register(&mut self, app_builder: AppBuilder) -> Result<()> {
|
||||||
let url = format!("{}/api/v1/apps", self.base);
|
let url = format!("{}/api/v1/apps", self.base);
|
||||||
self.scopes = app_builder.scopes;
|
self.scopes = app_builder.scopes;
|
||||||
|
|
||||||
let app: OAuth = self.client.post(&url).form(&app_builder).send()?.json()?;
|
let app: OAuth = self.client.post(&url).form(&app_builder).send()?.json()?;
|
||||||
|
|
||||||
self.client_id = Some(app.client_id);
|
self.client_id = Some(app.client_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user