From 46497bbae37f89e449b7a049663fe774843beb9b Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Sat, 12 Jun 2021 18:25:49 +0200
Subject: Switch from 'reqwest' to 'ureq'; Remove async
Remove all async from the project by switching from 'reqwest' to 'ureq'.
This should make the code simpler, and hopefully enable us to try out
multithreading.
---
src/github.rs | 31 ++++++++++++-------------------
1 file changed, 12 insertions(+), 19 deletions(-)
(limited to 'src/github.rs')
diff --git a/src/github.rs b/src/github.rs
index 58f8983..5289a0d 100644
--- a/src/github.rs
+++ b/src/github.rs
@@ -16,7 +16,6 @@
// along with Reflectub. If not, see .
-use reqwest::ClientBuilder;
use serde::Deserialize;
use thiserror;
@@ -30,11 +29,11 @@ const USER_AGENT: &'static str = concat!(
#[derive(Debug, thiserror::Error)]
pub enum Error {
- #[error("request error")]
- Http(#[from] reqwest::Error),
+ #[error("GitHub request error")]
+ Http(#[from] ureq::Error),
- #[error("request header error")]
- Header(#[from] reqwest::header::InvalidHeaderValue),
+ #[error("GitHub I/O error")]
+ Io(#[from] std::io::Error),
}
@@ -61,30 +60,24 @@ impl Repo {
/// Fetch all GitHub repositories for the given user.
-pub async fn fetch_repos(github_username: &str) -> Result, Error> {
- let mut headers = reqwest::header::HeaderMap::new();
- headers.insert("Accept", "application/vnd.github.v3+json".parse()?);
-
- let client = ClientBuilder::new()
+pub fn fetch_repos(github_username: &str) -> Result, Error> {
+ let agent = ureq::AgentBuilder::new()
.user_agent(USER_AGENT)
- .default_headers(headers)
- .build()?;
+ .build();
let mut repos = Vec::new();
for i in 1.. {
- let repo_page = client.request(
- reqwest::Method::GET,
- format!(
+ let repo_page: Vec = agent.get(
+ &format!(
"https://api.github.com/users/{}/repos?page={}&per_page=100&sort=updated",
github_username,
i,
),
)
- .send()
- .await?
- .json::>()
- .await?;
+ .set("Accept", "application/vnd.github.v3+json")
+ .call()?
+ .into_json()?;
if repo_page.is_empty() {
break;
--
cgit v1.2.3