Class: Webfinger
- Inherits:
-
Object
- Object
- Webfinger
- Defined in:
- lib/webfinger.rb
Overview
Copyright © 2010-2012, Diaspora Inc. This file is
licensed under the Affero General Public License version 3 or later. See
the COPYRIGHT file.
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#hcard ⇒ Object
Returns the value of attribute hcard.
-
#hcard_xrd ⇒ Object
Returns the value of attribute hcard_xrd.
-
#host_meta_xrd ⇒ Object
this tries the xrl url with https first, then falls back to http.
-
#person ⇒ Object
Returns the value of attribute person.
-
#ssl ⇒ Object
Returns the value of attribute ssl.
-
#webfinger_profile ⇒ Object
Returns the value of attribute webfinger_profile.
-
#webfinger_profile_xrd ⇒ Object
Returns the value of attribute webfinger_profile_xrd.
Class Method Summary collapse
Instance Method Summary collapse
- #cached_person ⇒ Object
- #create_or_update_person_from_webfinger_profile! ⇒ Object
- #existing_person_with_profile? ⇒ Boolean
- #fetch ⇒ Object
- #get(url) ⇒ Object
- #hcard_url ⇒ Object
- #host_meta_url ⇒ Object
-
#initialize(account) ⇒ Webfinger
constructor
A new instance of Webfinger.
- #make_person_from_webfinger ⇒ Object
- #swizzle(template) ⇒ Object
- #webfinger_profile_url ⇒ Object
Constructor Details
#initialize(account) ⇒ Webfinger
10 11 12 13 |
# File 'lib/webfinger.rb', line 10 def initialize(account) self.account = account self.ssl = true end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account
6 7 8 |
# File 'lib/webfinger.rb', line 6 def account @account end |
#hcard ⇒ Object
Returns the value of attribute hcard
6 7 8 |
# File 'lib/webfinger.rb', line 6 def hcard @hcard end |
#hcard_xrd ⇒ Object
Returns the value of attribute hcard_xrd
6 7 8 |
# File 'lib/webfinger.rb', line 6 def hcard_xrd @hcard_xrd end |
#host_meta_xrd ⇒ Object
this tries the xrl url with https first, then falls back to http
65 66 67 |
# File 'lib/webfinger.rb', line 65 def end |
#person ⇒ Object
Returns the value of attribute person
6 7 8 |
# File 'lib/webfinger.rb', line 6 def person @person end |
#ssl ⇒ Object
Returns the value of attribute ssl
6 7 8 |
# File 'lib/webfinger.rb', line 6 def ssl @ssl end |
#webfinger_profile ⇒ Object
Returns the value of attribute webfinger_profile
6 7 8 |
# File 'lib/webfinger.rb', line 6 def webfinger_profile @webfinger_profile end |
#webfinger_profile_xrd ⇒ Object
Returns the value of attribute webfinger_profile_xrd
6 7 8 |
# File 'lib/webfinger.rb', line 6 def webfinger_profile_xrd @webfinger_profile_xrd end |
Class Method Details
.in_background(account, opts = {}) ⇒ Object
21 22 23 |
# File 'lib/webfinger.rb', line 21 def self.in_background(account, opts={}) Workers::FetchWebfinger.perform_async(account) end |
Instance Method Details
#cached_person ⇒ Object
49 50 51 |
# File 'lib/webfinger.rb', line 49 def cached_person self.person ||= Person.by_account_identifier(account) end |
#create_or_update_person_from_webfinger_profile! ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/webfinger.rb', line 53 def create_or_update_person_from_webfinger_profile! FEDERATION_LOGGER.info("webfingering #{account}, it is not known or needs updating") if person #update my profile please person.assign_new_profile_from_hcard(self.hcard) else person = make_person_from_webfinger end FEDERATION_LOGGER.info("successfully webfingered #{@account}") if person person end |
#existing_person_with_profile? ⇒ Boolean
45 46 47 |
# File 'lib/webfinger.rb', line 45 def existing_person_with_profile? cached_person.present? && cached_person.profile.present? end |
#fetch ⇒ Object
16 17 18 19 |
# File 'lib/webfinger.rb', line 16 def fetch return person if existing_person_with_profile? create_or_update_person_from_webfinger_profile! end |
#get(url) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/webfinger.rb', line 30 def get(url) Rails.logger.info("Getting: #{url} for #{account}") begin res = Faraday.get(url) return false if res.status == 404 res.body rescue OpenSSL::SSL::SSLError => e Rails.logger.info "Failed to fetch #{url}: SSL setup invalid" raise e rescue => e Rails.logger.info("Failed to fetch: #{url} for #{account}; #{e.message}") raise e end end |
#hcard_url ⇒ Object
87 88 89 |
# File 'lib/webfinger.rb', line 87 def hcard_url self.webfinger_profile.hcard end |
#host_meta_url ⇒ Object
111 112 113 114 |
# File 'lib/webfinger.rb', line 111 def domain = account.split('@')[1] "http#{'s' if self.ssl}://#{domain}/.well-known/host-meta" end |
#make_person_from_webfinger ⇒ Object
107 108 109 |
# File 'lib/webfinger.rb', line 107 def make_person_from_webfinger Person.create_from_webfinger(webfinger_profile, hcard) unless webfinger_profile_xrd == false end |
#swizzle(template) ⇒ Object
116 117 118 |
# File 'lib/webfinger.rb', line 116 def swizzle(template) template.gsub('{uri}', account) end |
#webfinger_profile_url ⇒ Object
91 92 93 94 95 |
# File 'lib/webfinger.rb', line 91 def webfinger_profile_url doc = Nokogiri::XML(self.) return nil if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0" swizzle doc.search('Link').find{|x| x['rel']=='lrdd'}['template'] end |