You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB
Rust

use std::collections::HashMap;
pub struct GithubCtl<'a> {
username: &'a str,
token: &'a str,
http_client: reqwest::Client,
}
impl<'a> GithubCtl<'a> {
pub fn new(username: &'a str, token: &'a str) -> Result<Self, Box<dyn std::error::Error>> {
let http_client = reqwest::Client::new();
Ok(GithubCtl { username, token, http_client })
}
pub async fn get_events<O, R>(
&mut self,
owner: O,
repo: R,
) -> Result<(), Box<dyn std::error::Error>>
where
O: AsRef<str>,
R: AsRef<str>,
{
// /repos/{owner}/{repo}/events
// -H "Accept: application/vnd.github.v3+json"
// https://api.github.com/orgs/ORG/events
// -u username:token
// https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
let url = format!("https://api.github.com/repos/{owner}/{repo}/events", owner=owner.as_ref(), repo=repo.as_ref());
let resp = self.http_client.get(url).basic_auth(self.username, Some(self.token)).send().await?;
// let body = resp.json::<HashMap<String, String>>().await?;
// let resp = reqwest::get(url)
// .await?
// .json::<HashMap<String, String>>()
// .await?;
println!("{:#?}", body);
Ok(())
}
}