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
master
TheBestJohn 7 years ago committed by Aaron Power
parent 0b5441e52c
commit ab1e5f86f0
  1. 1
      Cargo.toml
  2. 2
      README.md
  3. 22
      src/apps.rs
  4. 2
      src/entities/status.rs
  5. 4
      src/lib.rs
  6. 11
      src/registration.rs

@ -1,6 +1,7 @@
[package]
name = "mammut"
version = "0.9.1"
description = "A wrapper around the Mastodon API."
authors = ["Aaron Power <theaaronepower@gmail.com>"]
license = "MIT/Apache-2.0"

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

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

@ -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<String>,
/// The Account which posted the status.
pub account: Account,
/// The ID of the status this status is replying to, if the status is

@ -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,
//! };
//!

@ -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<String>,
client_secret: Option<String>,
redirect: Option<String>,
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);

Loading…
Cancel
Save