Class: Fediverse::Webfinger
- Inherits:
-
Object
- Object
- Fediverse::Webfinger
- Defined in:
- lib/fediverse/webfinger.rb
Overview
Methods related to Webfinger: find accounts, fetch actors,...
Constant Summary collapse
- ACCOUNT_REGEX =
/(?<username>[a-z0-9\-_.]+)(?:@(?<domain>.*))?/
Class Method Summary collapse
-
.fetch_actor(username, domain) ⇒ Fedipub::Actor?
Fetches a distant actor.
-
.fetch_actor_url(url) ⇒ Fedipub::Actor?
Fetches an actor given its URL.
-
.local_user?(hash) ⇒ Boolean
Determines if a given account string should be a local account (same host as configured one).
-
.remote_follow_url(username, domain, actor_url: nil) ⇒ String
Returns remote follow link template, or complete link if actor_url is provided.
-
.split_account(account) ⇒ MatchData?
Extracts username and domain from an account string.
-
.webfinger(username, domain) ⇒ String?
Gets the real actor's federation URL from its username and domain.
Class Method Details
.fetch_actor(username, domain) ⇒ Fedipub::Actor?
Fetches a distant actor
35 36 37 |
# File 'lib/fediverse/webfinger.rb', line 35 def fetch_actor(username, domain) fetch_actor_url webfinger(username, domain) end |
.fetch_actor_url(url) ⇒ Fedipub::Actor?
Fetches an actor given its URL
44 45 46 |
# File 'lib/fediverse/webfinger.rb', line 44 def fetch_actor_url(url) webfinger_to_actor get_json url end |
.local_user?(hash) ⇒ Boolean
Determines if a given account string should be a local account (same host as configured one)
25 26 27 |
# File 'lib/fediverse/webfinger.rb', line 25 def local_user?(hash) hash[:username] && (hash[:domain].nil? || (hash[:domain] == Fedipub::Utils::Host.localhost)) end |
.remote_follow_url(username, domain, actor_url: nil) ⇒ String
Returns remote follow link template, or complete link if actor_url is provided
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fediverse/webfinger.rb', line 68 def remote_follow_url(username, domain, actor_url: nil) json = webfinger_response(username, domain) link = json['links'].find { |l| l['rel'] == 'http://ostatus.org/schema/1.0/subscribe' } return nil if link&.dig('template').nil? if actor_url link['template'].gsub('{uri}', CGI.escape(actor_url)) else link['template'] end end |
.split_account(account) ⇒ MatchData?
Extracts username and domain from an account string. Accepts forms "user@domain", "@user@domain" and "acct:user@domain"
16 17 18 |
# File 'lib/fediverse/webfinger.rb', line 16 def split_account(account) /\A(acct:|@)?#{ACCOUNT_REGEX}\z/io.match account end |
.webfinger(username, domain) ⇒ String?
Gets the real actor's federation URL from its username and domain
54 55 56 57 58 59 |
# File 'lib/fediverse/webfinger.rb', line 54 def webfinger(username, domain) json = webfinger_response(username, domain) link = json['links'].find { |l| Mime::Type.lookup(l['type']).to_sym == :activitypub } link['href'] if link end |