-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic websocket client (plus sidetracked into router setup, was…
…ted hours and then found an easier solution lmao)
- Loading branch information
1 parent
e67852e
commit f22e4a6
Showing
6 changed files
with
154 additions
and
109 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use http::StatusCode; | ||
use webhook::models::Message; | ||
|
||
use crate::error::AppError; | ||
|
||
pub struct WebhookClient { | ||
client: reqwest::Client, | ||
url: String, | ||
} | ||
|
||
impl WebhookClient { | ||
pub fn new(url: &str) -> WebhookClient { | ||
WebhookClient { | ||
client: reqwest::Client::new(), | ||
url: url.to_owned(), | ||
} | ||
} | ||
|
||
/// Basically a simple recreation of webhook-rs client send implementation with reqwest | ||
pub async fn send(&self, message: &Message) -> Result<(), AppError> { | ||
let res = self.client.post(&self.url).json(message).send().await?; | ||
if res.status() == StatusCode::NO_CONTENT { | ||
Ok(()) | ||
} else { | ||
let err_msg = match res.text().await { | ||
Ok(msg) => msg, | ||
Err(err) => format!("Webhook reqwest client error: {}", err), | ||
}; | ||
Err(AppError::Webhook(err_msg)) | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.