Skip to content

Commit 9b5cab7

Browse files
committed
Implement compose_with_picture()
1 parent b1e3f54 commit 9b5cab7

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

misskey_api/src/api.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,32 @@ impl PostAPI for MisskeyApi {
116116
}
117117

118118
async fn compose_with_picture(&self, text: &str, media: &Vec<String>) -> Result<(), String> {
119-
todo!()
119+
let payload = NoteWithPicture {
120+
i: &self.access_code,
121+
text: text.to_string(),
122+
mediaIds: media.to_vec()
123+
};
124+
125+
let res = reqwest::Client::new()
126+
.post(self.get_endpoint_url(ENDPOINT::notes::create))
127+
.header("Content-Type", "application/json")
128+
.json(&payload)
129+
.send().await;
130+
131+
match res {
132+
Ok(r) => {
133+
if r.status().as_u16() == 200 {
134+
Ok(())
135+
}
136+
else {
137+
let e = r.json::<CommonError>().await.unwrap();
138+
Err(e.message.unwrap())
139+
}
140+
},
141+
Err(_) => {
142+
Err("Unknown Error Occured".to_string())
143+
}
144+
}
120145
}
121146

122147
async fn upload_media(&self, picture: Bytes) -> Option<String> {

0 commit comments

Comments
 (0)