From 7c32649df419496b10f2eb68a25dcb8cd65e1afb Mon Sep 17 00:00:00 2001 From: maxwell <maxwell@joindiaspora.com> Date: Fri, 29 Oct 2010 09:48:09 -0700 Subject: [PATCH] rebasing master --- lib/em-webfinger.rb | 13 ++++++++++--- spec/lib/em-webfinger_spec.rb | 12 ++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/em-webfinger.rb b/lib/em-webfinger.rb index b9eaf03bf7..67b4dee521 100644 --- a/lib/em-webfinger.rb +++ b/lib/em-webfinger.rb @@ -10,7 +10,7 @@ class EMWebfinger raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/)) # Raise an error if identifier is not a valid email (generous regexp) raise "Identifier is invalid" if !(@account=~ /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/) - + end def fetch raise 'you need to set a callback before calling fetch' if @callbacks.empty? person = Person.by_account_identifier(@account) @@ -27,10 +27,10 @@ class EMWebfinger end private - def get_xrd http = EventMachine::HttpRequest.new(xrd_url).get :timeout => TIMEOUT - http.callback { get_webfinger_profile(webfinger_profile_url(http.response)) } + http.callback { + get_webfinger_profile(webfinger_profile_url(http.response)) } http.errback { process_callbacks "there was an error getting the xrd at #{xrd_url}" } end @@ -64,6 +64,13 @@ class EMWebfinger ##helpers private + + def check_nil_response(html) + + end + + + def webfinger_profile_url(xrd_response) doc = Nokogiri::XML::Document.parse(xrd_response) swizzle doc.at('Link[rel=lrdd]').attribute('template').value diff --git a/spec/lib/em-webfinger_spec.rb b/spec/lib/em-webfinger_spec.rb index 3dab4b9726..7ad6ad2dba 100644 --- a/spec/lib/em-webfinger_spec.rb +++ b/spec/lib/em-webfinger_spec.rb @@ -59,6 +59,18 @@ describe EMWebfinger do n.on_person{|person| puts "foo"} n.instance_variable_get(:@callbacks).count.should be 1 + + it 'should not blow up if the returned xrd is nil' do + http = FakeHttpRequest.new(:success) + http.callbacks = [''] + EventMachine::HttpRequest.should_receive(:new).and_return(http) + n = EMWebfinger.new("foo@example.com") + + n.on_person{|person| + person = "sad" + } + + end end end -- GitLab