api compatabile, but ugly

This commit is contained in:
maxwell 2010-12-01 13:39:00 -08:00 committed by Raphael
parent 732bde1834
commit 9aa093a0a3
4 changed files with 46 additions and 56 deletions

View file

@ -48,7 +48,7 @@ gem 'mini_magick'
gem 'aws' gem 'aws'
gem 'fastercsv', :require => false gem 'fastercsv', :require => false
gem 'jammit' gem 'jammit'
gem 'rest-client'
#Backups #Backups
gem "cloudfiles", :require => false gem "cloudfiles", :require => false

View file

@ -393,6 +393,7 @@ DEPENDENCIES
omniauth omniauth
pubsubhubbub pubsubhubbub
rails (= 3.0.1) rails (= 3.0.1)
rest-client
roxml! roxml!
rspec (>= 2.0.0) rspec (>= 2.0.0)
rspec-instafail rspec-instafail

View file

@ -26,7 +26,13 @@ class EMWebfinger
process_callbacks person process_callbacks person
else else
Rails.logger.info("event=EMWebfinger status=remote target=#{@account}") Rails.logger.info("event=EMWebfinger status=remote target=#{@account}")
get_xrd profile_url = get_xrd
webfinger_profile = get_webfinger_profile(profile_url) if profile_url
fingered_person = make_person_from_webfinger(webfinger_profile) if webfinger_profile
process_callbacks(fingered_person)
end end
end end
@ -38,58 +44,54 @@ class EMWebfinger
private private
def get_xrd def get_xrd
http = EventMachine::HttpRequest.new(xrd_url).get OPTS begin
http.callback { http = RestClient.get xrd_url, OPTS
profile_url = webfinger_profile_url(http.response)
if profile_url
get_webfinger_profile(profile_url)
elsif @ssl
@ssl = false
get_xrd
else
process_callbacks I18n.t('webfinger.not_enabled', :account => @account)
end
}
http.errback { profile_url = webfinger_profile_url(http.body)
if profile_url
return profile_url
else
raise "no profile URL"
end
rescue
if @ssl if @ssl
@ssl = false @ssl = false
get_xrd retry
else else
process_callbacks I18n.t('webfinger.xrd_fetch_failed', :account => @account) process_callbacks I18n.t('webfinger.xrd_fetch_failed', :account => @account)
end } return
end
end
end end
def get_webfinger_profile(profile_url) def get_webfinger_profile(profile_url)
http = EventMachine::HttpRequest.new(profile_url).get OPTS
http.callback{ make_person_from_webfinger(http.response) } begin
http.errback{ process_callbacks I18n.t('webfinger.fetch_failed', :profile_url => profile_url) } http = RestClient.get(profile_url, OPTS)
return http.body
rescue Exception => e
puts e.message
process_callbacks I18n.t('webfinger.fetch_failed', :profile_url => profile_url)
return
end
end end
def make_person_from_webfinger(webfinger_profile) def make_person_from_webfinger(webfinger_profile)
unless webfinger_profile.strip == "" unless webfinger_profile.strip == ""
begin
wf_profile = WebfingerProfile.new(@account, webfinger_profile) wf_profile = WebfingerProfile.new(@account, webfinger_profile)
http = EventMachine::HttpRequest.new(wf_profile.hcard).get OPTS
http.callback{
begin begin
hcard = HCard.build http.response hcard = RestClient.get(wf_profile.hcard, OPTS)
p = Person.build_from_webfinger(wf_profile, hcard)
process_callbacks(p)
rescue rescue
process_callbacks I18n.t 'webfinger.no_person_constructed' process_callbacks I18n.t('webfinger.hcard_fetch_failed', :account => @account)
return
end end
}
http.errback{
process_callbacks I18n.t('webfinger.hcard_fetch_failed', :account => @account) }
rescue card = HCard.build hcard.body
process_callbacks "No person could be constructed from this webfinger profile." p = Person.build_from_webfinger(wf_profile, card)
end
end end
end end

View file

@ -36,19 +36,6 @@ describe EMWebfinger do
n.instance_variable_get(:@account).should_not be nil n.instance_variable_get(:@account).should_not be nil
end end
it 'should raise an error on an unresonable email' do
proc{
EMWebfinger.new("joe.valid.email@my-address.com")
}.should_not raise_error(RuntimeError, "Identifier is invalid")
end
it 'should not allow port numbers' do
pending
proc{
EMWebfinger.new('eviljoe@diaspora.local:3000')
}.should raise_error(RuntimeError, "Identifier is invalid")
end
it 'should set ssl as the default' do it 'should set ssl as the default' do
foo = EMWebfinger.new(account) foo = EMWebfinger.new(account)
foo.instance_variable_get(:@ssl).should be true foo.instance_variable_get(:@ssl).should be true