Building a PubSubHubBub Endpoint for Kynetx


The Live Web already exists and is exemplified by emerging technologies and concepts such as PubSubHubBub and webhooks. PubSubHubBub (PuSH) is a method for augmenting RSS and Atom feeds that turns the formerly request-response-style interaction of RSS into one that makes calls to subscribers when relevant updates are posted. Webhooks are a simple way to use HTTP to create event notifications .

Both of these technologies are raising events, although not in a form directly usable by Kynetx. One approach to using them with KRL would be to write a custom endpoint. Often for special projects, however, it's just as effective to put together pieces from existing Web services to do the transformation from one kind of event to another. In this post we'll explore an example that uses both PuSH and Webhooks with KRL that doesn't require writing a custom endpoint.

Prowl is an iPhone application that raises Growl-style notifications on your phone. Those notifications can come from your computer, from the Web, or through the Prowl API. In this example, we'll send notifications to a phone when a Blogger Web site is updated.

Blogger RSS feeds are PuSH enabled, so when the blog is updated, services that have subscribe to the feed are notified immediately. Notify.io is a service that can listen to PuSH-enabled feeds (among other things) and publish the pushed items to a webhook (and other things). Kynetx provides a Web service that translates events raised via a webhook into a Kynetx-style event that KRL understands.

A PubSubHubBub endpoint built using Notify.io

Using these two services together, we can create a translating endpoint that raises events whenever a blog is updated. The wiring diagram is shown in the preceding diagram. We'll configure the webhook service to raise an event with type newpost.

The Prowl API can be easily encapsulated in a KRL module as shown below:

ruleset a16x83 {
  meta {
    name "Prowl Module"
    configure using apikeys = {} and
                    application = "Kynetx"
    provides send
  }

  global {
   send = defaction(title, description) {
     configure with priority = 0
     http:post("https://api.prowlapp.com/publicapi/add")
       with params = {
        "apikey": apikeys.pick("$.apikey"),
        "providerkey": apikeys.pick("$.providerkey"),
        "application":application,
        "priority": priority,      
        "event": title,
        "description" : description   
      }
    }
  }}

This provides rulesets with an action named send that will post the notification to the user's cell phone. Writing a rule to listen for the event from the endpoint and call the prowl:send action is simple. The only thing we need to do is provide the API and provider keys that we get from the Prowl Web site.

First we declare keys and use the module in the meta block of the ruleset:

key prowl {"apikey":"KEY GOES HERE",
           "providerkey": "KEY GOES HERE"}
use module a16x84 alias prowl
   with apikeys = key:prowl()
The rule is simple:
rule first_rule is active {
    select when webhook newpost
    prowl:send(event:param("title"), event:param("text"));
}

When an event is raised with a type that matches newpost, send the title and text parameters of the event to Prowl. The result is a notification on the iPhone like the one shown in figure above.

Of course, it would be just as easy to use the Twilio module to send an SMS. You could do both, based on priority, keyword, or anything else. Providing endpoints for real-time events online gives us the ability to use KRL to glue these event together and create interesting, useful little applications.