rebasing master
This commit is contained in:
parent
6d139ab946
commit
7c32649df4
2 changed files with 22 additions and 3 deletions
|
|
@ -10,7 +10,7 @@ class EMWebfinger
|
||||||
raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/))
|
raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/))
|
||||||
# Raise an error if identifier is not a valid email (generous regexp)
|
# 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]$/)
|
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
|
def fetch
|
||||||
raise 'you need to set a callback before calling fetch' if @callbacks.empty?
|
raise 'you need to set a callback before calling fetch' if @callbacks.empty?
|
||||||
person = Person.by_account_identifier(@account)
|
person = Person.by_account_identifier(@account)
|
||||||
|
|
@ -27,10 +27,10 @@ class EMWebfinger
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get_xrd
|
def get_xrd
|
||||||
http = EventMachine::HttpRequest.new(xrd_url).get :timeout => TIMEOUT
|
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}" }
|
http.errback { process_callbacks "there was an error getting the xrd at #{xrd_url}" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -64,6 +64,13 @@ class EMWebfinger
|
||||||
|
|
||||||
##helpers
|
##helpers
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def check_nil_response(html)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def webfinger_profile_url(xrd_response)
|
def webfinger_profile_url(xrd_response)
|
||||||
doc = Nokogiri::XML::Document.parse(xrd_response)
|
doc = Nokogiri::XML::Document.parse(xrd_response)
|
||||||
swizzle doc.at('Link[rel=lrdd]').attribute('template').value
|
swizzle doc.at('Link[rel=lrdd]').attribute('template').value
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,18 @@ describe EMWebfinger do
|
||||||
|
|
||||||
n.on_person{|person| puts "foo"}
|
n.on_person{|person| puts "foo"}
|
||||||
n.instance_variable_get(:@callbacks).count.should be 1
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue