Making API request but failing to decode the results.
parent
857c237319
commit
b7111994cd
@ -1 +1,5 @@
|
|||||||
/target
|
/target
|
||||||
|
.pat
|
||||||
|
.username
|
||||||
|
.org
|
||||||
|
.repo
|
||||||
|
@ -1 +1,39 @@
|
|||||||
pub struct GithubCtl {}
|
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(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
mod githubctl;
|
mod githubctl;
|
||||||
|
|
||||||
|
const USERNAME: &'static str = include_str!("../.username");
|
||||||
|
const TOKEN: &'static str = include_str!("../.pat");
|
||||||
|
const ORG: &'static str = include_str!("../.org");
|
||||||
|
const REPO: &'static str = include_str!("../.repo");
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("Hello, world!");
|
let mut github = githubctl::GithubCtl::new(USERNAME, TOKEN)?;
|
||||||
|
github.get_events(ORG, REPO).await?;
|
||||||
|
println!("done.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue