Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 53 lines (43 sloc) 1.558 kb
8fe339b @maxwell EM websocket cleanly merged with master. webfingering is now async
maxwell authored
1 class WebfingerProfile
2 attr_accessor :webfinger_profile, :account, :links, :hcard, :guid, :public_key, :seed_location
3
4 def initialize(account, webfinger_profile)
5 @account = account
6 @webfinger_profile = webfinger_profile
7 @links = {}
8 set_fields
9 end
85e0736 Remove stray puts
Raphael Sofaer authored
10
8fe339b @maxwell EM websocket cleanly merged with master. webfingering is now async
maxwell authored
11 def valid_diaspora_profile?
12 !(@webfinger_profile.nil? || @account.nil? || @links.nil? || @hcard.nil? ||
13 @guid.nil? || @public_key.nil? || @seed_location.nil? )
14 end
15
16 private
17
18 def set_fields
19 doc = Nokogiri::XML.parse(webfinger_profile)
85e0736 Remove stray puts
Raphael Sofaer authored
20
8fe339b @maxwell EM websocket cleanly merged with master. webfingering is now async
maxwell authored
21 account_string = doc.css('Subject').text.gsub('acct:', '').strip
85e0736 Remove stray puts
Raphael Sofaer authored
22
8fe339b @maxwell EM websocket cleanly merged with master. webfingering is now async
maxwell authored
23 raise "account in profile(#{account_string}) and account requested (#{@account}) do not match" if account_string != @account
24
85e0736 Remove stray puts
Raphael Sofaer authored
25 doc.css('Link').each do |l|
8fe339b @maxwell EM websocket cleanly merged with master. webfingering is now async
maxwell authored
26 rel = text_of_attribute(l, 'rel')
27 href = text_of_attribute(l, 'href')
28 @links[rel] = href
29 case rel
30 when "http://microformats.org/profile/hcard"
31 @hcard = href
32 when "http://joindiaspora.com/guid"
85e0736 Remove stray puts
Raphael Sofaer authored
33 @guid = href
8fe339b @maxwell EM websocket cleanly merged with master. webfingering is now async
maxwell authored
34 when "http://joindiaspora.com/seed_location"
35 @seed_location = href
36 end
37 end
38
39 if doc.at('Link[rel=diaspora-public-key]')
40 begin
85e0736 Remove stray puts
Raphael Sofaer authored
41 pubkey = text_of_attribute( doc.at('Link[rel=diaspora-public-key]'), 'href')
8fe339b @maxwell EM websocket cleanly merged with master. webfingering is now async
maxwell authored
42 @public_key = Base64.decode64 pubkey
43 rescue Exception => e
22d5e91 @maxwell remove splunk logging
maxwell authored
44 Rails.logger.info("event => :invalid_profile, :identifier => #{@account}")
8fe339b @maxwell EM websocket cleanly merged with master. webfingering is now async
maxwell authored
45 end
46 end
47 end
85e0736 Remove stray puts
Raphael Sofaer authored
48
8fe339b @maxwell EM websocket cleanly merged with master. webfingering is now async
maxwell authored
49 def text_of_attribute(doc, attr)
50 doc.attribute(attr) ? doc.attribute(attr).text : nil
51 end
52 end
Something went wrong with that request. Please try again.