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 'fastercsv', :require => false
gem 'jammit'
gem 'rest-client'
#Backups
gem "cloudfiles", :require => false

View file

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

View file

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

View file

@ -36,19 +36,6 @@ describe EMWebfinger do
n.instance_variable_get(:@account).should_not be nil
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
foo = EMWebfinger.new(account)
foo.instance_variable_get(:@ssl).should be true