github_email/methods/
by_user_events.rs

1use super::*;
2
3/// Collect authors email from comment
4///
5/// API: <https://api.github.com/users/{USER}/events/public>
6pub async fn collect_user_events(user: &str, authors: &mut Authors) -> Result<()> {
7    let url = format!("https://api.github.com/users/{user}/events/public");
8    let out = Client::new().get(url).header(USER_AGENT, "octocat").send().await?;
9    let text = out.text().await?;
10    let value = Value::from_str(&text)?;
11    match &value {
12        Value::Array(events) => {
13            for event in events {
14                read_payload(event, authors);
15            }
16            return Ok(());
17        }
18        Value::Object(o) => match o.get("message").and_then(|v| v.as_str()) {
19            Some(s) => return Err(GithubError::RuntimeError(s.to_string())),
20            None => {}
21        },
22        _ => {}
23    };
24    Err(GithubError::RuntimeError(format!("Unknown response when call `collect_user_events`: {text}")))
25}