Skip to content

Commit

Permalink
Merge pull request #95 from dten/release-0.23
Browse files Browse the repository at this point in the history
Release 0.23
  • Loading branch information
dten authored Jun 29, 2020
2 parents 94a638d + 62ab857 commit aa000e3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.23.0
* slack_api now provides async functions (enabled with "async" feature, on by default)
* slack_api::sync provides the original functions (enabled with "sync" feature)
* `Timestamp` type replaces all uses of string / u64 / f64 as timestamps

# 0.22.0
* Updates to API
* #68 Bot icons are sometimes an array
Expand Down
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ documentation = "https://docs.rs/slack_api"
license = "Apache-2.0"
name = "slack_api"
repository = "https://github.com/slack-rs/slack-rs-api.git"
version = "0.22.0"
version = "0.23.0"
edition = "2018"
readme = "README.md"

[dependencies]
serde = "1.0"
Expand Down Expand Up @@ -59,3 +60,8 @@ required-features = ["reqwest"]
name = "channel_history"
path = "examples/channel_history.rs"
required-features = ["reqwest"]

[[example]]
name = "channel_history_sync"
path = "examples/channel_history_sync.rs"
required-features = ["sync", "reqwest_blocking"]
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,33 @@

[Documentation][docs]

# Usage
## Usage

Add this to your `Cargo.toml`:
```toml
[dependencies]
slack_api = "0.21.0"
slack_api = "0.23.0"
```

and this to your crate root:
### Async
`default-features` include an async functions and client using [reqwest][reqwest]
See [async channel history example](examples/channel_histoy.hs)

```rust
extern crate slack_api;
```
### Sync
The `"sync"` feature provides sync functions and the `"reqwest_blocking"` feature provides a sync client using reqwest
See [sync channel history example](examples/channel_histoy_sync.hs)

## Slack docs
Slack's api is large and changes often. Their docs are high quality and no attempt to replicate them is made in this crate's docs. Please refer to their docs as your primary resource of how slack's api works.

## Providing own client
You can provide your own client by implementing the async or sync versions of `SlackWebRequestSender`.
Which should would allow avoiding `reqwest` and thus `tokio`.

## Something I need is missing
Not every method is available in this crate but if something is missing you would like then please log an issue. Bear in mind this is maintained in contributor's spare time and contributions are welcome.

# License
## License
`slack-api` is distributed under the [Apache-2.0 License](./LICENSE).

[docs]: https://docs.rs/slack_api
Expand All @@ -31,3 +43,5 @@ extern crate slack_api;
[license-img]: https://img.shields.io/github/license/mthjones/slack-rs-api.svg
[license-url]: https://raw.githubusercontent.com/mthjones/slack-rs-api/master/LICENSE
[slack]: https://api.slack.com/
[slack_web]: https://api.slack.com/web
[reqwest]: https://crates.io/crates/reqwest
33 changes: 33 additions & 0 deletions examples/channel_history_sync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use slack_api::sync as slack;

use std::env;

fn main() -> Result<(), Box<dyn std::error::Error>> {
// You can generate a legacy token to quickly test these apis
// https://api.slack.com/custom-integrations/legacy-tokens
let token = env::var("SLACK_API_TOKEN").map_err(|_| "SLACK_API_TOKEN env var must be set")?;
let client = slack::default_client().map_err(|_| "Could not get default_client")?;

let response = slack::channels::history(
&client,
&token,
&slack::channels::HistoryRequest {
channel: &env::args()
.nth(1)
.ok_or("must specify channel id as argument e.g. C09123456")?,
..slack::channels::HistoryRequest::default()
},
);

if let Ok(response) = response {
if let Some(messages) = response.messages {
for message in &messages {
println!("{:?}", message);
}
println!("Got {} messages:", messages.len());
}
} else {
println!("{:?}", response);
}
Ok(())
}

0 comments on commit aa000e3

Please sign in to comment.