about summary refs log tree commit diff
path: root/app/services/fetch_remote_account_service.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-09-26 16:42:38 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-26 16:44:40 +0200
commitc6b0311b8626b42bc7e79e0195047a50e5b64dd1 (patch)
treee68f4b6922de5ec6277de7bc76b2bdb47a8c3e89 /app/services/fetch_remote_account_service.rb
parent0bd4608ad1b29328f04fcad6e7a20ef61668d239 (diff)
Fix #54 - Fetch remote accounts by URL from mentions
Fetching atom extracted from FetchRemoteAccountService and FetchRemoteStatusService
into FetchAtomService. Mentions of the constant "http://activityschema.org/collection/public"
skipped as it's not a real URL/user.
Diffstat (limited to 'app/services/fetch_remote_account_service.rb')
-rw-r--r--app/services/fetch_remote_account_service.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/services/fetch_remote_account_service.rb b/app/services/fetch_remote_account_service.rb
new file mode 100644
index 000000000..d24ac2a37
--- /dev/null
+++ b/app/services/fetch_remote_account_service.rb
@@ -0,0 +1,22 @@
+class FetchRemoteAccountService < BaseService
+  def call(url)
+    atom_url, body = FetchAtomService.new.(url)
+
+    return nil if atom_url.nil?
+    return process_atom(atom_url, body)
+  end
+
+  private
+
+  def process_atom(url, body)
+    url_parts = Addressable::URI.parse(url)
+    username  = xml.at_xpath('//xmlns:author/xmlns:name').try(:content)
+    domain    = url_parts.host
+
+    return nil if username.nil?
+
+    Rails.logger.debug "Going to webfinger #{username}@#{domain}"
+
+    return FollowRemoteAccountService.new.("#{username}@#{domain}")
+  end
+end