1use std::collections::HashSet;
4use std::ops::{Deref, DerefMut};
5
6use octorust::Client;
7use octorust::auth::Credentials;
8
9type Result<T> = std::result::Result<T, octorust::ClientError>;
10
11#[derive(Clone)]
24#[repr(transparent)]
25pub struct GitHub(Client);
26
27impl Deref for GitHub {
28 type Target = Client;
29
30 fn deref(&self) -> &Self::Target { &self.0 }
31}
32
33impl DerefMut for GitHub {
34 fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
35}
36
37impl GitHub {
38 const USER_AGENT: &'static str = "gfas";
39
40 #[allow(clippy::result_large_err)]
42 pub fn new(token: String) -> Result<Self> {
43 Ok(Self(Client::new(Self::USER_AGENT, Credentials::Token(token))?))
44 }
45
46 pub async fn list_followings(&self, user: &str) -> Result<HashSet<String>> {
52 Ok(
53 self
54 .users()
55 .list_all_following_for_user(user)
56 .await?
57 .body
58 .into_iter()
59 .map(|u| u.login)
60 .collect()
61 )
62 }
63
64 pub async fn list_followers(&self, user: &str) -> Result<HashSet<String>> {
70 Ok(
71 self
72 .users()
73 .list_all_followers_for_user(user)
74 .await?
75 .body
76 .into_iter()
77 .map(|u| u.login)
78 .collect()
79 )
80 }
81}