Conversation
Signed-off-by: Stephen Reaves <reaves735@gmail.com>
Signed-off-by: Stephen Reaves <reaves735@gmail.com>
|
Hey there, thanks a lot for your contribution! Is there any particular reason you added two new JSON request methods instead of using the existing one with generics, just like with the other API endpoints for pages, databases, etc.? Other than that, it looks great. Merry Christmas! |
|
Hey, Yeah I was having some issues parsing the Merry Christmas to you too! |
|
Hey, sorry once again for the late response. The new year started quite busy for me unfortunately. I see. The pub async fn get_comments<T: AsIdentifier<BlockId>>(
&self,
block_id: T,
) -> Result<ListResponse<Comment>, Error> {
let result = self
.make_json_request(self.client.get(format!(
"https://api.notion.com/v1/comments?block_id={block_id}",
block_id = block_id.as_id()
)))
.await?;
match result {
Object::List { list } => Ok(list.expect_comments()?),
response => Err(Error::UnexpectedResponse { response }),
}
}with this implemented on pub(crate) fn expect_comments(self) -> Result<ListResponse<Comment>, crate::Error> {
let items: Result<Vec<_>, _> = self
.results
.into_iter()
.map(|object| match object {
Object::Comment { comment } => Ok(comment),
response => Err(Error::UnexpectedResponse { response }),
})
.collect();
Ok(ListResponse {
results: items?,
has_more: self.has_more,
next_cursor: self.next_cursor,
})
}Should work in a similar way for Users. BTW, I think #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(tag = "object", rename_all = "snake_case")]
pub struct Comment {
/// Unique identifier for the database
pub id: CommentId,
/// Body of comment
pub rich_text: Vec<RichText>,
pub created_time: DateTime<Utc>,
pub last_edited_time: DateTime<Utc>,
pub parent: Parent,
pub created_by: User,
pub discussion_id: String,
}Thanks! |
No description provided.