Document "everything"

This is a good start but many things need to be documented better, but
this will at least allow us to turn on #[deny(missing_docs)]
master
Paul Woolcock 6 years ago
parent 9e78d5ed46
commit 57cc44368c
  1. 29
      src/apps.rs
  2. 3
      src/entities/account.rs
  3. 1
      src/entities/list.rs
  4. 1
      src/entities/mention.rs
  5. 18
      src/entities/mod.rs
  6. 6
      src/http_send.rs
  7. 2
      src/lib.rs
  8. 7
      src/page.rs
  9. 11
      src/registration.rs
  10. 1
      src/requests/mod.rs
  11. 80
      src/requests/statuses.rs

@ -15,10 +15,38 @@ pub struct App {
} }
impl App { impl App {
/// Get an AppBuilder object
///
/// # Example
///
/// ```
/// # extern crate elefren;
/// use elefren::apps::App;
///
/// let mut builder = App::builder();
/// ```
pub fn builder<'a>() -> AppBuilder<'a> { pub fn builder<'a>() -> AppBuilder<'a> {
AppBuilder::new() AppBuilder::new()
} }
/// Retrieve the list of scopes that apply to this App
///
/// # Example
///
/// ```
/// # extern crate elefren;
/// # use elefren::Error;
/// use elefren::apps::{App, Scopes};
///
/// # fn main() -> Result<(), Error> {
/// let mut builder = App::builder();
/// builder.client_name("elefren-test");
/// let app = builder.build()?;
/// let scopes = app.scopes();
/// assert_eq!(scopes, Scopes::Read);
/// # Ok(())
/// # }
/// ```
pub fn scopes(&self) -> Scopes { pub fn scopes(&self) -> Scopes {
self.scopes self.scopes
} }
@ -45,6 +73,7 @@ pub struct AppBuilder<'a> {
} }
impl<'a> AppBuilder<'a> { impl<'a> AppBuilder<'a> {
/// Creates a new AppBuilder object
pub fn new() -> Self { pub fn new() -> Self {
Default::default() Default::default()
} }

@ -82,6 +82,7 @@ fn string_or_bool<'de, D: Deserializer<'de>>(val: D) -> ::std::result::Result<bo
}) })
} }
/// Data structure used for updating user credentials
#[derive(Debug)] #[derive(Debug)]
pub struct CredentialsBuilder<'a> { pub struct CredentialsBuilder<'a> {
display_name: Option<&'a str>, display_name: Option<&'a str>,
@ -91,6 +92,8 @@ pub struct CredentialsBuilder<'a> {
} }
impl<'a> CredentialsBuilder<'a> { impl<'a> CredentialsBuilder<'a> {
/// Turns a `CredentialsForm` into a form suitable for PUTing to the
/// endpoint
pub fn into_form(self) -> Result<Form> { pub fn into_form(self) -> Result<Form> {
let mut form = Form::new(); let mut form = Form::new();
macro_rules! add_to_form { macro_rules! add_to_form {

@ -1,3 +1,4 @@
/// Used for ser/de of list resources
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
pub struct List { pub struct List {
id: String, id: String,

@ -1,3 +1,4 @@
/// Represents a `mention` used in a status
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Mention { pub struct Mention {
/// URL of user's profile (can be remote) /// URL of user's profile (can be remote)

@ -1,25 +1,37 @@
/// Data structures for ser/de of account-related resources
pub mod account; pub mod account;
/// Data structures for ser/de of attachment-related resources
pub mod attachment; pub mod attachment;
/// Data structures for ser/de of card-related resources
pub mod card; pub mod card;
/// Data structures for ser/de of contetx-related resources
pub mod context; pub mod context;
/// Data structures for ser/de of instance-related resources
pub mod instance; pub mod instance;
pub(crate) mod itemsiter; pub(crate) mod itemsiter;
/// Data structures for ser/de of list-related resources
pub mod list; pub mod list;
/// Data structures for ser/de of mention-related resources
pub mod mention; pub mod mention;
/// Data structures for ser/de of notification-related resources
pub mod notification; pub mod notification;
/// Data structures for ser/de of relationship-related resources
pub mod relationship; pub mod relationship;
/// Data structures for ser/de of report-related resources
pub mod report; pub mod report;
/// Data structures for ser/de of search-related resources
pub mod search_result; pub mod search_result;
/// Data structures for ser/de of status-related resources
pub mod status; pub mod status;
/// An empty JSON object. /// An empty JSON object.
#[derive(Deserialize, Debug, Copy, Clone, PartialEq)] #[derive(Deserialize, Debug, Copy, Clone, PartialEq)]
pub struct Empty {} pub struct Empty {}
/// 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 mod prelude { 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::{ pub use super::{
account::{Account, CredentialsBuilder, Source}, account::{Account, CredentialsBuilder, Source},
attachment::{Attachment, MediaType}, attachment::{Attachment, MediaType},

@ -2,14 +2,20 @@ use reqwest::{Client, Request, RequestBuilder, Response};
use std::fmt::Debug; use std::fmt::Debug;
use Result; use Result;
/// Abstracts away the process of turning an HTTP request into an HTTP response
pub trait HttpSend: Clone + Debug { pub trait HttpSend: Clone + Debug {
/// Converts an HTTP request into an HTTP response
fn execute(&self, client: &Client, request: Request) -> Result<Response>; fn execute(&self, client: &Client, request: Request) -> Result<Response>;
/// Convenience method so that .build() doesn't have to be called at every
/// call site
fn send(&self, client: &Client, builder: &mut RequestBuilder) -> Result<Response> { fn send(&self, client: &Client, builder: &mut RequestBuilder) -> Result<Response> {
let request = builder.build()?; let request = builder.build()?;
self.execute(client, request) self.execute(client, request)
} }
} }
#[doc(hidden)]
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub struct HttpSender; pub struct HttpSender;

@ -26,7 +26,7 @@
//! ``` //! ```
#![deny( #![deny(
// missing_docs, missing_docs,
warnings, warnings,
missing_debug_implementations, missing_debug_implementations,
missing_copy_implementations, missing_copy_implementations,

@ -9,6 +9,7 @@ use url::Url;
use http_send::HttpSend; use http_send::HttpSend;
/// Represents a single page of API results
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Page<'a, T: for<'de> Deserialize<'de>, H: 'a + HttpSend> { pub struct Page<'a, T: for<'de> Deserialize<'de>, H: 'a + HttpSend> {
mastodon: &'a Mastodon<H>, mastodon: &'a Mastodon<H>,
@ -22,6 +23,8 @@ macro_rules! pages {
($($direction:ident: $fun:ident),*) => { ($($direction:ident: $fun:ident),*) => {
$( $(
doc_comment!(concat!(
"Method to retrieve the ", stringify!($direction), " page of results"),
pub fn $fun(&mut self) -> Result<Option<Vec<T>>> { pub fn $fun(&mut self) -> Result<Option<Vec<T>>> {
let url = match self.$direction.take() { let url = match self.$direction.take() {
Some(s) => s, Some(s) => s,
@ -37,7 +40,7 @@ macro_rules! pages {
self.prev = prev; self.prev = prev;
deserialise(response) deserialise(response)
} });
)* )*
} }
} }
@ -48,7 +51,7 @@ impl<'a, T: for<'de> Deserialize<'de>, H: HttpSend> Page<'a, T, H> {
prev: prev_page prev: prev_page
} }
pub fn new(mastodon: &'a Mastodon<H>, response: Response) -> Result<Self> { pub(crate) fn new(mastodon: &'a Mastodon<H>, response: Response) -> Result<Self> {
let (prev, next) = get_links(&response)?; let (prev, next) = get_links(&response)?;
Ok(Page { Ok(Page {
initial_items: deserialise(response)?, initial_items: deserialise(response)?,

@ -68,21 +68,30 @@ impl<'a, H: HttpSend> Registration<'a, H> {
} }
} }
/// Sets the name of this app
///
/// This is required, and if this isn't set then the AppBuilder::build
/// method will fail
pub fn client_name<I: Into<Cow<'a, str>>>(&mut self, name: I) -> &mut Self { pub fn client_name<I: Into<Cow<'a, str>>>(&mut self, name: I) -> &mut Self {
self.app_builder.client_name(name.into()); self.app_builder.client_name(name.into());
self self
} }
/// Sets the redirect uris that this app uses
pub fn redirect_uris<I: Into<Cow<'a, str>>>(&mut self, uris: I) -> &mut Self { pub fn redirect_uris<I: Into<Cow<'a, str>>>(&mut self, uris: I) -> &mut Self {
self.app_builder.redirect_uris(uris); self.app_builder.redirect_uris(uris);
self self
} }
/// Sets the scopes that this app requires
///
/// The default for an app is Scopes::Read
pub fn scopes(&mut self, scopes: Scopes) -> &mut Self { pub fn scopes(&mut self, scopes: Scopes) -> &mut Self {
self.app_builder.scopes(scopes); self.app_builder.scopes(scopes);
self self
} }
/// Sets the optional "website" to register the app with
pub fn website<I: Into<Cow<'a, str>>>(&mut self, website: I) -> &mut Self { pub fn website<I: Into<Cow<'a, str>>>(&mut self, website: I) -> &mut Self {
self.app_builder.website(website); self.app_builder.website(website);
self self
@ -216,6 +225,8 @@ impl<H: HttpSend> Registered<H> {
} }
} }
/// Represents the state of the auth flow when the app has been registered but
/// the user is not authenticated
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Registered<H: HttpSend> { pub struct Registered<H: HttpSend> {
base: String, base: String,

@ -1 +1,2 @@
/// Data structures for the MastodonClient::statuses method
pub mod statuses; pub mod statuses;

@ -1,5 +1,7 @@
use std::borrow::Cow; use std::borrow::Cow;
/// Builder for making a client.statuses() call
///
/// # Example /// # Example
/// ///
/// ``` /// ```
@ -19,40 +21,118 @@ pub struct StatusesRequest<'a> {
} }
impl<'a> StatusesRequest<'a> { impl<'a> StatusesRequest<'a> {
/// Construct a new `StatusesRequest` object
///
/// # Example
///
/// ```
/// # extern crate elefren;
/// # use elefren::StatusesRequest;
/// let request = StatusesRequest::new();
/// ```
pub fn new() -> Self { pub fn new() -> Self {
Self::default() Self::default()
} }
/// Set the `?only_media=1` flag for the .statuses() request
///
/// # Example
///
/// ```
/// # extern crate elefren;
/// # use elefren::StatusesRequest;
/// let request = StatusesRequest::new().only_media();
/// assert_eq!(&request.to_querystring(), "?only_media=1");
pub fn only_media(mut self) -> Self { pub fn only_media(mut self) -> Self {
self.only_media = true; self.only_media = true;
self self
} }
/// Set the `?exclude_replies=1` flag for the .statuses() request
///
/// # Example
///
/// ```
/// # extern crate elefren;
/// # use elefren::StatusesRequest;
/// let request = StatusesRequest::new().exclude_replies();
/// assert_eq!(&request.to_querystring(), "?exclude_replies=1");
/// ```
pub fn exclude_replies(mut self) -> Self { pub fn exclude_replies(mut self) -> Self {
self.exclude_replies = true; self.exclude_replies = true;
self self
} }
/// Set the `?pinned=1` flag for the .statuses() request
///
/// # Example
///
/// ```
/// # extern crate elefren;
/// # use elefren::StatusesRequest;
/// let request = StatusesRequest::new().pinned();
/// assert_eq!(&request.to_querystring(), "?pinned=1");
/// ```
pub fn pinned(mut self) -> Self { pub fn pinned(mut self) -> Self {
self.pinned = true; self.pinned = true;
self self
} }
/// Set the `?max_id=:max_id` flag for the .statuses() request
///
/// # Example
///
/// ```
/// # extern crate elefren;
/// # use elefren::StatusesRequest;
/// let request = StatusesRequest::new().max_id("foo");
/// assert_eq!(&request.to_querystring(), "?max_id=foo");
/// ```
pub fn max_id<S: Into<Cow<'a, str>>>(mut self, max_id: S) -> Self { pub fn max_id<S: Into<Cow<'a, str>>>(mut self, max_id: S) -> Self {
self.max_id = Some(max_id.into()); self.max_id = Some(max_id.into());
self self
} }
/// Set the `?since_id=:since_id` flag for the .statuses() request
///
/// # Example
///
/// ```
/// # extern crate elefren;
/// # use elefren::StatusesRequest;
/// let request = StatusesRequest::new().since_id("foo");
/// assert_eq!(&request.to_querystring(), "?since_id=foo");
/// ```
pub fn since_id<S: Into<Cow<'a, str>>>(mut self, since_id: S) -> Self { pub fn since_id<S: Into<Cow<'a, str>>>(mut self, since_id: S) -> Self {
self.since_id = Some(since_id.into()); self.since_id = Some(since_id.into());
self self
} }
/// Set the `?limit=:limit` flag for the .statuses() request
///
/// # Example
///
/// ```
/// # extern crate elefren;
/// # use elefren::StatusesRequest;
/// let request = StatusesRequest::new().limit(10);
/// assert_eq!(&request.to_querystring(), "?limit=10");
/// ```
pub fn limit(mut self, limit: usize) -> Self { pub fn limit(mut self, limit: usize) -> Self {
self.limit = Some(limit); self.limit = Some(limit);
self self
} }
/// Turns this builder into a querystring
///
/// # Example
///
/// ```
/// # extern crate elefren;
/// # use elefren::StatusesRequest;
/// let request = StatusesRequest::new().limit(10).pinned();
/// assert_eq!(&request.to_querystring(), "?pinned=1&limit=10");
/// ```
pub fn to_querystring(&self) -> String { pub fn to_querystring(&self) -> String {
let mut opts = vec![]; let mut opts = vec![];

Loading…
Cancel
Save