Version 0.10.0-rc1

- Added the ability to handle paged entities like favourites and such.
  (Only favourites in prerelease)
- Added optional `source` and `moved` fields to `Account`.
- Added `Source` struct to match with the `Account.source` field.
- Added `CredientialsBuilder` struct for updating profile using
  `verify_credientials`.
- Attachment now handles being sent an empty object, which is converted
  to `None`.
- Added ombed data fields to `Card`.
- Added `version` and `urls` fields to `Instance`.
- Added `id`, `muting_notifications`, and `domain_blocking` to `Relationship`.
- Added `emojis`, `language`, and `pinned` fields to `Status`
- Added `Emoji` struct.
- Added `List` and `Mention` structs(matching routes not added yet).
- Added example that prints your profile.
This commit is contained in:
Aaron Power
2018-02-12 00:09:23 +00:00
parent ab1e5f86f0
commit 4984dfaacf
15 changed files with 367 additions and 25 deletions
+58
View File
@@ -1,6 +1,9 @@
//! A module containing everything relating to a account returned from the api.
use chrono::prelude::*;
use reqwest::multipart::Form;
use ::Result;
use std::path::Path;
/// A struct representing an Account.
#[derive(Debug, Clone, Deserialize)]
@@ -36,4 +39,59 @@ pub struct Account {
pub url: String,
/// The username of the account.
pub username: String,
/// An extra attribute given from `verify_credentials` giving defaults about
/// a user
pub source: Option<Source>,
/// If the owner decided to switch accounts, new account is in
/// this attribute
pub moved: Option<String>,
}
/// An extra object given from `verify_credentials` giving defaults about a user
#[derive(Debug, Clone, Deserialize)]
pub struct Source {
privacy: ::status_builder::Visibility,
sensitive: bool,
note: String,
}
pub struct CredientialsBuilder<'a> {
display_name: Option<&'a str>,
note: Option<&'a str>,
avatar: Option<&'a Path>,
header: Option<&'a Path>,
}
impl<'a> CredientialsBuilder<'a> {
pub fn into_form(self) -> Result<Form> {
let mut form = Form::new();
macro_rules! add_to_form {
($key:ident : Text; $($rest:tt)*) => {{
if let Some(val) = self.$key {
form = form.text(stringify!($key), val.to_owned());
}
add_to_form!{$($rest)*}
}};
($key:ident : File; $($rest:tt)*) => {{
if let Some(val) = self.$key {
form = form.file(stringify!($key), val)?;
}
add_to_form!{$($rest)*}
}};
() => {}
}
add_to_form! {
display_name: Text;
note: Text;
avatar: File;
header: File;
}
Ok(form)
}
}
+19
View File
@@ -1,4 +1,6 @@
//! Module containing everything related to media attachements.
use serde::{Deserialize, Deserializer};
use super::Empty;
/// A struct representing a media attachment.
#[derive(Debug, Clone, Deserialize)]
@@ -18,11 +20,28 @@ pub struct Attachment {
/// (only present on local images)
pub text_url: Option<String>,
/// Meta information about the attachment.
#[serde(deserialize_with="empty_as_none")]
pub meta: Option<Meta>,
/// Noop will be removed.
pub description: Option<String>,
}
fn empty_as_none<'de, D: Deserializer<'de>>(val: D)
-> Result<Option<Meta>, D::Error>
{
#[derive(Deserialize)]
#[serde(untagged)]
enum EmptyOrMeta {
Empty(Empty),
Meta(Meta),
}
Ok(match EmptyOrMeta::deserialize(val)? {
EmptyOrMeta::Empty(_) => None,
EmptyOrMeta::Meta(m) => Some(m),
})
}
/// Information about the attachment itself.
#[derive(Debug, Deserialize, Clone)]
pub struct Meta {
+15 -1
View File
@@ -10,5 +10,19 @@ pub struct Card {
/// The card description.
pub description: String,
/// The image associated with the card, if any.
pub image: String,
pub image: Option<String>,
/// OEmbed data
author_name: Option<String>,
/// OEmbed data
author_url: Option<String>,
/// OEmbed data
provider_name: Option<String>,
/// OEmbed data
provider_url: Option<String>,
/// OEmbed data
html: Option<String>,
/// OEmbed data
width: Option<String>,
/// OEmbed data
height: Option<String>,
}
+4
View File
@@ -12,4 +12,8 @@ pub struct Instance {
/// An email address which can be used to contact the
/// instance administrator.
pub email: String,
/// The Mastodon version used by instance.
pub version: String,
/// `streaming_api`
pub urls: Vec<String>,
}
+5
View File
@@ -0,0 +1,5 @@
#[derive(Clone, Debug, Deserialize)]
pub struct List {
id: String,
title: String,
}
+10
View File
@@ -0,0 +1,10 @@
pub struct Mention {
/// URL of user's profile (can be remote)
pub url: String,
/// The username of the account
pub username: String,
/// Equals username for local users, includes `@domain` for remote ones
pub acct: String,
/// Account ID
pub id: String,
}
+6 -2
View File
@@ -3,6 +3,8 @@ pub mod attachment;
pub mod card;
pub mod context;
pub mod instance;
pub mod list;
pub mod mention;
pub mod notification;
pub mod relationship;
pub mod report;
@@ -17,14 +19,16 @@ pub mod prelude {
//! The purpose of this module is to alleviate imports of many common structs
//! by adding a glob import to the top of mastodon heavy modules:
pub use super::Empty;
pub use super::account::Account;
pub use super::account::{Account, CredientialsBuilder, Source};
pub use super::attachment::{Attachment, MediaType};
pub use super::card::Card;
pub use super::context::Context;
pub use super::instance::Instance;
pub use super::list::List;
pub use super::mention::Mention;
pub use super::notification::Notification;
pub use super::relationship::Relationship;
pub use super::report::Report;
pub use super::search_result::SearchResult;
pub use super::status::{Status, Application};
pub use super::status::{Application, Emoji, Status};
}
+6
View File
@@ -4,6 +4,8 @@
/// A struct containing information about a relationship with another account.
#[derive(Debug, Clone, Deserialize)]
pub struct Relationship {
/// Target account id
pub id: String,
/// Whether the application client follows the account.
pub following: bool,
/// Whether the account follows the application client.
@@ -14,4 +16,8 @@ pub struct Relationship {
pub muting: bool,
/// Whether the application client has requested to follow the account.
pub requested: bool,
/// Whether the user is also muting notifications
pub muting_notifications: bool,
/// Whether the user is currently blocking the accounts's domain
pub domain_blocking: bool,
}
+17
View File
@@ -28,6 +28,8 @@ pub struct Status {
pub content: String,
/// The time the status was created.
pub created_at: DateTime<Utc>,
/// An array of Emoji
pub emojis: Vec<Emoji>,
/// The number of reblogs for the status.
pub reblogs_count: u64,
/// The number of favourites for the status.
@@ -51,6 +53,10 @@ pub struct Status {
pub tags: Vec<Tag>,
/// Name of application used to post status.
pub application: Option<Application>,
/// The detected language for the status, if detected.
pub language: Option<String>,
/// Whether this is the pinned status for the account that posted it.
pub pinned: Option<bool>,
}
/// A mention of another user.
@@ -66,6 +72,17 @@ pub struct Mention {
pub id: String,
}
/// Struct representing an emoji within text.
#[derive(Clone, Debug, Deserialize)]
pub struct Emoji {
/// The shortcode of the emoji
pub shortcode: String,
/// URL to the emoji static image
pub static_url: String,
/// URL to the emoji image
pub url: String,
}
/// Hashtags in the status.
#[derive(Debug, Clone, Deserialize)]
pub struct Tag {