diff --git a/src/api/current.rs b/src/api/current.rs index 1bdd7802..7de4ea0b 100644 --- a/src/api/current.rs +++ b/src/api/current.rs @@ -1,5 +1,6 @@ //! Get data about the currently authenticated user. +use crate::models::UpdateUserProfile; use crate::{ models::{self, gists::Gist, orgs::MembershipInvitation, Installation, Repository}, Octocrab, Page, Result, @@ -25,6 +26,21 @@ impl<'octo> CurrentAuthHandler<'octo> { self.crab.get("/user", None::<&()>).await } + /// ### Update the authenticated user + /// + ///works with the following fine-grained token types: + /// + /// * [GitHub App user access tokens](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-user-access-token-for-a-github-app) + /// * [Fine-grained personal access tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token) + /// + /// The fine-grained token must have the following permission set: + /// + /// * "Profile" user permissions (write) + pub async fn update_user(&self, new_data: UpdateUserProfile) -> Result { + let params = serde_json::to_value(new_data).unwrap(); + self.crab.patch("/user", Some(¶ms)).await + } + /// Fetches information about the currently authenticated app. /// /// ```no_run diff --git a/src/models.rs b/src/models.rs index 17ca1715..3c3998c0 100644 --- a/src/models.rs +++ b/src/models.rs @@ -483,6 +483,21 @@ pub struct UserProfile { pub updated_at: DateTime, } +/// Data for updating a user profile, +/// e.g. name, email, company, location, bio, blog, twitter, hireable +#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] +#[non_exhaustive] +pub struct UpdateUserProfile { + pub name: Option, + pub email: Option, + pub blog: Option, + pub twitter_username: Option, + pub company: Option, + pub location: Option, + pub hireable: Option, + pub bio: Option, +} + /// The simple profile for a GitHub user #[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] #[non_exhaustive]