Skip to content

Commit

Permalink
Check for todos
Browse files Browse the repository at this point in the history
  • Loading branch information
alanvardy committed Apr 9, 2023
1 parent c00cdeb commit d82cc29
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 76 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 2023-04-08 v0.3.8

- Left some dbg! statements in the code like a doofus

## 2023-04-08 v0.3.7

- Prompt for section when moving an item to a project with sections
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tod"
version = "0.3.7"
version = "0.3.8"
authors = ["Alan Vardy <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion PUBLISH_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cargo aur

9. [Create a new release](https://github.com/alanvardy/tod/releases/new)

- Make sure to use the label and title in format `v0.3.7`
- Make sure to use the label and title in format `v0.3.8`
- Add binary from tod directory

10. Publish to Cargo with `cargo publish`
Expand Down
2 changes: 1 addition & 1 deletion push_aur.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ mv PKGBUILD ../tod-bin/
rm *.tar.gz
cd ../tod-bin/
git add .
git commit -m v0.3.7
git commit -m new version
git push aur
cd ../tod
128 changes: 56 additions & 72 deletions src/request.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::env;

use reqwest::blocking::Client;
use reqwest::header::AUTHORIZATION;
use reqwest::header::CONTENT_TYPE;
Expand Down Expand Up @@ -126,33 +128,21 @@ fn post_todoist_sync(
let _placeholder = config.clone().mock_url;

#[cfg(test)]
let todoist_url: String = config.clone().mock_url.expect("Mock URL not set");
let todoist_url: String = config.mock_url.clone().expect("Mock URL not set");

let request_url = format!("{todoist_url}{url}");
let token = config.token;

let response = if let Some(false) = config.spinners {
Client::new()
.post(request_url)
.header(CONTENT_TYPE, "application/json")
.header(AUTHORIZATION, format!("Bearer {token}"))
.json(&body)
.send()
.or(Err("Did not get response from server"))?
} else {
let mut sp = Spinner::new(SPINNER, MESSAGE.into());
let response = Client::new()
.post(request_url)
.header(CONTENT_TYPE, "application/json")
.header(AUTHORIZATION, format!("Bearer {token}"))
.json(&body)
.send()
.or(Err("Did not get response from server"))?;
let token = config.token.clone();

sp.stop();
print!("\x1b[2K\r");
response
};
let spinner = maybe_start_spinner(config);
let response = Client::new()
.post(request_url)
.header(CONTENT_TYPE, "application/json")
.header(AUTHORIZATION, format!("Bearer {token}"))
.json(&body)
.send()
.or(Err("Did not get response from server"))?;

maybe_stop_spinner(spinner);

if response.status().is_success() {
Ok(response.text().or(Err("Could not read response text"))?)
Expand All @@ -171,37 +161,24 @@ fn post_todoist_rest(
let todoist_url: String = "https://api.todoist.com".to_string();

#[cfg(test)]
let todoist_url: String = config.mock_url.expect("Mock URL not set");
let todoist_url: String = config.mock_url.clone().expect("Mock URL not set");

let token = config.token;
let token = config.token.clone();

let request_url = format!("{todoist_url}{url}");
let authorization: &str = &format!("Bearer {token}");
let spinner = maybe_start_spinner(config);

let response = if let Some(false) = config.spinners {
Client::new()
.post(request_url)
.header(CONTENT_TYPE, "application/json")
.header(AUTHORIZATION, authorization)
.header("X-Request-Id", new_uuid())
.json(&body)
.send()
.or(Err("Did not get response from server"))?
} else {
let mut sp = Spinner::new(SPINNER, MESSAGE.into());
let response = Client::new()
.post(request_url)
.header(CONTENT_TYPE, "application/json")
.header(AUTHORIZATION, authorization)
.header("X-Request-Id", new_uuid())
.json(&body)
.send()
.or(Err("Did not get response from server"))?;
let response = Client::new()
.post(request_url)
.header(CONTENT_TYPE, "application/json")
.header(AUTHORIZATION, authorization)
.header("X-Request-Id", new_uuid())
.json(&body)
.send()
.or(Err("Did not get response from server"))?;

sp.stop();
print!("\x1b[2K\r");
response
};
maybe_stop_spinner(spinner);

if response.status().is_success() {
Ok(response.text().or(Err("Could not read response text"))?)
Expand All @@ -217,33 +194,21 @@ fn get_todoist_rest(config: Config, url: String) -> Result<String, String> {
let todoist_url: String = "https://api.todoist.com".to_string();

#[cfg(test)]
let todoist_url: String = config.mock_url.expect("Mock URL not set");
let todoist_url: String = config.mock_url.clone().expect("Mock URL not set");

let token = dbg!(config.token);
let token = config.token.clone();

let request_url = dbg!(format!("{todoist_url}{url}"));
let request_url = format!("{todoist_url}{url}");
let authorization: &str = &format!("Bearer {token}");
let spinner = maybe_start_spinner(config);
let response = Client::new()
.get(request_url)
.header(CONTENT_TYPE, "application/json")
.header(AUTHORIZATION, authorization)
.send()
.or(Err("Did not get response from server"))?;

let response = if let Some(false) = config.spinners {
Client::new()
.get(request_url)
.header(CONTENT_TYPE, "application/json")
.header(AUTHORIZATION, authorization)
.send()
.or(Err("Did not get response from server"))?
} else {
let mut sp = Spinner::new(SPINNER, MESSAGE.into());
let response = Client::new()
.get(request_url)
.header(CONTENT_TYPE, "application/json")
.header(AUTHORIZATION, authorization)
.send()
.or(Err("Did not get response from server"))?;

sp.stop();
print!("\x1b[2K\r");
response
};
maybe_stop_spinner(spinner);

if response.status().is_success() {
Ok(response.text().or(Err("Could not read response text"))?)
Expand Down Expand Up @@ -288,6 +253,25 @@ fn new_uuid() -> String {
}
}

fn maybe_start_spinner(config: Config) -> Option<Spinner> {
match env::var("DISABLE_SPINNER") {
Ok(_) => None,
_ => {
if let Some(true) = config.spinners {
let sp = Spinner::new(SPINNER, MESSAGE.into());
Some(sp)
} else {
None
}
}
}
}
fn maybe_stop_spinner(spinner: Option<Spinner>) {
if let Some(mut sp) = spinner {
sp.stop();
print!("\x1b[2K\r");
};
}
#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit d82cc29

Please sign in to comment.