aboutsummaryrefslogtreecommitdiffstats
path: root/src/github.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/github.rs')
-rw-r--r--src/github.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/github.rs b/src/github.rs
new file mode 100644
index 0000000..bf42fc8
--- /dev/null
+++ b/src/github.rs
@@ -0,0 +1,36 @@
+use reqwest::blocking::ClientBuilder;
+
+use crate::repo::Repo;
+
+
+const USER_AGENT: &'static str = concat!(
+ env!("CARGO_PKG_NAME"),
+ "/",
+ env!("CARGO_PKG_VERSION"),
+);
+
+
+pub fn fetch_repos() -> Result<Vec<Repo>, Box<dyn std::error::Error>> {
+ let mut headers = reqwest::header::HeaderMap::new();
+ headers.insert("Accept", "application/vnd.github.v3+json".parse().unwrap());
+
+ let client = ClientBuilder::new()
+ .user_agent(USER_AGENT)
+ .default_headers(headers)
+ .build()
+ .unwrap();
+
+ let repos = client.request(
+ reqwest::Method::GET,
+ format!(
+ "https://api.github.com/users/{}/repos",
+ "teddywing",
+ ),
+ )
+ .send()
+ .unwrap()
+ .json::<Vec<Repo>>()
+ .unwrap();
+
+ Ok(repos)
+}