This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async fn started_tracking_handler(body: TrackingStartedPayload) -> WebResult<impl Reply> { | |
println!("tracking was started with data: {:?}", body); | |
Ok("OK") | |
} | |
async fn stopped_tracking_handler(body: TrackingStoppedPayload) -> WebResult<impl Reply> { | |
println!("time entry was created with data: {:?}", body); | |
Ok("OK") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let started_tracking_route = warp::path!("started-tracking") | |
.and(warp::post()) | |
.and(warp::body::json()) | |
.and_then(started_tracking_handler); | |
let stopped_tracking_route = warp::path!("stopped-tracking") | |
.and(warp::post()) | |
.and(warp::body::json()) | |
.and_then(stopped_tracking_handler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println!("subscribing to started tracking..."); | |
subscribe_to_started_tracking(&token, &public_url).await?; | |
println!("subscribing to stopped tracking..."); | |
subscribe_to_stopped_tracking(&token, &public_url).await?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async fn subscribe_to_started_tracking(token: &str, public_url: &str) -> Result<(), Error> { | |
let body = EventRequest { | |
event: "trackingStarted", | |
target_url: format!("{}/started-tracking", public_url), | |
}; | |
let resp = CLIENT | |
.post(&url("/webhooks/subscription")) | |
.header("Authorization", auth(token)) | |
.json(&body) | |
.send() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Serialize, Debug)] | |
struct EventRequest { | |
event: &'static str, | |
target_url: String, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println!("fetching available events..."); | |
let events = fetch_events(&token).await?; | |
println!("available events: {:?}", events); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Deserialize, Debug)] | |
struct EventsResponse { | |
events: Vec<String>, | |
} | |
async fn fetch_events(token: &str) -> Result<Vec<String>, Error> { | |
let resp = CLIENT | |
.get(&url("/webhooks/event")) | |
.header("Authorization", auth(token)) | |
.send() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[tokio::main] | |
async fn main() -> Result<(), Error> { | |
let public_url = env::var("PUBLIC_URL").expect("PUBLIC_URL needs to be set"); | |
let api_key = env::var("TMLR_API_KEY").expect("TMLR_API_KEY needs to be set"); | |
let api_secret = env::var("TMLR_API_SECRET").expect("TMLR_API_SECRET needs to be set"); | |
println!("signing in.."); | |
let token = sign_in(api_key, api_secret).await?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lt --port 8000 | |
your url is: https://friendly-mule-3.loca.lt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[dependencies] | |
reqwest = { version = "0.10", features = ["json"] } | |
tokio = { version = "0.2", features = ["macros", "rt-threaded"] } | |
serde = {version = "1.0", features = ["derive"] } | |
serde_json = "1.0" | |
once_cell = "1.4" | |
warp = "0.2" |