1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
use crate::model::{
keys::{GpgKey, SshKey},
organizations::SimpleOrganization,
user::SimpleUser,
};
use super::prelude::*;
/// * tags users
/// * get `/user/followers`
/// * docs <https://docs.github.com/rest/reference/users#list-followers-of-the-authenticated-user>
///
/// List followers of the authenticated user
/// Lists the people following the authenticated user.
pub async fn get_followers<T>(client: &T, params: Option<&Pagination>) -> Result<Vec<SimpleUser>, GithubRestError>
where
T: Requester,
{
client
.req::<Pagination, String, Vec<SimpleUser>>(EndPoints::GetUserFollowers(), params, None)
.await
}
/// * tags users
/// * get `/user/following`
/// * docs <https://docs.github.com/rest/reference/users#list-the-people-the-authenticated-user-follows>
///
/// List the people the authenticated user follows
/// Lists the people who the authenticated user follows.
pub async fn get_following<T>(client: &T, params: Option<&Pagination>) -> Result<Vec<SimpleUser>, GithubRestError>
where
T: Requester,
{
client
.req::<Pagination, String, Vec<SimpleUser>>(EndPoints::GetUserFollowing(), params, None)
.await
}
user_and_pagination_methods!(
/// * tags users
/// * get `/users/{username}/keys`
/// * docs <https://docs.github.com/rest/reference/users#list-public-keys-for-a-user>
///
/// List public keys for a user
/// Lists the _verified_ public SSH keys for a user. This is accessible by
/// anyone.
get_user_keys,
EndPoints::GetUsersusernameKeys,
Vec<SshKey>,
/// * tags users
/// * get `/users/{username}/gpg_keys`
/// * docs <https://docs.github.com/rest/reference/users#list-gpg-keys-for-a-user>
///
/// List GPG keys for a user
/// Lists the GPG keys for a user. This information is accessible by anyone.
get_user_gpg_keys,
EndPoints::GetUsersusernameGpgKeys,
Vec<GpgKey>,
/// * tags orgs
/// * get `/users/{username}/orgs`
/// * docs <https://docs.github.com/rest/reference/orgs#list-organizations-for-a-user>
///
/// List organizations for a user
/// List [public organization memberships](https://docs.github.com/articles/publicizing-or-concealing-organization-membership) for the specified user.
///
/// This method only lists _public_ memberships, regardless of authentication. If you need to fetch all of the organization memberships (public and private) for the authenticated user, use the [List organizations for the authenticated user](https://docs.github.com/rest/reference/orgs#list-organizations-for-the-authenticated-user) API instead.
get_user_organizations,
EndPoints::GetUsersusernameOrgs,
Vec<SimpleOrganization>,
/// * tags users
/// * get `/users/{username}/following`
/// * docs <https://docs.github.com/rest/reference/users#list-the-people-a-user-follows>
///
/// List the people a user follows
/// Lists the people who the specified user follows.
get_user_following,
EndPoints::GetUsersusernameFollowing,
Vec<SimpleUser>,
/// * tags users
/// * get `/users/{username}/followers`
/// * docs <https://docs.github.com/rest/reference/users#list-followers-of-a-user>
///
/// List followers of a user
/// Lists the people following the specified user.
get_user_followers,
EndPoints::GetUsersusernameFollowers,
Vec<SimpleUser>
);
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
pub struct Pagination {
/// Results per page (max 100)
/// Default: 30
#[serde(skip_serializing_if = "Option::is_none")]
pub per_page: Option<String>,
/// Page number of the results to fetch.
/// Default: 1
#[serde(skip_serializing_if = "Option::is_none")]
pub page: Option<String>,
}
#[cfg(feature = "client")]
#[cfg(test)]
mod tests {
use crate::{client::DefaultRequester, methods::util};
use super::*;
#[tokio::test]
async fn test_get_followers() {
let res = get_followers(&util::github_auth(), None).await.unwrap();
dbg!(res);
}
#[tokio::test]
async fn test_get_following() {
let res = get_followers(&util::github_auth(), None).await.unwrap();
dbg!(res);
}
#[tokio::test]
async fn test_get_user_following() {
let client = DefaultRequester::new_none();
let res = get_user_following(
&client,
"proudmuslim-dev",
Some(&Pagination {
per_page: Some("2".to_owned()),
page: Some("1".to_owned()),
}),
)
.await
.unwrap();
dbg!(res);
}
#[tokio::test]
async fn test_get_user_followers() {
let client = DefaultRequester::new_none();
let res = get_user_followers(
&client,
"proudmuslim-dev",
Some(&Pagination {
per_page: Some("2".to_owned()),
page: Some("1".to_owned()),
}),
)
.await
.unwrap();
dbg!(res);
}
#[tokio::test]
async fn test_get_user_organizations() {
let client = DefaultRequester::new_none();
let res = get_user_organizations(&client, "proudmuslim-dev", None).await.unwrap();
dbg!(res);
}
#[tokio::test]
async fn test_get_user_keys() {
let client = DefaultRequester::new_none();
let res = get_user_keys(&client, "proudmuslim-dev", None).await.unwrap();
dbg!(res);
}
#[tokio::test]
async fn test_get_user_gpg_keys() {
let client = DefaultRequester::new_none();
let res = get_user_gpg_keys(&client, "proudmuslim-dev", None).await.unwrap();
dbg!(res);
}
}