-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gists: Handle fork related operations (#339)
* gists: Handle `GET gists/{gist_id}/forks` Fetches a sequence of gists that have forked the given `gist_id`. * gists: Handle `POST /gists/{gist_id}/forks` Calling this endpoint forks the gist_id to the authenticated user's account.
- Loading branch information
Showing
2 changed files
with
81 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
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,50 @@ | ||
use crate::{gists::GistsHandler, models::gists::Gist, Page, Result}; | ||
use serde; | ||
|
||
#[derive(serde::Serialize)] | ||
pub struct ListGistForksBuilder<'octo, 'b> { | ||
#[serde(skip)] | ||
handler: &'b GistsHandler<'octo>, | ||
#[serde(skip)] | ||
gist_id: String, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
per_page: Option<u8>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
page: Option<u32>, | ||
} | ||
|
||
impl<'octo, 'b> ListGistForksBuilder<'octo, 'b> { | ||
pub(crate) fn new(handler: &'b GistsHandler<'octo>, gist_id: String) -> Self { | ||
Self { | ||
handler, | ||
gist_id, | ||
per_page: None, | ||
page: None, | ||
} | ||
} | ||
|
||
/// Set the `per_page` query parameter on the builder. | ||
/// | ||
/// Controls the number of results to return per "page" of results. | ||
/// The maximum value is 100 results per page retrieved. Values larger than | ||
/// `100` are clamped to `100` by GitHub's API | ||
pub fn per_page(mut self, count: u8) -> Self { | ||
self.per_page = Some(count); | ||
self | ||
} | ||
|
||
/// Sets the `page` query parameter on the builder. | ||
/// | ||
/// Controls which page of the result set should be retrieved. | ||
/// All pages are retrieved if this is omitted. | ||
pub fn page(mut self, page_num: u32) -> Self { | ||
self.page = Some(page_num); | ||
self | ||
} | ||
|
||
/// Sends the actual request to GitHub's API | ||
pub async fn send(self) -> Result<Page<Gist>> { | ||
let route = format!("/gists/{gist_id}/forks", gist_id = self.gist_id); | ||
self.handler.crab.get(route, Some(&self)).await | ||
} | ||
} |