1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
//! [Comment API](https://developers.deezer.com/api/comment) #[warn(missing_docs)] use crate::models::{DeezerObject, User}; use crate::Result; use serde::{Deserialize, Serialize}; /// Contains all the information provided for a Comment. /// /// # Examples /// /// You can query a comment by id via the [`DeezerObject::get()`] method: /// /// ```rust /// # use deezer::models::*; /// # use deezer::DeezerError; /// # #[tokio::main] /// # async fn main() -> Result<(), DeezerError> { /// let comment = Comment::get(4179157801).await?.unwrap(); /// # assert_eq!(comment.id, 4179157801); /// # Ok(()) /// # } /// ``` /// /// Or you can use [`DeezerClient::comment()`](crate::DeezerClient::comment()): /// /// ```rust /// # use deezer::models::*; /// # use deezer::{DeezerClient, DeezerError}; /// # #[tokio::main] /// # async fn main() -> Result<(), DeezerError> { /// let deezer = DeezerClient::new(); /// let comment = deezer.comment(4179157801).await?.unwrap(); /// # assert_eq!(comment.id, 4179157801); /// # Ok(()) /// # } /// /// ``` #[derive(Deserialize, Serialize, Debug)] pub struct Comment { /// The comment's Deezer id pub id: u64, /// The content of the comment pub text: String, /// The date the comment was posted pub date: u64, /// Object the comment belongs to, containing: id, type. /// Type can be "artist", "album" or "playlist". object: CommentParent, /// User this comment belongs to pub author: CommentAuthor, } impl DeezerObject for Comment { fn get_api_url(id: u64) -> String { format!("comment/{}", id) } } /// Subset of [`User`]. /// /// Use [`get_full()`] for the corresponding [`User`] struct. /// /// [`get_full()`]: CommentAuthor::get_full #[derive(Deserialize, Serialize, Debug)] pub struct CommentAuthor { /// The comment's Deezer id pub id: u64, /// The user's Deezer nickname pub name: String, /// The url of the profil for the user on Deezer pub link: String, /// The url of the user's profile picture pub picture: String, /// The url of the user's profile picture in size small pub picture_small: String, /// The url of the user's profile picture in size medium pub picture_medium: String, /// The url of the user's profile picture in size big pub picture_big: String, /// The url of the user's profile picture in size xl pub picture_xl: String, } impl CommentAuthor { /// Returns the full [`User`]. pub async fn get_full(&self) -> Result<User> { // Safety: unwrap should be okay here, as the artist is referenced by the deezer api let user = User::get(self.id).await?.unwrap(); Ok(user) } } #[derive(Deserialize, Serialize, Debug)] struct CommentParent { id: String, #[serde(rename = "type")] object_type: String, }