diff --git a/src/githubctl/githubctl.rs b/src/githubctl/githubctl.rs index c1260f8..dc408fa 100644 --- a/src/githubctl/githubctl.rs +++ b/src/githubctl/githubctl.rs @@ -1,6 +1,3 @@ -use reqwest::header::HeaderValue; -use reqwest::header::ETAG; -use std::collections::HashMap; use tokio::sync::mpsc; use super::github_endpoint_watcher::GithubEndpointWatcher; @@ -45,6 +42,34 @@ impl<'a> GithubCtl<'a> { owner = owner.as_ref().trim(), repo = repo.as_ref().trim() ); + return Ok(self.watch_list(url).await); + } + + pub async fn watch_org(&mut self, org: O) -> Result<(), Box> + where + O: AsRef, + { + let url = format!( + "https://api.github.com/users/{username}/events/orgs/{org}", + org = org.as_ref().trim(), + username = self.username.trim() + ); + return Ok(self.watch_list(url).await); + } + + pub async fn watch_self(&mut self) -> Result<(), Box> { + let url = format!( + "https://api.github.com/users/{username}/received_events", + username = self.username.trim() + ); + return Ok(self.watch_list(url).await); + } + + async fn watch_list(&mut self, url: U) + where + U: Into, + { + let url = url.into(); let username = self.username.to_string(); let token = self.token.to_string(); let event_stream = self.event_writer.clone(); @@ -72,6 +97,5 @@ impl<'a> GithubCtl<'a> { } } }); - Ok(()) } }