rebasing master

This commit is contained in:
maxwell 2010-10-29 09:48:09 -07:00
parent 6d139ab946
commit 7c32649df4
2 changed files with 22 additions and 3 deletions

View file

@ -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

View file

@ -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