Skip to content

Commit

Permalink
Superfeedr PSHB Rails Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
empika committed Aug 31, 2009
0 parents commit 48ee8fd
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
superfeedr_pshb.tmproj
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2009 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 changes: 40 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
SupperfeedrPshb
===============

This is a simple PubSubHubbub client that allows you to easily subscribe and
unsubscribe from feeds. It was initially written for Superfeedr.com but should
work with other hubs although this is untested.

It does not handle the challenge/response part of things but I have included a simple
example of this below. It will not handle recieving updates to your feeds either.

This plugin requires everyones favorite party: HTTParty
So please make sure you install that.

Example
=======
Lets create our happy Pshb'er:
pshb = SuperfeedrPshb::SuperfeedrPshb.new("username", "password",
"http://base.url.of.your.site.with.no.trailing.slash",
"http://yourhub.com/defaults/to/superfeedr/but/is/optional")

Now lets subscribe to a feed:
pshb.subscribe("/your/callback/inc/leading/slash", "http://feed.com/to/subscribe/to", "verify_token")

Now lets unsubscribe the feed:
pshb.unsubscribe("/your/callback/inc/leading/slash", "http://feed.com/to/subscribe/to", "verify_token")

Here is an example of a simple controller action to echo back the challenge, you will
also need to handle your feed updates in this action too:

def pshb
if !params["hub.challenge"].nil?
@challenge = params["hub.challenge"]
render :action => "pshb", :status => 200
else
@challenge = "uhoh!"
render :action => "pshb", :status => 404
end
end

Copyright (c) 2009 Eddy Parris http://www.tech-noir.co.uk, released under the MIT license
23 changes: 23 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the supperfeedr_pshb plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the supperfeedr_pshb plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'SupperfeedrPshb'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
2 changes: 2 additions & 0 deletions install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Install hook code here
puts IO.read(File.join(File.dirname(__FILE__), 'README'))
36 changes: 36 additions & 0 deletions lib/superfeedr_pshb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SupperfeedrPshb
require 'httparty'

module SuperfeedrPshb
class SuperfeedrPshb
include HTTParty
attr_accessor :hub, :auth, :callback_root
base_uri nil

def initialize(username, password, callback_root, hub = "http://superfeedr.com/hubbub")
self.class.base_uri hub
self.class.basic_auth username, password
@auth = {:username => username, :password => password}
@callback_root = callback_root
end

def create_and_send_request(type, mode_options)
options = { :body => { 'hub.mode' => type, 'hub.verify' => "sync" } }
options[:body].merge!(mode_options)
puts options.inspect
self.class.post('/', options)
end

def subscribe(callback, topic, token)
options = {'hub.callback' => @callback_root + callback, 'hub.topic' => topic, 'hub.verify_token' => token}
create_and_send_request("subscribe", options)
end

def unsubscribe(callback, topic, token)
options = {'hub.callback' => @callback_root + callback, 'hub.topic' => topic, 'hub.verify_token' => token}
create_and_send_request("unsubscribe", options)
end

end

end
2 changes: 2 additions & 0 deletions rails/init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Include hook code here
require 'superfeedr_pshb'
4 changes: 4 additions & 0 deletions tasks/supperfeedr_pshb_tasks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :supperfeedr_pshb do
# # Task goes here
# end
8 changes: 8 additions & 0 deletions test/supperfeedr_pshb_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class SupperfeedrPshbTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'rubygems'
require 'active_support'
require 'active_support/test_case'
1 change: 1 addition & 0 deletions uninstall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Uninstall hook code here

0 comments on commit 48ee8fd

Please sign in to comment.