This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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)] | |
#[serde(rename_all = "camelCase")] | |
struct SignInRequest { | |
api_key: String, | |
api_secret: String, | |
} | |
#[derive(Deserialize, Debug)] | |
struct SignInResponse { | |
token: String, |
This file contains hidden or 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 hidden or 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 hidden or 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" |
This file contains hidden or 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
export TMLR_API_KEY=<your api key> | |
export TMLR_API_SECRET=<your api secret> | |
cargo run |
This file contains hidden or 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
use tokio::fs; | |
async fn generate_report(token: &str) -> Result<(), Error> { | |
let resp = CLIENT | |
.get(&url( | |
"/report/2020-01-01T00:00:00.000/2020-12-31T23:59:59.999?timezone=Europe/Vienna", | |
)) | |
.header("Authorization", auth(token)) | |
.send() | |
.await? |