pub struct User;
Implementations§
Source§impl User
impl User
Sourcepub fn current(&self) -> GetAuthenticatedUserBuilder
pub fn current(&self) -> GetAuthenticatedUserBuilder
Gets the currently authenticated user. This will return a User object representing the currently authenticated user. As long as the token is valid, this method will always return a user.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let user = client
.user()
.current()
.send(&client)
.await
.unwrap();
Sourcepub fn create_repo(&self, name: impl ToString) -> CreateRepoBuilder
pub fn create_repo(&self, name: impl ToString) -> CreateRepoBuilder
Creates a new repository for the authenticated user.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let repo = client
.user()
.create_repo("my-new-repo")
.private(true)
.send(&client)
.await
.unwrap();
This will create a new private repository with the name “my-new-repo” for the authenticated user.
Sourcepub fn list_repos(&self) -> ListReposBuilder
pub fn list_repos(&self) -> ListReposBuilder
Lists all repositories for the authenticated user. This will return a list of all Repository objects owned by the authenticated user.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let repos = client
.user()
.list_repos()
.limit(10)
.page(2)
.send(&client)
.await
.unwrap();
Sourcepub fn orgs(&self) -> Orgs
pub fn orgs(&self) -> Orgs
List the current user’s organizations.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let orgs = client
.user()
.orgs()
.page(2)
.limit(10)
.send(&client)
.await
.unwrap();
Sourcepub fn create_access_token(
&self,
user: impl ToString,
name: impl ToString,
scopes: Vec<impl ToString>,
) -> CreateAccessTokenBuilder
pub fn create_access_token( &self, user: impl ToString, name: impl ToString, scopes: Vec<impl ToString>, ) -> CreateAccessTokenBuilder
Creates a new access token for a user. NOTE: This endpoint requires basic authentication and will fail otherwise.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Basic("username", "password")
);
let token = client
.user()
.create_access_token("username", "my-new-token", vec!["write:repository", "read:user"])
.send(&client)
.await
.unwrap();
println!("Token {} created: {}", token.name, token.sha1);
let new_client = Client::new(
"https://gitea.example.com",
Auth::Token(token.sha1)
);
This will create a new token with the name “my-new-token”, which can read all user data and read and write to repositories.
If the token is successfully created, this method will return a [AccessToken] object. If the user is not authenticated correctly (e.g. not using basic auth), this method will return a 403 status code. In case of any client-side errors, this method will return a 400 status code.
Sourcepub fn list_access_tokens(
&self,
username: impl ToString,
) -> ListAccessTokensBuilder
pub fn list_access_tokens( &self, username: impl ToString, ) -> ListAccessTokensBuilder
Lists all access tokens for a user. NOTE: This endpoint requires basic authentication and will fail otherwise.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Basic("username", "password")
);
let tokens = client
.user()
.list_access_tokens("username")
.send(&client)
.await
.unwrap();
This will list all access tokens for the user “username”.
Sourcepub fn delete_access_token(
&self,
user: impl ToString,
token: impl ToString,
) -> DeleteAccessTokenBuilder
pub fn delete_access_token( &self, user: impl ToString, token: impl ToString, ) -> DeleteAccessTokenBuilder
Deletes an access token by its username and token. This will delete the token and revoke all permissions associated with it. NOTE: This endpoint requires basic authentication and will fail otherwise.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Basic("username", "password")
);
client.
user()
.delete_access_token("username", "token")
.send(&client)
.await
.unwrap();
This will delete the token with the name “token-name” for the user “username”.
If the token does not exist, this method will return a 404 status code. If the target user is not the authenticated user and the authenticated user is not an administrator, this method will return a 403 status code. For any client-side other errors, this method will return a 422 status code. If the token is successfully deleted, this method will return a 204 status code.
Sourcepub fn get_settings(&self) -> GetSettingsBuilder
pub fn get_settings(&self) -> GetSettingsBuilder
Gets the current user’s settings.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let settings = client
.user()
.get_settings()
.send(&client)
.await
.unwrap();
println!("User settings: {:?}", settings);
Sourcepub fn update_settings(&self) -> UpdateSettingsBuilder
pub fn update_settings(&self) -> UpdateSettingsBuilder
Updates the current user’s settings.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let settings = client
.user()
.update_settings()
.theme("dark")
.send(&client)
.await
.unwrap();
println!("User settings: {:?}", settings);
This will update the user’s theme to “dark”.
Sourcepub fn list_starred(&self) -> ListStarredBuilder
pub fn list_starred(&self) -> ListStarredBuilder
Lists all repositories starred by the authenticated user.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let repos = client
.user()
.list_starred()
.send(&client)
.await
.unwrap();
Sourcepub fn is_starred(
&self,
owner: impl ToString,
repo: impl ToString,
) -> IsStarredBuilder
pub fn is_starred( &self, owner: impl ToString, repo: impl ToString, ) -> IsStarredBuilder
Checks if the authenticated user has starred a repository.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let starred = client
.user()
.is_starred("owner", "repo")
.send(&client)
.await
.unwrap();
if starred {
println!("You have starred this repo!");
} else {
println!("You have not starred this repo.");
}
Sourcepub fn star_repo(
&self,
owner: impl ToString,
repo: impl ToString,
) -> StarRepoBuilder
pub fn star_repo( &self, owner: impl ToString, repo: impl ToString, ) -> StarRepoBuilder
Stars a repository for the authenticated user. This will star the repository with the given owner and name.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
client
.user()
.star_repo("owner", "repo")
.send(&client)
.await
.unwrap();
This will star the repository “repo” owned by “owner”.
Sourcepub fn unstar_repo(
&self,
owner: impl ToString,
repo: impl ToString,
) -> UnstarRepoBuilder
pub fn unstar_repo( &self, owner: impl ToString, repo: impl ToString, ) -> UnstarRepoBuilder
Unstars a repository for the authenticated user. This will unstar the repository with the given owner and name.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
client
.user()
.unstar_repo("owner", "repo")
.send(&client)
.await
.unwrap();