use crate::{api::prelude::*, model::FollowType};
#[derive(Debug, Clone)]
pub struct FollowArtistsOrUsers {
pub type_: FollowType,
pub ids: Vec<String>,
}
impl Endpoint for FollowArtistsOrUsers {
fn method(&self) -> Method {
Method::PUT
}
fn endpoint(&self) -> Cow<'static, str> {
"me/following".into()
}
fn parameters(&self) -> QueryParams<'_> {
let mut params = QueryParams::default();
params.push("type", &self.type_);
params
}
fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, BodyError> {
JsonParams::into_body(&serde_json::json!({
"ids": self.ids,
}))
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{
api::{self, Query as _},
test::client::{ExpectedUrl, SingleTestClient},
};
#[test]
fn test_follow_artists_or_users_endpoint() {
let endpoint = ExpectedUrl::builder()
.method(Method::PUT)
.content_type("application/json")
.endpoint("me/following")
.add_query_params(&[("type", "artist")])
.body_str(r#"{"ids":["2CIMQHirSU0MQqyYHq0eOx","57dN52uHvrHOxijzpIgu3E","1vCWHaC5f2uS3yhpwWbIA6"]}"#)
.build();
let client = SingleTestClient::new_raw(endpoint, "");
let endpoint = FollowArtistsOrUsers {
type_: FollowType::Artist,
ids: vec![
"2CIMQHirSU0MQqyYHq0eOx".to_owned(),
"57dN52uHvrHOxijzpIgu3E".to_owned(),
"1vCWHaC5f2uS3yhpwWbIA6".to_owned(),
],
};
api::ignore(endpoint).query(&client).unwrap();
}
}