#webhook #ifttt #api-bindings #api

ift-webhook

a convenient tool for trigger ifttt's webhooks

4 releases

0.2.8 Mar 13, 2021
0.2.7 Mar 13, 2021
0.2.6 Mar 11, 2021
0.2.5 Mar 11, 2021
0.2.4 Mar 11, 2021

#1646 in Development tools

MIT license

14KB
252 lines

ift-webhook

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) inside the request, which is depends on the service webhook connected with.

Installation

cargo add ift-webhook

Hot to use

blocking api

code

extern crate ift-webhook
extern crate dotenv
use ift_webhook::*

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

non-blocking api

Cargo.toml

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

code

extern crate ift-webhook
extern crate dotenv
use ift_webhook::*

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

non-blocking api with time delay

Cargo.toml

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

code

extern crate ift-webhook
extern crate dotenv
use ift_webhook::*

dotenv::dotenv().unwrap();
let event_name = dotenv::var("EVENT").unwrap();
let api_key = dotenv::var("KEY").unwrap();
let client = AsyncIftWHClient::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())

Dependencies

~0–13MB
~145K SLoC