From a79d2e96b64060eab7d88f683e62c70440dbca88 Mon Sep 17 00:00:00 2001 From: Vaibhav Yenamandra <3663231+envp@users.noreply.github.com> Date: Sun, 16 Apr 2023 18:13:33 -0400 Subject: [PATCH] current: Handle `GET /gists/starred` List gists starred by authenticated user Adds `CurrentAuthHandler::list_gists_starred_by_authenticated_user`. This allows callers to fetch gists that were starred by the authenticated user. --- src/api/current.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/api/current.rs b/src/api/current.rs index 45ecc6ab..4ce72af5 100644 --- a/src/api/current.rs +++ b/src/api/current.rs @@ -118,6 +118,11 @@ impl<'octo> CurrentAuthHandler<'octo> { // self.crab.get("/gists", None::<&()>).await ListGistsForAuthenticatedUserBuilder::new(self.crab) } + + /// List gists that were starred by the authenticated user. + pub fn list_gists_starred_by_authenticated_user(&self) -> ListStarredGistsBuilder<'octo> { + ListStarredGistsBuilder::new(self.crab) + } } /// A builder pattern struct for listing starred repositories. @@ -391,3 +396,56 @@ impl<'octo> ListGistsForAuthenticatedUserBuilder<'octo> { self.crab.get("/gists", Some(&self)).await } } + +#[derive(serde::Serialize)] +pub struct ListStarredGistsBuilder<'octo> { + /// Client under use for building the request. + #[serde(skip)] + crab: &'octo Octocrab, + + /// Only show gists that were starred after the given ISO 8601 UTC timestamp. + #[serde(skip_serializing_if = "Option::is_none")] + since: Option>, + + /// Number of results to return per page. Maximum supported value is `100`. + /// Larger values are clamped to `100`. Defaults to `30` + #[serde(skip_serializing_if = "Option::is_none")] + per_page: Option, + + /// Page number of the results to fetch. Defaults to `1`. + #[serde(skip_serializing_if = "Option::is_none")] + page: Option, +} + +impl<'octo> ListStarredGistsBuilder<'octo> { + pub fn new(crab: &'octo Octocrab) -> Self { + Self { + crab, + since: None, + per_page: None, + page: None, + } + } + + /// Only show gists that were starred after the given ISO 8601 UTC timestamp. + pub fn since(mut self, last_updated: DateTime) -> Self { + self.since = Some(last_updated); + self + } + + /// The page number from the result set to fetch. + pub fn page(mut self, page_num: u32) -> Self { + self.page = Some(page_num); + self + } + + pub fn per_page(mut self, count: u8) -> Self { + self.per_page = Some(count); + self + } + + /// Sends the actual request. + pub async fn send(self) -> crate::Result> { + self.crab.get("/gists/starred", Some(&self)).await + } +}