ifttt_webhook_rust

Crates.ioifttt_webhook_rust
lib.rsifttt_webhook_rust
version0.2.2
sourcesrc
created_at2021-03-11 06:48:07.141701
updated_at2021-03-11 08:37:51.986536
descriptiona convenient tool for trigger ifttt's webhooks
homepage
repositoryhttps://github.com/sinyo-matu/ifttt_webhook_rust
max_upload_size
id367129
size14,742
Yang Qin (sinyo-matu)

documentation

README

ifttt_webhook_rust

crate.io

a simple lib binding to the ifttt's webhook api. there is a async interface can be activate in feature non-blocking. and a time delay trigger function for delay the trigger in feature delay.

the blocking interface use ureq, and the non-blocking interface use reqwest internally.

about ifttt webhook usage: For example,You can call a url (supplied by ifttt) then receive a notification (could include data* you supplied) on you phone.

*sometimes you can set some json data (up to three fields in it) on the request, which is depends on the service webhook connected with.

Installation

cargo add ifttt_webhook_rust

Usage

blocking api

code

    extern crate ifttt_webhook_rust
    extern crate dotenv
    use ifttt_webhook_rust::*

    dotenv::dotenv().unwrap();
    let event_name = dotenv::var("EVENT").unwrap();
    let api_key = dotenv::var("KEY").unwrap();
    let client = BlockingIftttWebHookClient::new(&api_key);
    let res = client.trigger(&event_name, None);
    assert!(res.is_ok())

non-blocking api

Cargo.toml

ifttt_webhook_rust={version=*,default-features= false,features=["non-blocking"]}

code

    extern crate ifttt_webhook_rust
    extern crate dotenv
    use ifttt_webhook_rust::*

    dotenv::dotenv().unwrap();
    let event_name = dotenv::var("EVENT").unwrap();
    let api_key = dotenv::var("KEY").unwrap();
    let data = WebHookData::new(Some("test_blocking1"), Some("test2"), None);
    let client = NonBlockingIftttWebHookClient::new(&api_key);
    let res = client.trigger(&event_name, data).await;
    assert!(res.is_ok())

non-blocking api with time delay

Cargo.toml

ifttt_webhook_rust={version=*,default-features= false,features=["delay"]}

code

    extern crate ifttt_webhook_rust
    extern crate dotenv
    use ifttt_webhook_rust::*
    
    dotenv::dotenv().unwrap();
    let event_name = dotenv::var("EVENT").unwrap();
    let api_key = dotenv::var("KEY").unwrap();
    let client = NonBlockingIftttWebHookClient::new(&api_key);    
    let res_handler: DelayResultHandler =
        client.trigger_with_delay(&event_name, None, std::time::Duration::from_secs(5));
    ///do something else
    let res = res_handler.await;
    assert!(res.is_ok())
Commit count: 20

cargo fmt