Skip to content
Closed
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
33 changes: 21 additions & 12 deletions src/slack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ impl Slack {
pub fn send(&self, payload: &Payload) -> Result<()> {
let response = self.client.post(self.hook.clone()).json(payload).send()?;

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

/// Construct a new instance of slack for a specific incoming url endpoint with a proxy tunnel.
pub fn new_with_proxy<T: TryInto<Url, Err = Error>>(hook: T, proxy: T) -> Result<Slack> {
Ok(Slack {
hook: hook.try_into()?,
client: reqwest::Client::builder()
.proxy(reqwest::Proxy::all(proxy.try_into()?)?)
.build()?,
})
}
}

/// Slack timestamp
Expand Down Expand Up @@ -113,7 +123,8 @@ impl<'a> From<&'a [SlackTextContent]> for SlackText {
SlackTextContent::Text(ref s) => format!("{}", s),
SlackTextContent::Link(ref link) => format!("{}", link),
SlackTextContent::User(ref u) => format!("{}", u),
}).collect::<Vec<String>>()
})
.collect::<Vec<String>>()
.join(" ");
SlackText::new_raw(st)
}
Expand Down Expand Up @@ -245,16 +256,14 @@ mod test {

#[test]
fn json_complete_payload_test() {
let a = vec![
AttachmentBuilder::new("fallback <&>")
.text("text <&>")
.color("#6800e8")
.fields(vec![Field::new("title", "value", None)])
.title_link("https://title_link.com/")
.ts(&NaiveDateTime::from_timestamp(123_456_789, 0))
.build()
.unwrap(),
];
let a = vec![AttachmentBuilder::new("fallback <&>")
.text("text <&>")
.color("#6800e8")
.fields(vec![Field::new("title", "value", None)])
.title_link("https://title_link.com/")
.ts(&NaiveDateTime::from_timestamp(123_456_789, 0))
.build()
.unwrap()];

let p = PayloadBuilder::new()
.text("test message")
Expand Down