zh / watercoolr

pubsub via webhooks
watercoolr.nuklei.com
21 stars 1 forks source link

Watercoolr

pubsub via webhooks, or "twitter" for your applications

Input

Native watercoolr publishers

Send POST request with JSON-encoded 'payload' parameter to

http://watercoolr.example.com/publish

'payload' must provide at least channel name payload[:channel] and a message payload[:message]. The message will be send to all subscribers of that channel.

You can use watercoolr to receive input from different web services, supporting webhooks.

ping.fm

http://ping.fm/ can provide IM, E-mail, web etc. input for your webhooks. The information is coming via POST parameters - see also http://groups.google.com/group/pingfm-developers/web/working-with-a-custom-url

Go to http://ping.fm/custom/ and in the "Custom URL:" box enter:

http://watercoolr.example.com/pingfm

You need a channel with 'pingfm' type. During the system startup one such channel is added by default. Just find it's name or create a new one - the latest created will be used. You can add then subscribers to your 'pingfm' channel.

GitHub

http://github.com/ can push notification for repository commits to your webhooks. The all information is inside JSON-encoded 'payload' parameter. See also: http://github.com/guides/post-receive-hooks

From your project pages go to "Admin"|"Service Hooks" and in the "Post-Receive URLs" box enter:

http://watercoolr.example.com/github

You need a channel with 'github' type. During the system startup one such channel is added by default. Just find it's name or create a new one - the latest created will be used. You can add then subscribers to your 'github' channel.

PubSubHubbub

watercoolr can be PubSubHubbub CALLBACK ONLY for now. To get Atom notifications from some hub:

1a. Create 'pubsubhubbub' type channel with some topic and a secret:

resp = RestClient.post 'http://admin:admin@localhost:4567/channels', :data => { :type => 'pubsubhubbub', :topic => 'http://example.com/feed', :secret => 'secret' }.to_json id = JSON.parse(resp)["id"]

Or:

1b. If you will use Superfeedr for hub, register a channel with ID={secret superfeedr token}:

TOKEN = 'YourSuperFeedrToken'.freeze resp = RestClient.post 'http://admin:admin@localhost:4567/channels', :data => { :type => 'superfeedr', :id => TOKEN }.to_json id = JSON.parse(resp)["id"]

  1. Add subscribers like usual (provide channel secret if needed)

    3a. GAE PubSubHubBub

Go to http://pubsubhubbub.appspot.com/subscribe and

In "Settings"|"Notifications" choose Type: "PubSubhubbub" and in the "Webhook URL" box enter:

http://watercoolr.example.com/hub/callback/{YourSuperFeedrToken}

Output

"Normal" subscribers (webhooks)

watercoolr can push notifications to normal webhooks. Information is divided on two parts (similar to github):

To prevent security information leaks, all subscribers are created with type='debug' by default. For such subscribers, 'data' parameter is not send during the POSTs. This kind of subscribers are suitable for example for debugging (PostBin etc.). To have the 'data' parameter send to the hook, set the subscriber type to any string, different from 'debug':

Small webhooks library

To be easier to start with watercoolr, it provides a small library of ready to use webhooks, accessable on the same system, where watercoolr is deployed. If the site URL is http://localhost:4567/ , the URLs for webhooks will be:

http://localhost:4567/hook/:NAME/:SECRET/

where :NAME is one of ff (FriendFeed), twitter, xmpp or prowl and :SECRET is a special user, created during the initial deployment:

DB[:users] << { :name => 'all', :password => '...', :service => 'hooks' }

You can create also secret token per webhook, with :name => 'ff', 'twitter' or 'xmpp'

DB[:users] << { :name => 'all', :password => 'secret', :service => 'hooks' } DB[:users] << { :name => 'xmpp', :password => 'token', :service => 'hooks' }

xmpp webhook will be on URL: http://localhost:4567/hook/xmpp/token/ and all other webhooks - on URL: http://localhost:4567/hook/:name/secret/

Webhooks can be used like watercoolr subscribers or called directly with POST request and 'data' amd 'payload' parameters from other services (github etc.)

Pushing to iPhone

'prowl' webhook can be used to push notifications to iPhone.

resp = RestClient.post 'http://localhost:4567/subscribe', :data => { :channel => id, :type => 'local', :url => 'http://localhost:4567/hook/prowl/secret/', :apikey => 'PROWL_APIKEY', :priority => 2}.to_json puts resp

resp = RestClient.post 'http://localhost:4567/publish', :data => { :channel => id, :title => 'Alert!' :message => 'Call me!' }.to_json puts resp

For Prowl API details see: http://forums.cocoaforge.com/viewtopic.php?f=45&t=20339

messagepub subscribers

http://messagepub.com/ can send message to twitter, XMPP (jabber), SMS etc. There also have a ruby wrapper around their API

gem install messagepub --no-rdoc --no-ri

In order to use their services, subscribers with 'messagepub' type and additional data (channels, propagation etc.) need to be used. See also: http://messagepub.com/documentation/api .