Skip to content

Commit 9415f39

Browse files
committed
repub reqwest
1 parent d8219d7 commit 9415f39

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/client.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,33 @@ use crate::{error, serialization, ChunkedQuery, Node, Point, Points, Precision,
99
/// The client to influxdb
1010
#[derive(Debug, Clone)]
1111
pub struct Client {
12-
host: String,
12+
host: Url,
1313
db: String,
1414
authentication: Option<(String, String)>,
1515
client: HttpClient,
1616
}
1717

1818
impl Client {
1919
/// Create a new influxdb client with http
20-
pub fn new<T>(host: T, db: T) -> Self
20+
pub fn new<T>(host: Url, db: T) -> Self
2121
where
2222
T: Into<String>,
2323
{
2424
Client {
25-
host: host.into(),
25+
host,
2626
db: db.into(),
2727
authentication: None,
2828
client: HttpClient::default(),
2929
}
3030
}
3131

3232
/// Create a new influxdb client with custom reqwest's client.
33-
pub fn new_with_client<T>(host: T, db: T, client: HttpClient) -> Self
33+
pub fn new_with_client<T>(host: Url, db: T, client: HttpClient) -> Self
3434
where
3535
T: Into<String>,
3636
{
3737
Client {
38-
host: host.into(),
38+
host,
3939
db: db.into(),
4040
authentication: None,
4141
client,
@@ -452,7 +452,7 @@ impl Client {
452452

453453
/// Constructs the full URL for an API call.
454454
fn build_url(&self, key: &str, param: Option<Vec<(&str, &str)>>) -> Url {
455-
let url = Url::parse(&self.host).unwrap().join(key).unwrap();
455+
let url = self.host.join(key).unwrap();
456456

457457
let mut authentication = Vec::new();
458458

@@ -474,7 +474,7 @@ impl Client {
474474
impl Default for Client {
475475
/// connecting for default database `test` and host `http://localhost:8086`
476476
fn default() -> Self {
477-
Client::new("http://localhost:8086", "test")
477+
Client::new(Url::parse("http://localhost:8086").unwrap(), "test")
478478
}
479479
}
480480

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ pub(crate) mod serialization;
7070
pub use client::{Client, UdpClient};
7171
pub use error::Error;
7272
pub use keys::{ChunkedQuery, Node, Point, Points, Precision, Query, Series, Value};
73+
74+
pub use reqwest;

tests/client_test.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use influx_db_client::{point, points, Client, Point, Points, Precision, UdpClient, Value};
1+
use influx_db_client::{
2+
point, points, reqwest::Url, Client, Point, Points, Precision, UdpClient, Value,
3+
};
24
use std::fs::File;
35
use std::io::Read;
46
use std::thread::sleep;
@@ -242,7 +244,11 @@ bind-address = "127.0.0.1:{rpc_port}"
242244
.unwrap();
243245

244246
let host = format!("https://localhost:{}", http_port);
245-
let client = Client::new_with_client(host.as_str(), "test_use_https", http_client);
247+
let client = Client::new_with_client(
248+
Url::parse(host.as_str()).unwrap(),
249+
"test_use_https",
250+
http_client,
251+
);
246252

247253
block_on(async {
248254
client.create_database(client.get_db()).await.unwrap();

0 commit comments

Comments
 (0)