-
-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gists API: Complete support #371
Conversation
df6d26a
to
c18ac2b
Compare
src/api/gists/list_gists.rs
Outdated
|
||
/// Handles query data for the `GET /gists/public` endpoint. | ||
#[derive(Debug, serde::Serialize)] | ||
pub struct ListAllPublicGistsBuilder<'octo> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is significant overlap between ListAllPublicGistsBuilder
and ListAllGistsBuilder
.
An alternative implementation I considered was to have a flag in ListAllGistsBuilder
decide which endpoint to call, but decided against it because GET /gists/public
offers specific guarantees on the order of results returned.
I've no strong opinions on the structure otherwise, happy to merge these two types if that is considered more desirable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think separate structs is probably best as it future proofs us from GitHub making them slightly different in the future.
Another approach you could have taken is to have a type parameter for the visibility, that way it would technically be two different types ListGistsBuilder<All>
and ListGistsBuilder<Public>
but they could share all of the same fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, will look into this!
src/api/users.rs
Outdated
pub fn list_user_gists(&self, username: impl AsRef<str>) -> ListGistsForUserBuilder<'octo> { | ||
ListGistsForUserBuilder::new(self.crab, username.as_ref().to_string()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Official docs file this endpoint with the rest of gist endpoints. Would you prefer I move this handler into api/gists.rs
as well? @XAMPPRocky
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.
Add `GistHandler::list_all_gists(...)` which: * For an authenticated caller, this endpoint lists all gists of the authenticated user. * If called anonymously, it will retrieve ALL public gists in GitHub. Use with caution! There is partial overlap with functionality in `CurrentAuthHandler::list_gists_for_authenticated_user`.
Adds the handler: `GistsHandler::list_all_recent_public_gists` The struct introduced has significant overlap with `ListAllGistsBuilder` but is kept as a separate type since the response for `ListAllPublicGistsBuilder` has specific sorting guarantees which differ from `GET /gists`
* Create module `api/users.rs` * Add a handler for `GET /users/{username}/gists` This is technically documented under the [gists api][1], but is grouped with other functions for handling routes under `/users/`. [1] https://docs.github.com/en/rest/gists/gists?apiVersion=2022-11-28#list-gists-for-a-user
Since both of these share almost all of the code except for the endpoint we implement a trait with an associated constant that provides this value.
GitHub keeps this endpoint with other gist related endpoints so we will do the same for minimizing surprise.
Thank you for your PR! |
This PR completes support for GitHub's gists api.
The remaining 3 endpoints in #27 (comment) will all be implemented here:
Closes #27