Skip to content

Instantly share code, notes, and snippets.

@zupzup
zupzup / main.rs
Created December 2, 2020 12:49
Timeular Webhooks Call List Subscriptions
println!("listing subscriptions...");
let subscriptions = list_subscriptions(&token).await?;
println!("subscriptions: {:?}", subscriptions);
@zupzup
zupzup / main.rs
Created December 2, 2020 12:47
Timeular Webhooks List Subscriptions
#[derive(Deserialize, Debug)]
struct SubscriptionsResponse {
subscriptions: Vec<Subscription>,
}
#[derive(Deserialize, Debug)]
struct Subscription {
id: String,
event: String,
target_url: String,
@zupzup
zupzup / shell
Created December 2, 2020 12:26
Timeular Webhooks Response 2
time entry was created with data: TrackingStoppedPayload { user_id: "1234", event_type: "trackingStopped", data: TrackingStoppedData { new_time_entry: Some(TimeEntry { id: "1234", activity: Activity { id: "1234", name: "Misc", color: "#17bbd2", integration: "zei", space_id: "1234", device_side: None }, duration: Duration { started_at: "2020-11-30T07:08:52.203", stopped_at: "2020-11-30T08:08:59.789" }, note: Note { text: None, tags: [], mentions: [] } }) } }
@zupzup
zupzup / shell
Created December 2, 2020 12:26
Timeular Webhooks Response 1
tracking was started with data: TrackingStartedPayload { user_id: "1234", event_type: "trackingStarted", data: TrackingStartedData { current_tracking: Tracking { id: 1234, activity: Activity { id: "1234", name: "Misc", color: "#17bbd2", integration: "zei", space_id: "1234", device_side: None }, started_at: "2020-11-30T07:08:52.203", note: Note { text: None, tags: [], mentions: [] } } } }
@zupzup
zupzup / shell
Created December 2, 2020 12:25
Timeular Webhooks Test
PUBLIC_URL=the-url-from-localtunnel TMLR_API_KEY=secret TMLR_API_SECRET=secret cargo run
@zupzup
zupzup / main.rs
Created December 2, 2020 12:25
Timeular Webhooks Server
let health_route = warp::path!("health").and_then(health_handler);
warp::serve(
started_tracking_route
.or(stopped_tracking_route)
.or(health_route),
)
.run(([0, 0, 0, 0], 8000))
.await;
Ok(())
@zupzup
zupzup / main.rs
Created December 2, 2020 12:25
Timeular Webhooks Types
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct TrackingStartedPayload {
user_id: String,
event_type: String,
data: TrackingStartedData,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
@zupzup
zupzup / main.rs
Created December 2, 2020 12:25
Timeular Webhooks Handlers
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")
}
@zupzup
zupzup / main.rs
Created December 2, 2020 12:24
Timeular Webhooks Routes
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);
@zupzup
zupzup / gist:5120b3e4cb640dd057d55f0d7736675e
Created December 2, 2020 12:01
Timeular Webhooks Subscription
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?;