-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comb-through A.K.A. v2 #54
Comments
What do you prefer to do do with URLs that accept multiple optional parameters (like /api/v1/timelines/public), just add all of them with an |
The previous authors seemed to be fans of using the builder pattern to generate structures which use serde of serialization into a urlencoded string, and I think it fits nicely. There are a couple changes I'm making to the way they did that as a part of v2:
Another thought I have on this is that perhaps it would be a good idea to take a look at this section of the Any thoughts? |
(1) Sure. |
Any way I can help out here? Is the Would love to have this; the admin API will be critical for building automod tools for Mastodon, and I ended up implementing most of it in https://github.com/VyrCossont/mastodon-async/tree/admin-api before noticing this issue. |
Hello, yes, I am coming back to this soon but a couple of more urgent projects have come up, I should be wrapping them up soon (at least the urgent part). I really appreciate your work on the admin API, however, as you noted there may be some things which are already done. By all means, create a pull request (targeting the |
Right on. I'll take a look at the |
Also, my take on builders and defaults is that, while unnecessary options are un-ergonomic:
|
I tried implementing a builder with some mandatory and some optional parameters using use derive_builder::Builder;
use mastodon_async_entities::{report::Category, AccountId, RuleId, StatusId};
use serde_with::skip_serializing_none;
/// Form used to create a report
///
/// // Example
///
/// ```
/// use mastodon_async::{entities::{AccountId, report::Category}, requests::AddReportRequest};
/// let request = AddReportRequest::builder(AccountId::new("666")).category(Category::Spam).build();
/// ```
#[skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Builder)]
#[builder(
custom_constructor,
build_fn(private, name = "try_build"),
setter(into, strip_option)
)]
pub struct AddReportRequest {
/// The account being reported.
#[builder(private)]
pub account_id: AccountId,
/// Attach statuses to the report to provide additional context.
#[builder(default)]
pub status_ids: Option<Vec<StatusId>>,
/// The reason for the report.
#[builder(default)]
pub comment: Option<String>,
/// If the account is remote, should the report be forwarded to the remote admin?
#[builder(default)]
pub forward: Option<bool>,
/// Machine-readable category of the report.
#[builder(default)]
pub category: Option<Category>,
/// Rules broken by a [`Category::Violation`] report.
#[builder(default)]
pub rule_ids: Option<Vec<RuleId>>,
}
impl AddReportRequest {
/// Start building a form for creating a report.
pub fn builder(account_id: AccountId) -> AddReportRequestBuilder {
let mut builder = AddReportRequestBuilder::create_empty();
builder.account_id(account_id);
builder
}
}
impl AddReportRequestBuilder {
/// Build the form for creating a report.
pub fn build(&self) -> AddReportRequest {
self.try_build()
.expect("One or more required fields are missing!")
}
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json;
#[test]
fn test_serialize_request() {
let request = AddReportRequest::builder(AccountId::new("666"))
.category(Category::Spam)
.build();
let ser = serde_json::to_string(&request).expect("Couldn't serialize");
assert_eq!(ser, r#"{"account_id":"666","category":"spam"}"#);
}
} This gives the caller two options, both safe: they can create an The boilerplate cost of this is a |
Looks good to me. |
@VyrCossont you may want to review the changes in this commit 035637f |
Filled in the reporting and admin APIs here: https://github.com/VyrCossont/mastodon-async/tree/comb The above builder pattern is pretty much fine, I think. I'm going to convert the older builders to that style where it makes sense. |
This is great! Would you mind creating a PR for this? |
Sure, I'll open a draft and let you know once it's ready for review. |
Draft in #93. I'm concurrently working on an automod bot that uses |
It has come to my attention that the Mastodon API has been updated a lot since the original work this was based on, and we need to comb through the API documentation ensuring that each type is implemented according to the spec.
When this is released, we will cut a new v2.0 release. Breaking changes will be a part of this.
Tasks for this PR
Comb through entities
IdentityProofalready deprecated upstream. no sense in adding an entity just to deprecate it.Entities, second pass
IsVariant
cargo doc
(fix doc links #83)Comb through methods
Finishing up/other tasks
mastodon_async::requests
module is migrated entirely intomastodon_async_entities::forms
The text was updated successfully, but these errors were encountered: