Skip to content

Commit

Permalink
proper examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavrax committed Aug 29, 2023
1 parent f16c320 commit bc662ef
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,27 @@ required-features = ["default", "subscribe"]
name = "subscribe_raw_blocking"
required-features = ["default", "subscribe"]

[[example]]
name = "here_now"
required-features = ["default", "presence"]

[[example]]
name = "here_now_blocking"
required-features = ["default", "blocking", "presence"]

[[example]]
name = "where_now"
required-features = ["default", "presence"]

[[example]]
name = "where_now_blocking"
required-features = ["default", "blocking", "presence"]

[[example]]
name = "presence_state"
required-features = ["default", "presence"]

[[example]]
name = "presence_state_blocking"
required-features = ["default", "blocking", "presence"]

4 changes: 3 additions & 1 deletion examples/here_now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
.execute()
.await?;

println!("All channels data: {:?}", channels_now);
println!("All channels data: {:?}\n", channels_now);

channels_now.iter().for_each(|channel| {
println!("Channel: {}", channel.name);
Expand All @@ -36,6 +36,8 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
.occupants
.iter()
.for_each(|occupant| println!("Occupant: {:?}", occupant));

println!();
});

Ok(())
Expand Down
42 changes: 42 additions & 0 deletions examples/here_now_blocking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use pubnub::{Keyset, PubNubClientBuilder};
use std::env;

fn main() -> Result<(), Box<dyn snafu::Error>> {
let publish_key = env::var("SDK_PUB_KEY")?;
let subscribe_key = env::var("SDK_SUB_KEY")?;

let client = PubNubClientBuilder::with_reqwest_blocking_transport()
.with_keyset(Keyset {
subscribe_key,
publish_key: Some(publish_key),
secret_key: None,
})
.with_user_id("user_id")
.build()?;

println!("running!");

let channels_now = client
.here_now()
.channels(["my_channel".into(), "other_channel".into()].to_vec())
.include_state(true)
.include_user_id(true)
.execute_blocking()?;

println!("All channels data: {:?}\n", channels_now);

channels_now.iter().for_each(|channel| {
println!("Channel: {}", channel.name);
println!("Occupancy: {}", channel.occupancy);
println!("Occupants: {:?}", channel.occupants);

channel
.occupants
.iter()
.for_each(|occupant| println!("Occupant: {:?}", occupant));

println!();
});

Ok(())
}
40 changes: 40 additions & 0 deletions examples/presence_state_blocking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use pubnub::{Keyset, PubNubClientBuilder};
use std::env;

fn main() -> Result<(), Box<dyn snafu::Error>> {
let publish_key = env::var("SDK_PUB_KEY")?;
let subscribe_key = env::var("SDK_SUB_KEY")?;

let _client = PubNubClientBuilder::with_reqwest_blocking_transport()
.with_keyset(Keyset {
subscribe_key,
publish_key: Some(publish_key),
secret_key: None,
})
.with_user_id("user_id")
.build()?;

println!("running!");

// client
// .set_presence_state()
// .channels(["my_channel".into(), "other_channel".into()].to_vec())
// .state("{\"What you're doing\": \"Me? Nothing... Just hanging around\"}")
// .user_id("user_id")
// .execute_blocking()?;
//
// let states = client
// .get_presence_state()
// .channels(["my_channel".into(), "other_channel".into()].to_vec())
// .user_id("user_id")
// .execute_blocking()?;
//
// println!("All channels state: {:?}", states);
//
// states.iter().for_each(|channel| {
// println!("Channel: {}", channel.channel);
// println!("State: {:?}", channel.state);
// });
//
Ok(())
}
27 changes: 27 additions & 0 deletions examples/where_now_blocking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use pubnub::{Keyset, PubNubClientBuilder};
use std::env;

fn main() -> Result<(), Box<dyn snafu::Error>> {
let publish_key = env::var("SDK_PUB_KEY")?;
let subscribe_key = env::var("SDK_SUB_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!("running!");

// let where_user = client
// .where_now()
// .user_id("user_id")
// .execute_blocking()?;
//
// println!("All channels data: {:?}", where_user);

Ok(())
}

0 comments on commit bc662ef

Please sign in to comment.