Skip to content

Commit

Permalink
Formatter trait
Browse files Browse the repository at this point in the history
  • Loading branch information
shettysach committed Mar 21, 2024
1 parent 0068ce3 commit 707cdc5
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 152 deletions.
2 changes: 1 addition & 1 deletion configs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Sachith C Shetty",
"intro": "Hello, I'm Sachith. I'm a CSE student, currently exploring AI/ML and memory safe languages like Rust. I am passionate about creating projects and learning how to code well.",

"interests": ["Artificial Intelligence", "Machine Learning", "LLMs", "Linux", "Embedded Systems", "Wasm (Web Assembly)", "APIs", "CLIs / TUIs"],
"interests": ["Artificial Intelligence", "Machine Learning", "LLMs", "GNU-Linux", "CLIs / TUIs", "Embedded Systems", "WASM"],

"langs": ["Rust", "Python", "C++", "Bash", "Dart"],

Expand Down
24 changes: 16 additions & 8 deletions src/commands/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn read_config() -> Option<Config> {

pub fn get_about() -> String {
match read_config() {
Some(config) => format_about(config.about),
Some(config) => config.about.formatter(),
_ => String::from(READ_JSON_ERROR),
}
}
Expand All @@ -59,7 +59,7 @@ pub async fn get_repos() -> String {

pub fn get_contacts() -> &'static String {
CONTACTS.get_or_init(|| match read_config() {
Some(config) => format_contacts(&config.links),
Some(config) => config.links.formatter(),
_ => String::from(READ_JSON_ERROR),
})
}
Expand All @@ -80,10 +80,14 @@ async fn fetch_github() -> String {
}) {
Ok((info_response, stats_response)) => {
if info_response.status().is_success() && stats_response.status().is_success() {
let user_info: UserInfo = info_response.json().await.unwrap();
let user_stats: UserStats = stats_response.json().await.unwrap();

format_github(config.github, config.about.langs, user_info, user_stats)
let account = Account {
username: config.github,
langs: config.about.langs,
info: info_response.json().await.unwrap(),
stats: stats_response.json().await.unwrap(),
};

account.formatter()
} else {
String::from(FETCH_GITHUB_ERROR)
}
Expand All @@ -105,8 +109,12 @@ async fn fetch_repos() -> String {

match reqwest::get(&repos_url).await {
Ok(response) => {
let repos: ApiResponse = response.json().await.unwrap();
format_repos(config.github, repos.response)
let api_response: ApiResponse = response.json().await.unwrap();
let repos = Repos {
username: config.github,
repos: api_response.response,
};
repos.formatter()
}
Err(_) => String::from(FETCH_GITHUB_ERROR),
}
Expand Down
Loading

0 comments on commit 707cdc5

Please sign in to comment.