Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ license = "MIT/Apache-2.0"
name = "slack-hook"
readme = "README.md"
repository = "https://github.com/frostly/rust-slack"
version = "0.8.0"
version = "0.9.0"

[dependencies]
chrono = "0.4"
reqwest = "0.9"
hex = "0.3"
error-chain = "~0.11"
futures = "0.1.28"
serde = "1"
serde_derive = "1"
serde_json = "1"
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern crate reqwest;
extern crate chrono;
#[macro_use]
extern crate error_chain;
extern crate futures;
extern crate hex as hexx;
extern crate serde;
#[macro_use]
Expand Down
31 changes: 27 additions & 4 deletions src/slack.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use chrono::NaiveDateTime;
use error::{Error, ErrorKind, Result};
use reqwest::{Client, Url};
use futures::*;
use reqwest::async::Client;
use reqwest::Url;
use serde::{Serialize, Serializer};
use std::fmt;
use {Payload, TryInto};
Expand All @@ -23,14 +25,35 @@ impl Slack {

/// Send payload to slack service
pub fn send(&self, payload: &Payload) -> Result<()> {
let response = self.client.post(self.hook.clone()).json(payload).send()?;

if response.status().is_success(){
let response = self
.client
.post(self.hook.clone())
.json(payload)
.send()
.wait()?;

if response.status().is_success() {
Ok(())
} else {
Err(ErrorKind::Slack(format!("HTTP error {}", response.status())).into())
}
}

/// Send payload to slack service, returning a future Response.
pub fn async_send(&self, payload: &Payload) -> impl Future<Item = (), Error = Error> {
self.client
.post(self.hook.clone())
.json(payload)
.send()
.map_err(|err| err.into())
.and_then(|response| {
if response.status().is_success() {
Ok(())
} else {
Err(ErrorKind::Slack(format!("HTTP error {}", response.status())).into())
}
})
}
}

/// Slack timestamp
Expand Down