RS, MS, relationship_flow returns the action and the url to execute it to

This commit is contained in:
maxwell 2010-07-20 16:13:58 -07:00
parent 715a6ae770
commit 933bf61db8
2 changed files with 67 additions and 13 deletions

View file

@ -1,16 +1,49 @@
module RequestsHelper module RequestsHelper
def diaspora_url(identifier)
if identifier.include? '@' def subscription_mode(profile)
if diaspora?(profile)
begin :friend
f = Redfinger.finger(identifier) elsif ostatus?(profile)
good_links = f.links.map{|x| return x.href if x.rel =='http://joindiaspora.com/seed_location'} :subscribe
identifier = good_links.first unless good_links.first.nil? else
rescue :none
end
end end
def diaspora?(profile)
profile_contains(profile, 'http://joindiaspora.com/seed_location')
end
def ostatus?(profile)
profile_contains(profile, 'http://ostatus.org/schema/1.0/subscribe')
end
def profile_contains(profile, rel)
profile.links.each{|x| return true if x.rel == rel}
false
end
def subscription_url(action, profile)
if action == :subscribe
pp profile.links
profile.links.select{|x| x.rel == 'http://schemas.google.com/g/2010#updates-from'}.first.href
elsif action == :friend
profile.links.select{|x| x.rel == 'http://joindiaspora.com/seed_location'}.first.href
else
''
end
end
def relationship_flow(identifier)
unless identifier.include?( '@')
return identifier
end end
identifier f = Redfinger.finger(identifier)
action = subscription_mode(f)
url = subscription_url(action, f)
{ action => url }
end end
end end

View file

@ -3,11 +3,18 @@ require File.dirname(__FILE__) + '/../spec_helper'
include RequestsHelper include RequestsHelper
describe RequestsHelper do describe RequestsHelper do
before do
@tom = Redfinger.finger('tom@tom.joindiaspora.com')
@evan = Redfinger.finger('evan@status.net')
@max = Redfinger.finger('mbs348@gmail.com')
end
describe "profile" do describe "profile" do
it 'should fetch the public webfinger profile on request' do it 'should fetch the public webfinger profile on request' do
pending "Can we please find a way to do this that doesn't freak me out if my internet connection is down? Thanks, Rafi" pending
#post :create {:request => {:destination_url => 'tom@tom.joindiaspora.com'} #post :create {:request => {:destination_url => 'tom@tom.joindiaspora.com'}
url = diaspora_url('http://tom.joindiaspora.com/') url = diaspora_url('http://tom.joindiaspora.com/')
url.should == 'http://tom.joindiaspora.com/' url.should == 'http://tom.joindiaspora.com/'
@ -15,5 +22,19 @@ describe RequestsHelper do
url = diaspora_url('tom@tom.joindiaspora.com') url = diaspora_url('tom@tom.joindiaspora.com')
url.should == 'http://tom.joindiaspora.com/' url.should == 'http://tom.joindiaspora.com/'
end end
it 'should detect how to subscribe to a diaspora or ostatus webfinger profile' do
subscription_mode(@tom).should == :friend
subscription_mode(@evan).should == :subscribe
subscription_mode(@max).should == :none
end
it 'should return the correct tag and url for a given address' do
relationship_flow('tom@tom.joindiaspora.com')[:friend].should == 'http://tom.joindiaspora.com/'
relationship_flow('evan@status.net')[:subscribe].should == 'http://evan.status.net/api/statuses/user_timeline/1.atom'
end
end end
end end