Skip to content

Commit

Permalink
add github/website commands to open links
Browse files Browse the repository at this point in the history
  • Loading branch information
ooojustin committed Oct 7, 2023
1 parent 65522e0 commit 7151307
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum Commands {
#[arg(short = 'C', long)]
copy: bool,
},
/// Open a specified email.
/// Open a specific email by providing the ID.
Open {
/// The ID of the email.
#[arg()]
Expand All @@ -42,5 +42,9 @@ pub enum Commands {
copy: bool,
},
/// Display the duration until the current inbox expires.
Expires
Expires,
/// Open the website that this program uses behind the scenes.
Website,
/// Open the GitHub repository for this application.
Github,
}
13 changes: 4 additions & 9 deletions src/inbox.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[path = "cookies.rs"]
mod cookies;
mod utils;
mod date_time;
pub mod utils;
pub mod email;

use serde::Deserialize;
Expand All @@ -11,7 +11,7 @@ use reqwest_cookie_store::CookieStoreMutex;
use email::Email;
use chrono::{Duration, DateTime, Utc};

const DISPOSABLE_MAIL: &str = "https://www.disposablemail.com";
pub const DISPOSABLE_MAIL: &str = "https://www.disposablemail.com";

/// A disposable email inbox.
pub struct Inbox {
Expand Down Expand Up @@ -94,7 +94,8 @@ impl Inbox {
Ok(())
}

async fn get_exp_delta(&self) -> Result<Duration> {
/// Determine how long it will be until this inbox expires.
pub async fn get_exp_delta(&self) -> Result<Duration> {
let response = self.client.get(format!("{}/index/zivot", DISPOSABLE_MAIL))
.headers(utils::headers(true))
.send()
Expand All @@ -107,12 +108,6 @@ impl Inbox {
Ok(li.end - li.now)
}

pub async fn get_exp_delta_string(&self) -> Result<String> {
let delta: Duration = self.get_exp_delta().await?;
let delta_str = utils::format_duration(delta);
Ok(delta_str)
}

/// Print cookies stored in Inbox.
#[allow(dead_code)]
pub fn print_cookies(&self) {
Expand Down
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,21 @@ async fn main() {
},
args::Commands::Expires => {
println!("Email address: {}", ai.email);
match inbox.get_exp_delta_string().await {
Ok(expires) => println!("Expires: {}", expires),
match inbox.get_exp_delta().await {
Ok(delta) => {
let expires = inbox::utils::format_duration(delta);
println!("Expires: {}", expires);
},
Err(err) => eprintln!("Failed to determine inbox expiration: {}", err)
}
},
args::Commands::Website => {
inbox::utils::open(inbox::DISPOSABLE_MAIL.to_string());
println!("Opened DisposableMail website in browser.");
},
args::Commands::Github => {
inbox::utils::open("https://github.com/ooojustin/clinbox".to_string());
println!("Opened clinbox GitHub repository in browser.");
}
}

Expand Down

0 comments on commit 7151307

Please sign in to comment.