gitea_sdk/api/users/mod.rs
1pub mod get;
2pub mod orgs;
3pub mod repos;
4pub mod stars;
5
6pub struct Users {
7 pub username: String,
8}
9
10impl Users {
11 /// Gets a user by their username.
12 /// This will return a [User] object if the user exists and is visible to the currently
13 /// authenticated user.
14 /// If the user does not exist or is not visible, this method will return a 404 status code and
15 /// an empty response.
16 ///
17 /// # Example
18 /// ```
19 /// # use gitea_sdk::{Client, Auth};
20 /// # async fn get_user() {
21 /// let client = Client::new(
22 /// "https://gitea.example.com",
23 /// Auth::Token("your-token")
24 /// );
25 /// let user = client
26 /// .users("username")
27 /// .get()
28 /// .send(&client)
29 /// .await
30 /// .unwrap();
31 /// # }
32 /// ```
33 /// This will get the user with the username "username".
34 /// If the user does not exist, this method will return a [TeatimeError] with a 404 status code.
35 ///
36 pub fn get(&self) -> get::GetUserBuilder {
37 get::GetUserBuilder::new(&self.username)
38 }
39
40 /// Gets the repositories for a user.
41 /// This will return a list of repositories for the user.
42 ///
43 /// # Example
44 /// ```
45 /// # use gitea_sdk::{Client, Auth};
46 /// # async fn get_repos() {
47 /// let client = Client::new(
48 /// "https://gitea.example.com",
49 /// Auth::Token("your-token")
50 /// );
51 /// let repos = client
52 /// .users("username")
53 /// .list_repos()
54 /// .send(&client)
55 /// .await
56 /// .unwrap();
57 /// # }
58 /// ```
59 pub fn list_repos(&self) -> repos::ListReposBuilder {
60 repos::ListReposBuilder::new(&self.username)
61 }
62
63 /// Gets the stars for a user.
64 /// This will return a list of starred repositories for the user.
65 ///
66 /// # Example
67 /// ```
68 /// # use gitea_sdk::{Client, Auth};
69 /// # async fn get_stars() {
70 /// let client = Client::new(
71 /// "https://gitea.example.com",
72 /// Auth::Token("your-token")
73 /// );
74 /// let stars = client
75 /// .users("username")
76 /// .list_starred()
77 /// .send(&client)
78 /// .await
79 /// .unwrap();
80 /// # }
81 /// ```
82 pub fn list_starred(&self) -> stars::ListStarredBuilder {
83 stars::ListStarredBuilder::new(&self.username)
84 }
85
86 /// Gets the organizations for a user.
87 ///
88 /// # Example
89 /// ```
90 /// # use gitea_sdk::{Client, Auth};
91 /// # async fn get_orgs() {
92 /// let client = Client::new(
93 /// "https://gitea.example.com",
94 /// Auth::Token("your-token")
95 /// );
96 /// let orgs = client
97 /// .users("username")
98 /// .list_orgs()
99 /// .send(&client)
100 /// .await
101 /// .unwrap();
102 /// # }
103 /// ```
104 pub fn list_orgs(&self) -> orgs::Orgs {
105 orgs::Orgs::new(&self.username)
106 }
107}