blob: f6e4a37b8b66b358cd4751302783f0dd882943ba (
plain) (
tree)
|
|
mod client;
mod config;
mod message;
use clap::{crate_version, Parser};
use std::path::PathBuf;
use std::process::exit;
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
#[clap(version = crate_version!())]
struct Args {
#[clap(short, long, value_parser)]
config: PathBuf,
#[clap(subcommand)]
subcmd: message::MessageKind,
}
const TWILIO_BASE_URL: &str = "https://api.twilio.com";
fn main() {
let args = Args::parse();
let config: config::Config = match config::Config::load_from_file(&args.config) {
Ok(config) => config,
Err(e) => {
eprintln!("unable to load data from {}: {}", args.config.display(), e);
exit(1);
}
};
let msg = message::Message::builder()
.from(config.from.to_owned())
.to(config.to.to_owned())
.with_action(args.subcmd, &config)
.build();
let client = client::TwilioClient::new(
&config.account_sid,
&config.auth_token,
reqwest::Url::parse(TWILIO_BASE_URL).unwrap(),
);
match client.send(msg) {
Ok(m) => println!("message sent successfully: status is {:?}", m.status),
Err(error) => {
eprintln!("failed to send the message: {}", error);
exit(1);
}
}
}
|