summaryrefslogtreecommitdiff
path: root/src/client/connector/connectors
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/connector/connectors')
-rw-r--r--src/client/connector/connectors/httpconnector.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/client/connector/connectors/httpconnector.rs b/src/client/connector/connectors/httpconnector.rs
index 2a7c0d8..923df94 100644
--- a/src/client/connector/connectors/httpconnector.rs
+++ b/src/client/connector/connectors/httpconnector.rs
@@ -1,4 +1,4 @@
-use reqwest::{Error, StatusCode, Url, blocking::get};
+use reqwest::{Error, StatusCode, Url, blocking::Client};
use crate::connector::*;
use std::{thread::sleep, time::Duration};
@@ -6,13 +6,16 @@ use std::{thread::sleep, time::Duration};
pub(crate) struct HTTPConnector {
prev: String,
url: Url,
+ client: Client,
}
impl HTTPConnector {
- pub fn new(url: &str) -> Result<Self, url::ParseError> {
+ pub fn new(url: &str) -> std::result::Result<Self, url::ParseError> {
Ok(Self {
prev: String::new(),
url: Url::parse(url)?,
+ // TODO: keep alive
+ client: Client::new(),
})
}
}
@@ -34,8 +37,8 @@ impl std::fmt::Display for Err {
impl Connection for HTTPConnector {
type Err = Err;
- fn update(&self) -> Option<Result<Self::Success, Self::Err>> {
- let res = match get(self.url.as_str()) {
+ fn update(&self) -> Option<Result<Self::Ok, Self::Err>> {
+ let resp = match self.client.get(self.url.as_str()).send() {
Ok(resp) => match resp.status() {
StatusCode::TOO_MANY_REQUESTS => {
sleep(Duration::from_secs(5));
@@ -43,23 +46,25 @@ impl Connection for HTTPConnector {
}
status => {
if !status.is_success() {
- return Some(Err(Err::StatusCode(status)));
+ return Some(Result::Err(Err::StatusCode(status)));
}
match resp.text() {
Ok(text) => text,
- Err(e) => return Some(Err(Err::Reqwest(e))),
+ Err(e) => return Some(Result::Err(Err::Reqwest(e))),
}
}
},
- Err(e) => return Some(Err(Err::Reqwest(e))),
+ Err(e) => return Some(Result::Err(Err::Reqwest(e))),
};
- if res == self.prev {
+ if resp == self.prev {
return None;
}
- Some(Ok(res))
+ Some(Result::Ok(resp))
}
- // fn ntfy<T>(&self, data: T) {}
+ fn ntfy(&self, data: String) {
+ println!("{}", data)
+ }
}