Expand description
§Pusher-HTTP-Rust
The Rust library for interacting with the Pusher HTTP API.
This package lets you trigger events to your client and query the state of your Pusher channels. When used with a server, you can validate Pusher webhooks and authenticate private- or presence-channels.
In order to use this library, you need to have a free account on http://pusher.com. After registering, you will need the application credentials for your app.
§Getting Started
Firstly, add pusher
to your Cargo.toml
.
To trigger an event:
extern crate pusher; // imports the `pusher` module
use pusher::PusherBuilder; // brings the PusherBuilder struct into scope
// the functions are async, so we need a reactor running (e.g. tokio)
// this example uses "current_thread" for simplicity
#[tokio::main(flavor = "current_thread")]
async fn main() {
// initializes a Pusher object with your app credentials
let pusher = PusherBuilder::new("APP_ID", "KEY", "SECRET").finalize();
// triggers an event called "my_event" on a channel called "test_channel", with the payload "hello world!"
let result = pusher.trigger("test_channel", "my_event", "hello world!").await;
match result {
Ok(events) => println!("Successfully published: {:?}", events),
Err(err) => println!("Failed to publish: {}", err),
}
}
Structs§
- Channel
- This represents the data received upon querying the state of a Pusher channel.
- Channel
List - A list of channels returned by the API.
- Channel
User - A particular user who occupies a presence channel.
- Channel
User List - The list of users subscribed to a presence channel, as returned by the Pusher API.
- Member
- When authenticating presence-channels, this represents a particular member of the channel. This object becomes associated with that user’s subscription.
- Pusher
- A client to interact with Pusher’s HTTP API to trigger, query application state, authenticate private- or presence-channels, and validate webhooks.
- Pusher
Builder - An ephemeral object upon which to pass configuration options to when initializing a Pusher instance.
- Triggered
Events - Any event_ids returned by the HTTP API, if connected to certain clusters.
- Webhook
- This is returned upon validating that a webhook is indeed from Pusher, carrying all the data received by that POST request.
Type Aliases§
- Query
Parameters - When querying the state of Pusher channels, you can pass this in to specify options.