Skip to content

Commit d917aec

Browse files
Xavraxparfeon
andauthored
Release v0.3.0 (#173)
Co-authored-by: Serhii Mamontov <[email protected]>
1 parent 1e15d07 commit d917aec

File tree

4 files changed

+119
-31
lines changed

4 files changed

+119
-31
lines changed

.pubnub.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
name: rust
2-
version: 0.2.1
2+
version: 0.3.0
33
schema: 1
44
scm: github.com/pubnub/rust
55
files: []
66
changelog:
7+
- date: 2023-08-30
8+
version: 0.3.0
9+
changes:
10+
- type: feature
11+
text: "PubNub subscribe API implemented."
12+
- type: feature
13+
text: "PubNub presence API implemented."
14+
- type: feature
15+
text: "Event engine as a new method of handling connections for `subscribe` and `presence` methods implemented."
716
- date: 2023-06-07
817
version: 0.2.1
918
changes:
@@ -87,6 +96,28 @@ features:
8796
- PUBLISH-ASYNC
8897
- PUBLISH-REPLICATION-FLAG
8998
- PUBLISH-MESSAGE-TTL
99+
subscribe:
100+
- SUBSCRIBE-CHANNELS
101+
- SUBSCRIBE-CHANNEL-GROUPS
102+
- SUBSCRIBE-PRESENCE-CHANNELS
103+
- SUBSCRIBE-PRESENCE-CHANNELS-GROUPS
104+
- SUBSCRIBE-WITH-TIMETOKEN
105+
- SUBSCRIBE-FILTER-EXPRESSION
106+
- SUBSCRIBE-PUBLISHER-UUID
107+
- SUBSCRIBE-PUBSUB-V2
108+
- SUBSCRIBE-SIGNAL-LISTENER
109+
- SUBSCRIBE-MEMBERSHIP-LISTENER
110+
- SUBSCRIBE-OBJECTS-CHANNEL-LISTENER
111+
- SUBSCRIBE-OBJECTS-UUID-LISTENER
112+
- SUBSCRIBE-MESSAGE-ACTIONS-LISTENER
113+
- SUBSCRIBE-FILE-LISTENER
114+
presence:
115+
- PRESENCE-HERE-NOW
116+
- PRESENCE-WHERE-NOW
117+
- PRESENCE-SET-STATE
118+
- PRESENCE-GET-STATE
119+
- PRESENCE-HEARTBEAT
120+
- PRESENCE-DELTAS
90121
supported-platforms:
91122
- version: PubNub Rust SDK
92123
platforms:

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pubnub"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
edition = "2021"
55
license = "MIT"
66
authors = ["PubNub <[email protected]>"]
@@ -17,7 +17,7 @@ build = "build.rs"
1717
full = ["publish", "subscribe", "presence", "access", "serde", "reqwest", "aescbc", "parse_token", "blocking", "std", "tokio"]
1818

1919
# Enables all default features
20-
default = ["publish", "subscribe", "presence", "serde", "reqwest", "aescbc", "std", "blocking", "tokio"]
20+
default = ["publish", "subscribe", "serde", "reqwest", "aescbc", "std", "blocking", "tokio"]
2121

2222
# [PubNub features]
2323

@@ -64,9 +64,9 @@ extra_platforms = ["spin/portable_atomic", "dep:portable-atomic"]
6464

6565
# [Internal features] (not intended for use outside of the library)
6666
contract_test = ["parse_token", "publish", "access"]
67-
full_no_std = ["serde", "reqwest", "aescbc", "parse_token", "blocking", "publish", "access", "subscribe", "tokio"]
68-
full_no_std_platform_independent = ["serde", "aescbc", "parse_token", "blocking", "publish", "access", "subscribe"]
69-
pubnub_only = ["aescbc", "parse_token", "blocking", "publish", "access", "subscribe"]
67+
full_no_std = ["serde", "reqwest", "aescbc", "parse_token", "blocking", "publish", "access", "subscribe", "tokio", "presence"]
68+
full_no_std_platform_independent = ["serde", "aescbc", "parse_token", "blocking", "publish", "access", "subscribe", "presence"]
69+
pubnub_only = ["aescbc", "parse_token", "blocking", "publish", "access", "subscribe", "presence"]
7070
mock_getrandom = ["getrandom/custom"]
7171
# TODO: temporary treated as internal until we officially release it
7272
subscribe = ["dep:futures"]

README.md

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ Add `pubnub` to your Rust project in the `Cargo.toml` file:
3535
```toml
3636
# default features
3737
[dependencies]
38-
pubnub = "0.2.1"
38+
pubnub = "0.3.0"
3939

4040
# all features
4141
[dependencies]
42-
pubnub = { version = "0.2.1", features = ["full"] }
42+
pubnub = { version = "0.3.0", features = ["full"] }
4343
```
4444

4545
### Example
@@ -48,28 +48,75 @@ Try the following sample code to get up and running quickly!
4848

4949
```rust
5050
use pubnub::{Keyset, PubNubClientBuilder};
51+
use pubnub::dx::subscribe::{SubscribeStreamEvent, Update};
52+
use futures::StreamExt;
53+
use tokio::time::sleep;
54+
use std::time::Duration;
55+
use serde_json;
5156

5257
#[tokio::main]
5358
async fn main() -> Result<(), Box<dyn std::error::Error>> {
5459
let publish_key = "my_publish_key";
5560
let subscribe_key = "my_subscribe_key";
56-
5761
let client = PubNubClientBuilder::with_reqwest_transport()
58-
.with_keyset(Keyset {
59-
subscribe_key,
60-
publish_key: Some(publish_key),
61-
secret_key: None,
62-
})
63-
.with_user_id("user_id")
64-
.build()?;
65-
62+
.with_keyset(Keyset {
63+
subscribe_key,
64+
publish_key: Some(publish_key),
65+
secret_key: None,
66+
})
67+
.with_user_id("user_id")
68+
.build()?;
69+
println!("PubNub instance created");
70+
71+
let subscription = client
72+
.subscribe()
73+
.channels(["my_channel".into()].to_vec())
74+
.execute()?;
75+
76+
println!("Subscribed to channel");
77+
78+
// Launch a new task to print out each received message
79+
tokio::spawn(subscription.stream().for_each(|event| async move {
80+
match event {
81+
SubscribeStreamEvent::Update(update) => {
82+
match update {
83+
Update::Message(message) | Update::Signal(message) => {
84+
// Silently log if UTF-8 conversion fails
85+
if let Ok(utf8_message) = String::from_utf8(message.data.clone()) {
86+
if let Ok(cleaned) = serde_json::from_str::<String>(&utf8_message) {
87+
println!("message: {}", cleaned);
88+
}
89+
}
90+
}
91+
Update::Presence(presence) => {
92+
println!("presence: {:?}", presence)
93+
}
94+
Update::Object(object) => {
95+
println!("object: {:?}", object)
96+
}
97+
Update::MessageAction(action) => {
98+
println!("message action: {:?}", action)
99+
}
100+
Update::File(file) => {
101+
println!("file: {:?}", file)
102+
}
103+
}
104+
}
105+
SubscribeStreamEvent::Status(status) => println!("\nstatus: {:?}", status),
106+
}
107+
}));
108+
109+
sleep(Duration::from_secs(1)).await;
110+
// Send a message to the channel
66111
client
67112
.publish_message("hello world!")
68113
.channel("my_channel")
69114
.r#type("text-message")
70115
.execute()
71116
.await?;
72117

118+
sleep(Duration::from_secs(10)).await;
119+
73120
Ok(())
74121
}
75122
```
@@ -83,22 +130,25 @@ The `pubnub` crate is split into multiple features. You can enable or disable th
83130
```toml
84131
# only blocking and access + default features
85132
[dependencies]
86-
pubnub = { version = "0.2.1", features = ["blocking", "access"] }
133+
pubnub = { version = "0.3.0", features = ["blocking", "access"] }
87134

88135
# only parse_token + default features
89136
[dependencies]
90-
pubnub = { version = "0.2.1", features = ["parse_token"] }
137+
pubnub = { version = "0.3.0", features = ["parse_token"] }
91138
```
92139

93140
### Available features
94141

95142
| Feature name | Description | Available PubNub APIs |
96143
| :------------ | :---------- | :------------- |
97-
| `full` | Enables all non-conflicting features | Configuration, Publish, Access Manager, Parse Token |
98-
| `default` | Enables default features: `publish`, `serde`, `reqwest`, `aescbc`, `std` | Configuration, Publish |
144+
| `full` | Enables all non-conflicting features | Configuration, Publish, Subscribe, Access Manager, Parse Token, Presence |
145+
| `default` | Enables default features: `publish`, `subscribe`, `serde`, `reqwest`, `aescbc`, `std` | Configuration, Publish, Subscribe |
99146
| `publish` | Enables Publish API | Configuration, Publish |
100147
| `access` | Enables Access Manager API | Configuration, Access Manager |
101148
| `parse_token` | Enables parsing Access Manager tokens | Configuration, Parse Token |
149+
| `subscribe` | Enables Subscribe API | Configuration, Subscribe |
150+
| `presence` | Enables Presence API | Configuration, Presence |
151+
| `tokio` | Enables the [tokio](https://tokio.rs/) asynchronous runtime for Subscribe and Presence APIs | n/a |
102152
| `serde` | Uses [serde](https://github.com/serde-rs/serde) for serialization | n/a |
103153
| `reqwest` | Uses [reqwest](https://github.com/seanmonstar/reqwest) as a transport layer | n/a |
104154
| `blocking` | Enables blocking executions of APIs | n/a |
@@ -121,7 +171,7 @@ features and enable the ones you need, for example:
121171

122172
```toml
123173
[dependencies]
124-
pubnub = { version = "0.2.1", default-features = false, features = ["serde", "publish",
174+
pubnub = { version = "0.3.0", default-features = false, features = ["serde", "publish",
125175
"blocking"] }
126176
```
127177

@@ -135,8 +185,10 @@ some parts of the `alloc::sync` module, which is also not supported in certain `
135185

136186
Some SDK features aren't supported in a `no_std` environment:
137187

138-
* partially `access` module (because of lack timestamp support)
188+
* partially `access` module (because of lack of timestamp support)
139189
* partially `reqwest` transport (because of the reqwest implementation details)
190+
* partially `subscribe` module (because of the spawning tasks and time dependence)
191+
* partially `presence` module (because of the spawning tasks and time dependence)
140192
* `std` feature (because of the `std` library)
141193

142194
We depend on a random number generator to generate data for debugging purposes.

src/lib.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
//! ```toml
3939
//! # default features
4040
//! [dependencies]
41-
//! pubnub = "0.2.1"
41+
//! pubnub = "0.3.0"
4242
//!
4343
//! # all features
4444
//! [dependencies]
45-
//! pubnub = { version = "0.2.1", features = ["full"] }
45+
//! pubnub = { version = "0.3.0", features = ["full"] }
4646
//! ```
4747
//!
4848
//! ### Example
@@ -133,22 +133,25 @@
133133
//! ```toml
134134
//! # only blocking and access + default features
135135
//! [dependencies]
136-
//! pubnub = { version = "0.2.1", features = ["blocking", "access"] }
136+
//! pubnub = { version = "0.3.0", features = ["blocking", "access"] }
137137
//!
138138
//! # only parse_token + default features
139139
//! [dependencies]
140-
//! pubnub = { version = "0.2.1", features = ["parse_token"] }
140+
//! pubnub = { version = "0.3.0", features = ["parse_token"] }
141141
//! ```
142142
//!
143143
//! ### Available features
144144
//!
145145
//! | Feature name | Description | Available PubNub APIs |
146146
//! | :------------ | :---------- | :------------- |
147-
//! | `full` | Enables all non-conflicting features | Configuration, Publish, Access Manager, Parse Token |
148-
//! | `default` | Enables default features: `publish`, `serde`, `reqwest`, `aescbc`, `std` | Configuration, Publish |
147+
//! | `full` | Enables all non-conflicting features | Configuration, Publish, Subscribe, Access Manager, Parse Token, Presence |
148+
//! | `default` | Enables default features: `publish`, `subscribe`, `serde`, `reqwest`, `aescbc`, `std` | Configuration, Publish, Subscribe |
149149
//! | `publish` | Enables Publish API | Configuration, Publish |
150150
//! | `access` | Enables Access Manager API | Configuration, Access Manager |
151151
//! | `parse_token` | Enables parsing Access Manager tokens | Configuration, Parse Token |
152+
//! | `subscribe` | Enables Subscribe API | Configuration, Subscribe |
153+
//! | `presence` | Enables Presence API | Configuration, Presence |
154+
//! | `tokio` | Enables the [tokio](https://tokio.rs/) asynchronous runtime for Subscribe and Presence APIs | n/a |
152155
//! | `serde` | Uses [serde](https://github.com/serde-rs/serde) for serialization | n/a |
153156
//! | `reqwest` | Uses [reqwest](https://github.com/seanmonstar/reqwest) as a transport layer | n/a |
154157
//! | `blocking` | Enables blocking executions of APIs | n/a |
@@ -171,7 +174,7 @@
171174
//!
172175
//! ```toml
173176
//! [dependencies]
174-
//! pubnub = { version = "0.2.1", default-features = false, features = ["serde", "publish",
177+
//! pubnub = { version = "0.3.0", default-features = false, features = ["serde", "publish",
175178
//! "blocking"] }
176179
//! ```
177180
//!
@@ -185,8 +188,10 @@
185188
//!
186189
//! Some SDK features aren't supported in a `no_std` environment:
187190
//!
188-
//! * partially `access` module (because of lack timestamp support)
191+
//! * partially `access` module (because of lack of timestamp support)
189192
//! * partially `reqwest` transport (because of the reqwest implementation details)
193+
//! * partially `subscribe` module (because of the spawning tasks and time dependence)
194+
//! * partially `presence` module (because of the spawning tasks and time dependence)
190195
//! * `std` feature (because of the `std` library)
191196
//!
192197
//! We depend on a random number generator to generate data for debugging purposes.

0 commit comments

Comments
 (0)