pijul-hooks 0.1.1

Tools to handle webhooks from nest.pijul.com

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())
}))