aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/github.rs36
-rw-r--r--src/lib.rs2
-rw-r--r--src/main.rs45
-rw-r--r--src/repo.rs13
4 files changed, 54 insertions, 42 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)
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..fe2cab4
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,2 @@
+pub mod github;
+pub mod repo;
diff --git a/src/main.rs b/src/main.rs
index 14d5f4d..ea540e6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,47 +1,8 @@
-use reqwest::blocking::ClientBuilder;
-use serde::Deserialize;
-
-
-const USER_AGENT: &'static str = concat!(
- env!("CARGO_PKG_NAME"),
- "/",
- env!("CARGO_PKG_VERSION"),
-);
-
-
-#[derive(Debug, Deserialize)]
-struct Repo {
- id: usize,
- name: String,
- description: Option<String>,
- fork: bool,
- git_url: String,
- default_branch: String,
- updated_at: String, // TODO: Maybe parse to date?
-}
+use reflectub::github;
fn main() {
- 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 response = client.request(
- reqwest::Method::GET,
- format!(
- "https://api.github.com/users/{}/repos",
- "teddywing",
- ),
- )
- .send()
- .unwrap()
- .json::<Vec<Repo>>()
- .unwrap();
+ let repos = github::fetch_repos().unwrap();
- dbg!(&response);
+ dbg!(&repos);
}
diff --git a/src/repo.rs b/src/repo.rs
new file mode 100644
index 0000000..e934be2
--- /dev/null
+++ b/src/repo.rs
@@ -0,0 +1,13 @@
+use serde::Deserialize;
+
+
+#[derive(Debug, Deserialize)]
+pub struct Repo {
+ id: usize,
+ name: String,
+ description: Option<String>,
+ fork: bool,
+ git_url: String,
+ default_branch: String,
+ updated_at: String, // TODO: Maybe parse to date?
+}