diff --git a/lib/em-webfinger.rb b/lib/em-webfinger.rb index b9eaf03bf7fa61e078553cbdeed248fd03f2af05..67b4dee5219b69b8310407de35b2a29c80c11c0d 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 3dab4b9726e0b84e9fd585c1c044644506687700..7ad6ad2dba90f1e9f814c0a357bf6f7ec4e6ce5d 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