client: Simplify json conversion
This commit is contained in:
parent
284faf9b4d
commit
3322d47957
1 changed files with 2 additions and 15 deletions
|
@ -1,4 +1,3 @@
|
|||
use std::io::Write;
|
||||
use crate::post::{Id, Post, RawPost, RawPosts};
|
||||
use anyhow::Result;
|
||||
use base64::{engine::GeneralPurpose, Engine};
|
||||
|
@ -79,17 +78,7 @@ impl Client {
|
|||
) -> Result<Vec<Post>> {
|
||||
self.request_limiter().await;
|
||||
let res = self.list_posts_raw(limit, tags, page).await?;
|
||||
let text = res.text().await?;
|
||||
|
||||
if cfg!(debug) {
|
||||
let mut debug_file = std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open("/tmp/debug.json")?;
|
||||
debug_file.write_all(text.as_bytes())?;
|
||||
}
|
||||
|
||||
Ok(serde_json::from_str::<RawPosts>(text.as_str())?.into())
|
||||
Ok(res.json::<RawPosts>().await?.into())
|
||||
}
|
||||
|
||||
/// Get a specific post
|
||||
|
@ -112,9 +101,7 @@ impl Client {
|
|||
pub async fn get_post(&mut self, post_id: Id) -> Result<Post> {
|
||||
self.request_limiter().await;
|
||||
let res = self.get_post_raw(post_id).await?;
|
||||
let text = res.text().await?;
|
||||
|
||||
Ok(serde_json::from_str::<RawPost>(text.as_str())?.into())
|
||||
Ok(res.json::<RawPost>().await?.into())
|
||||
}
|
||||
|
||||
pub async fn get_post_raw(&mut self, post_id: Id) -> Result<Response> {
|
||||
|
|
Loading…
Reference in a new issue