Skip to content

Commit

Permalink
Added default timeout for HTTP client
Browse files Browse the repository at this point in the history
  • Loading branch information
christos-h committed Apr 29, 2021
1 parent 5fa035d commit 7b87db4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "posthog-rs"
license = "MIT"
version = "0.1.1"
version = "0.1.2"
authors = ["christos <[email protected]>"]
description = "An unofficial Rust client for Posthog (https://posthog.com/)."
repository = "https://github.com/openquery-io/posthog-rs"
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ use chrono::{NaiveDateTime};
use reqwest::blocking::Client as HttpClient;
use reqwest::header::CONTENT_TYPE;
use serde::{Serialize};

use std::time::Duration;

extern crate serde_json;

const API_ENDPOINT: &str = "https://app.posthog.com/capture/";
const TIMEOUT: &Duration = &Duration::from_millis(800); // This should be specified by the user

pub fn client<C: Into<ClientOptions>>(options: C) -> Client {
let client = HttpClient::builder().timeout(Some(TIMEOUT.clone())).build().unwrap(); // Unwrap here is as safe as `HttpClient::new`
Client {
options: options.into(),
client: HttpClient::new(),
client,
}
}

Expand Down Expand Up @@ -65,7 +67,6 @@ struct InnerEvent {
api_key: String,
event: String,
properties: Properties,
//#[serde(serialize_with = "serialize_timestamp", skip_serializing_if = "Option::is_none")]
timestamp: Option<NaiveDateTime>,
}

Expand Down Expand Up @@ -112,7 +113,6 @@ pub mod tests {
properties: Properties { distinct_id: "1234".to_string(), props },
timestamp: Some(Utc::now().naive_utc()),
};

let res = client.capture(event).unwrap();
client.capture(event).unwrap();
}
}

0 comments on commit 7b87db4

Please sign in to comment.