#webhook #hook #com #pijul #nest #hyper #handle

pijul-hooks

Tools to handle webhooks from nest.pijul.com

3 releases

Uses old Rust 2015

0.1.2 Mar 30, 2019
0.1.1 Mar 30, 2019
0.1.0 Mar 14, 2019

#4 in #pijul

MIT/Apache

8KB
117 lines

Hooks for the Pijul Nest

This crate can be used to write web servers that can receive requests from nest.pijul.com. It takes care of all the necessary authentication and parsing.

Here is an example client and server:

extern crate futures;
use futures::Future;
use pijul_hooks::*;
tokio::run(futures::lazy(move || {
    let secret = "ce sera notre petit secret";
    let port = 9812;
    let addr = ([127, 0, 0, 1], port).into();
    let make_service = move || {
        hyper::service::service_fn(move |req| {
            parse_request(req, &secret).map(|hook| {
                hook.unwrap();
                let ok = hyper::Body::from("Ok");
                hyper::Response::new(ok)
            })
        })
    };
    let (tx, rx) = futures::sync::oneshot::channel::<()>();
    let server = hyper::Server::bind(&addr).serve(make_service);
    hyper::rt::spawn(server.with_graceful_shutdown(rx).map_err(|e| {
        eprintln!("server error: {}", e);
    }));
    (Hook {
        url: format!("http://!127.0.0.1:{}/", port).parse().unwrap(),
        secret: secret.to_string(),
    })
    .run(&HookContent::Discussion {
        repository_owner: "owner".to_string(),
        repository_name: "name".to_string(),
        discussion_number: 1234,
        title: "title".to_string(),
        author: "author".to_string(),
    })
    .map_err(|e| eprintln!("error: {:?}", e))
    .map(|_| tx.send(()).unwrap())
}))

Dependencies

~21MB
~463K SLoC