-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::api::fav::Fav; | ||
use crate::api::post::get_one::PostEntry; | ||
use crate::infra::http::{body_or_err, RequestBuilderExt, VecExt}; | ||
use crate::infra::iter::IntoIteratorExt; | ||
use crate::infra::json; | ||
use crate::infra::result::IntoResult; | ||
use crate::openapi; | ||
use anyhow::Result; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
struct FavEntry { | ||
#[serde(rename = "Title")] | ||
pub title: String, | ||
#[serde(rename = "LinkUrl")] | ||
pub link_url: String, | ||
#[serde(rename = "Summary")] | ||
pub summary: String, | ||
#[serde(rename = "Tags")] | ||
pub tags: Vec<String>, | ||
#[serde(rename = "DateAdded")] | ||
pub create_time: String, | ||
} | ||
|
||
impl Fav { | ||
pub async fn get_list(&self, skip: usize, take: usize) -> Result<Vec<PostEntry>> { | ||
let client = &reqwest::Client::new(); | ||
|
||
let range = (skip + 1)..=(skip + take); | ||
range | ||
.map(|i| async move { | ||
let req = { | ||
let url = { | ||
let query = vec![("pageIndex", i), ("pageSize", 1)].into_query_string(); | ||
openapi!("Bookmarks?{}", query) | ||
}; | ||
|
||
client.get(url).pat_auth(&self.pat) | ||
}; | ||
|
||
let resp = req.send().await?; | ||
|
||
let entry = { | ||
let body = body_or_err(resp).await?; | ||
let json = json::deserialize::<Value>(&body)?["postList"].take(); | ||
|
||
let [entry, ..] = serde_json::from_value::<[PostEntry; 1]>(json)?; | ||
entry | ||
}; | ||
|
||
entry.into_ok() | ||
}) | ||
.join_all() | ||
.await | ||
.into_iter() | ||
.collect() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod get_list; | ||
|
||
pub struct Fav { | ||
pat: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod auth; | ||
pub mod fav; | ||
pub mod ing; | ||
pub mod news; | ||
pub mod post; | ||
|