SuperFeedr Tutorial

SuperFeedr Tutorial

This is a quick guide to help you get this app up and running with your SuperFeedr account.

Installation

If you have not yet installed the djpubsubhubbub app, please follow the Installation instructions and come back to this tutorial.

Settings

You're going to need to add the following settings to your projects settings.py file.

#SuperFeedr
SUPERFEEDR_HUB = 'https://superfeedr.com/hubbub'
SUPERFEEDR_USER = 'your-user-name'
SUPERFEEDR_PASS = 'your-password'

# djpubsubhubbub
PUBSUBHUBBUB_CONFIG = 'myproject.config.SubHubConfig'


The above snippet is assuming your project is named 'myproject'. The first 3 variables should be obvious enough. The 4th is going to be a configuration class that the djpubsubhubbub app is going to use to talk with SuperFeedr. Continue to the next section...

Configuration

The setting PUBSUBHUBBUB_CONFIG is referencing a Python path of myproject.config.SubHubConfig. We need to create a file named config.py in your myproject directory. It should contain the following:

import base64
from django.conf import settings

class SubHubConfig(object):
    def get_extra_hub_headers(self, feed_url, hub_url):
        headers = {}
        if hub_url == settings.SUPERFEEDR_HUB:
            headers['Authorization'] = \
                'Basic %s' % base64.b64encode('%s:%s' % (
                    settings.SUPERFEEDR_USER,
                    settings.SUPERFEEDR_PASS,
                ))
        return headers

    def get_default_callback_host(self, feed_url, hub_url):
        return 'www.your-project-domain.com'


This will tell the djpubsubhubbub app that whenever it's talking to the SuperFeedr Hub URL, to add the authorization headers to the request, which is required by SuperFeedr.

Note: The second method above (get_default_callback_host) is optional and only necessary if you don't want to use the Django sites framework. By default, if this method is not provided, djpubsubhubbub will simply call Site.objects.get_current() to get the current FQDN to use in the callback URL. For more info, see Django Sites Documentation.

Signals

The djpubsubhubbub app uses Django signals to let you know when new content has been posted. The signal name is updated. How to use signals is beyond the scope of this tutorial, but you can read the documentation here: Django Signals.

Here is a generic example:

from djpubsubhubbub.signals import updated

def update_handler(sender, update, **kwargs):
    ''' Process new content being provided from SuperFeedr
    '''
    for entry in update.entries:
        # do something with entry here

updated.connect(update_handler, dispatch_uid='superfeedr')


Subscribing

You should be all setup now. You can subscribe to a new feed like so:

>>> from django.conf import settings
>>> from djpubsubhubbub.models import Subscription
>>> sub = Subscription.objects.subscribe(
...     topic='http://www.someurl.com/rss/feed/',
...     hub=settings.SUPERFEEDR_HUB,
... )
>>>


All Done!

That's pretty much it. You should now have an active subscription using SuperFeedr as a hub.

If you notice any issues with this page, please use the issue tracker above to report it and I will correct what needs to be corrected. Enjoy!

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.