aboutsummaryrefslogtreecommitdiffstats
path: root/src/github.rs
diff options
context:
space:
mode:
authorTeddy Wing2021-06-12 18:25:49 +0200
committerTeddy Wing2021-06-12 18:25:49 +0200
commit46497bbae37f89e449b7a049663fe774843beb9b (patch)
tree89403988f141f61e0e2a78d655730e7cbc19dad8 /src/github.rs
parent6a6bacf975156a045cf48f9e58520f0bc0f54429 (diff)
downloadreflectub-46497bbae37f89e449b7a049663fe774843beb9b.tar.bz2
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.
Diffstat (limited to 'src/github.rs')
-rw-r--r--src/github.rs31
1 files changed, 12 insertions, 19 deletions
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 <https://www.gnu.org/licenses/>.
-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<Vec<Repo>, 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<Vec<Repo>, 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<Repo> = agent.get(
+ &format!(
"https://api.github.com/users/{}/repos?page={}&per_page=100&sort=updated",
github_username,
i,
),
)
- .send()
- .await?
- .json::<Vec<Repo>>()
- .await?;
+ .set("Accept", "application/vnd.github.v3+json")
+ .call()?
+ .into_json()?;
if repo_page.is_empty() {
break;