Skip to content

Commit

Permalink
feat: init repo
Browse files Browse the repository at this point in the history
  • Loading branch information
pxseu committed Sep 2, 2022
1 parent 5490506 commit a7aed6d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @pxseu
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# leap_edge_rs

Utility library for connecting and receiving events from [Leap Edge](https://docs.hop.io/docs/channels/internals/leap). Used for Channels and Pipe.

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
leap_edge_rs = "0.1"
```

or if you want to add features:

```toml
[dependencies.leap_edge_rs]
version = "0.1"
default-features = false
features = ["rustls-tls-webpki-roots", "zlib"]
```

## Usage

### Subscribe to a channel

```rust
use leap_edge_rs::{LeapEdge, LeapOptions, leap::types::Event};

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let leap = LeapEdge::new(LeapOptions {
project: "my-project",
..Default::default()
}).await?;

leap.channel_subscribe("my-channel").await?;

while let Some(event) = leap.listen().await {
println!("{:?}", event);
}
}
```

### Get all events:

```rust
use leap_edge_rs::{LeapEdge, LeapOptions};

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let leap = LeapEdge::new(LeapOptions {
project: "my-project",
..Default::default()
}).await?;

while let Some(event) = leap.listen().await {
println!("{:?}", event);
}
}
```

### Get only messages or direct messages:

```rust
use leap_edge_rs::{LeapEdge, LeapOptions, leap::types::Event};

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let leap = LeapEdge::new(LeapOptions {
project: "my-project",
..Default::default()
}).await?;

while let Some(event) = leap.listen().await {
match event {
Event::Message(message) | Event::DirectMessage(message) => println!("{:?}", message),

_ => {}
}
}
}
```
2 changes: 1 addition & 1 deletion examples/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn main() -> Result<(), std::io::Error> {
.await?;

if let Ok(channel) = std::env::var("CHANNEL") {
manager.channel_subscribe(&channel).await.ok();
manager.channel_subscribe(&channel).await?;
}

while (manager.listen().await).is_some() {}
Expand Down

0 comments on commit a7aed6d

Please sign in to comment.