Skip to content

Instantly share code, notes, and snippets.

@jimmyislive
Created December 16, 2013 17:50
Show Gist options
  • Save jimmyislive/7991228 to your computer and use it in GitHub Desktop.
Save jimmyislive/7991228 to your computer and use it in GitHub Desktop.
Sample function that can be used to POST to the hub whenever your feed changes. The cfg object is something that has all the appropriate params depending on which environment you are on e.g. dev | staging | production etc
function pubsubhubub_post(post_url, callback) {
var payload = { hostname: cfg.hub,
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}
var pubsubhubub_request = https.request(payload, function(pubsubhubub_response) {
//dunno y, but this no-op is needed here !!!
pubsubhubub_response.on('data', function(chunk) {
console.log('BODY: ' + chunk);
});
//redundant?
pubsubhubub_response.on('close', function() {
console.log('received close event after sending pubsub request with status code ' + pubsubhubub_response.statusCode)
callback();
});
//this needs to be here for sure...
pubsubhubub_response.on('end', function() {
console.log('received end event after sending pubsub request with status code ' + pubsubhubub_response.statusCode)
callback();
});
});
pubsubhubub_request.on('error', function(e) {
console.log('error during pubsubhubub_request...')
console.error(e);
});
pubsubhubub_request.write('hub.mode=publish&hub.url=' + cfg.transportRequire + '://' + cfg.apiHost + '/feeds/rss2');
pubsubhubub_request.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment