Skip to content

Commit

Permalink
PubNub SDK 0.5.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
pubnub-release-bot committed Jan 25, 2024
1 parent 2039949 commit d9e91ac
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 54 deletions.
13 changes: 12 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
name: rust
version: 0.4.1
version: 0.5.0
schema: 1
scm: github.com/pubnub/rust
files: []
changelog:
- date: 2024-01-25
version: 0.5.0
changes:
- type: feature
text: "Change the real-time event handling interface."
- type: feature
text: "`user_id` state for specified channels will be maintained by the SDK. State with subscribe calls has been improved."
- type: feature
text: "Adding `Channel`, `ChannelGroup`, `ChannelMetadata` and `UuidMetadata` entities to be first-class citizens to access APIs related to them. Currently, access is provided only for subscription APIs."
- type: feature
text: "Added ability to configure request retry policies to exclude specific endpoints from retry."
- date: 2023-11-03
version: 0.4.1
changes:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pubnub"
version = "0.4.1"
version = "0.5.0"
edition = "2021"
license-file = "LICENSE"
authors = ["PubNub <[email protected]>"]
Expand Down
94 changes: 47 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Add `pubnub` to your Rust project in the `Cargo.toml` file:
```toml
# default features
[dependencies]
pubnub = "0.4.1"
pubnub = "0.5.0"

# all features
[dependencies]
pubnub = { version = "0.4.1", features = ["full"] }
pubnub = { version = "0.5.0", features = ["full"] }
```

### Example
Expand All @@ -57,53 +57,53 @@ use serde_json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let publish_key = "my_publish_key";
use pubnub::subscribe::{EventEmitter, SubscriptionParams};
let publish_key = "my_publish_key";
let subscribe_key = "my_subscribe_key";
let client = PubNubClientBuilder::with_reqwest_transport()
.with_keyset(Keyset {
subscribe_key,
publish_key: Some(publish_key),
secret_key: None,
})
.with_user_id("user_id")
.build()?;
println!("PubNub instance created");

let subscription = client
.subscribe()
.channels(["my_channel".into()].to_vec())
.execute()?;

println!("Subscribed to channel");

// Launch a new task to print out each received message
tokio::spawn(subscription.stream().for_each(|event| async move {
match event {
SubscribeStreamEvent::Update(update) => {
match update {
Update::Message(message) | Update::Signal(message) => {
// Silently log if UTF-8 conversion fails
if let Ok(utf8_message) = String::from_utf8(message.data.clone()) {
if let Ok(cleaned) = serde_json::from_str::<String>(&utf8_message) {
println!("message: {}", cleaned);
}
}
}
Update::Presence(presence) => {
println!("presence: {:?}", presence)
}
Update::Object(object) => {
println!("object: {:?}", object)
}
Update::MessageAction(action) => {
println!("message action: {:?}", action)
}
Update::File(file) => {
println!("file: {:?}", file)
.with_keyset(Keyset {
subscribe_key,
publish_key: Some(publish_key),
secret_key: None,
})
.with_user_id("user_id")
.build()?;
println!("PubNub instance created");

let subscription = client.subscription(SubscriptionParams {
channels: Some(&["my_channel"]),
channel_groups: None,
options: None
});

println!("Subscribed to channel");

// Launch a new task to print out each received message
tokio::spawn(client.status_stream().for_each(|status| async move {
println!("\nStatus: {:?}", status)
}));
tokio::spawn(subscription.stream().for_each(|event| async move {
match event {
Update::Message(message) | Update::Signal(message) => {
// Silently log if UTF-8 conversion fails
if let Ok(utf8_message) = String::from_utf8(message.data.clone()) {
if let Ok(cleaned) = serde_json::from_str::<String>(&utf8_message) {
println!("message: {}", cleaned);
}
}
}
SubscribeStreamEvent::Status(status) => println!("\nstatus: {:?}", status),
Update::Presence(presence) => {
println!("presence: {:?}", presence)
}
Update::AppContext(object) => {
println!("object: {:?}", object)
}
Update::MessageAction(action) => {
println!("message action: {:?}", action)
}
Update::File(file) => {
println!("file: {:?}", file)
}
}
}));

Expand Down Expand Up @@ -132,11 +132,11 @@ disable them in the `Cargo.toml` file, like so:
```toml
# only blocking and access + default features
[dependencies]
pubnub = { version = "0.4.1", features = ["blocking", "access"] }
pubnub = { version = "0.5.0", features = ["blocking", "access"] }

# only parse_token + default features
[dependencies]
pubnub = { version = "0.4.1", features = ["parse_token"] }
pubnub = { version = "0.5.0", features = ["parse_token"] }
```

### Available features
Expand Down Expand Up @@ -175,7 +175,7 @@ you need, for example:

```toml
[dependencies]
pubnub = { version = "0.4.1", default-features = false, features = ["serde", "publish",
pubnub = { version = "0.5.0", default-features = false, features = ["serde", "publish",
"blocking"] }
```

Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
//! ```toml
//! # default features
//! [dependencies]
//! pubnub = "0.4.1"
//! pubnub = "0.5.0"
//!
//! # all features
//! [dependencies]
//! pubnub = { version = "0.4.1", features = ["full"] }
//! pubnub = { version = "0.5.0", features = ["full"] }
//! ```
//!
//! ### Example
Expand Down Expand Up @@ -135,11 +135,11 @@
//! ```toml
//! # only blocking and access + default features
//! [dependencies]
//! pubnub = { version = "0.4.1", features = ["blocking", "access"] }
//! pubnub = { version = "0.5.0", features = ["blocking", "access"] }
//!
//! # only parse_token + default features
//! [dependencies]
//! pubnub = { version = "0.4.1", features = ["parse_token"] }
//! pubnub = { version = "0.5.0", features = ["parse_token"] }
//! ```
//!
//! ### Available features
Expand Down Expand Up @@ -178,7 +178,7 @@
//!
//! ```toml
//! [dependencies]
//! pubnub = { version = "0.4.1", default-features = false, features = ["serde", "publish",
//! pubnub = { version = "0.5.0", default-features = false, features = ["serde", "publish",
//! "blocking"] }
//! ```
//!
Expand Down

0 comments on commit d9e91ac

Please sign in to comment.