Skip to main content

influent/
lib.rs

1extern crate tokio;
2extern crate tokio_executor;
3extern crate futures;
4extern crate http;
5extern crate base64;
6extern crate hyper;
7extern crate url;
8
9pub mod client;
10pub mod hurl;
11pub mod serializer;
12pub mod measurement;
13
14use client::Credentials;
15use client::http::HttpClient;
16use hurl::hyper::HyperHurl;
17use serializer::line::LineSerializer;
18
19/// Simple factory of `HttpClient` with `LineSerializer`
20///
21/// Takes two parameters, where first is `Credentials` struct, and second - `Vec<&str>`, where each item
22/// is a InfluxDB host url.
23///
24/// # Examples
25///
26/// ```
27/// use influent::create_client;
28/// use influent::client::Credentials;
29///
30/// let credentials = Credentials {
31///     username: "gobwas",
32///     password: "xxx",
33///     database: "mydb"
34/// };
35///
36/// let client = create_client(credentials, vec!["http://localhost:8086"]);
37/// ```
38pub fn create_client<'a>(credentials: Credentials<'a>, hosts: Vec<&'a str>) -> HttpClient<'a> {
39    let mut client = HttpClient::new(credentials, Box::new(LineSerializer::new()), Box::new(HyperHurl::new()));
40
41    for host in hosts {
42        client.add_host(host);
43    }
44
45    client
46}
47