Skip to content

Commit

Permalink
pixiv: add endpoint for illust_follow
Browse files Browse the repository at this point in the history
  • Loading branch information
karin0 committed Sep 16, 2024
1 parent 620e43a commit 058a9b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
14 changes: 12 additions & 2 deletions pixiv/src/aapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ async fn fin<'de, T: DeserializeOwned>(req: RequestBuilder) -> Result<T> {

#[derive(Copy, Clone, Debug, IntoStaticStr)]
#[strum(serialize_all = "snake_case")]
pub enum BookmarkRestrict {
pub enum Restrict {
Public,
Private,
}

#[deprecated]
pub type BookmarkRestrict = Restrict;

impl<S: ApiState> Client<S> {
fn app(&self, endpoint: &impl Endpoint) -> RequestBuilder {
self.call(endpoint).header("host", "app-api.pixiv.net")
Expand All @@ -38,7 +41,7 @@ impl<S: ApiState> Client<S> {
pub async fn user_bookmarks_illust<T: DeserializeOwned>(
&self,
user_id: &str,
restrict: BookmarkRestrict,
restrict: Restrict,
) -> Result<T> {
fin(self.app(&self.api.user_bookmarks_illust).query(&[
("user_id", user_id),
Expand All @@ -47,4 +50,11 @@ impl<S: ApiState> Client<S> {
]))
.await
}

pub async fn illust_follow<T: DeserializeOwned>(&self, restrict: Restrict) -> Result<T> {
fin(self
.app(&self.api.illust_follow)
.query(&[("restrict", Into::<&str>::into(restrict))]))
.await
}
}
4 changes: 3 additions & 1 deletion pixiv/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ impl Endpoint for SimpleEndpoint {
pub struct ApiEndpoint {
pub auth: SimpleEndpoint,
pub user_bookmarks_illust: SimpleEndpoint,
pub illust_follow: SimpleEndpoint,
}

impl ApiEndpoint {
pub fn with_hosts(app_host: Option<&str>, oauth_host: Option<&str>) -> Result<Self> {
let app_host = app_host.unwrap_or("https://app-api.pixiv.net");
let oauth_host = oauth_host.unwrap_or("https://oauth.secure.pixiv.net");
let appv1 = Version::new(format!("{app_host}/v1"));
// let appv2 = Version::new(format!("{}/v2", app_host));
let appv2 = Version::new(format!("{}/v2", app_host));
let oauth = Version::new(oauth_host);
Ok(Self {
auth: oauth.post("auth/token")?,
user_bookmarks_illust: appv1.get("user/bookmarks/illust")?,
illust_follow: appv2.get("illust/follow")?,
})
}

Expand Down
6 changes: 5 additions & 1 deletion pixiv/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ pub struct Illust {
pub visible: bool,
pub create_date: String,
pub caption: String,
pub is_bookmarked: bool,
#[serde(rename = "type")]
pub type_: String,
}

#[derive(Deserialize, Debug, Clone)]
pub struct UserBookmarksIllust {
pub struct IllustPage {
pub illusts: Vec<Illust>,
pub next_url: Option<String>,
}

#[deprecated]
pub type UserBookmarksIllust = IllustPage;

0 comments on commit 058a9b7

Please sign in to comment.