parent
10eb47a33e
commit
fa7868675d
@ -0,0 +1,3 @@ |
||||
class BaseService |
||||
include ApplicationHelper |
||||
end |
@ -0,0 +1,16 @@ |
||||
class FetchEntryService < BaseService |
||||
# Knowing nothing but the URL of a remote status, create a local representation of it and return it |
||||
# @param [String] url Atom URL |
||||
# @return [Status] |
||||
def call(url) |
||||
body = http_client.get(url) |
||||
xml = Nokogiri::XML(body) |
||||
# todo |
||||
end |
||||
|
||||
private |
||||
|
||||
def http_client |
||||
HTTP |
||||
end |
||||
end |
@ -1,12 +1,23 @@ |
||||
class FollowService |
||||
class FollowService < BaseService |
||||
# Follow a remote user, notify remote user about the follow |
||||
# @param [Account] source_account From which to follow |
||||
# @param [String] uri User URI to follow in the form of username@domain |
||||
def call(source_account, uri) |
||||
target_account = follow_remote_account_service.(uri) |
||||
source_account.follow!(target_account) unless target_account.nil? |
||||
|
||||
return if target_account.nil? |
||||
|
||||
follow = source_account.follow!(target_account) |
||||
send_interaction_service.(follow.stream_entry, target_account) |
||||
end |
||||
|
||||
private |
||||
|
||||
def follow_remote_account_service |
||||
FollowRemoteAccountService.new |
||||
@follow_remote_account_service ||= FollowRemoteAccountService.new |
||||
end |
||||
|
||||
def send_interaction_service |
||||
@send_interaction_service ||= SendInteractionService.new |
||||
end |
||||
end |
||||
|
@ -0,0 +1,29 @@ |
||||
class SendInteractionService < BaseService |
||||
include AtomHelper |
||||
|
||||
# Send an Atom representation of an interaction to a remote Salmon endpoint |
||||
# @param [StreamEntry] stream_entry |
||||
# @param [Account] target_account |
||||
def call(stream_entry, target_account) |
||||
envelope = salmon.pack(entry_xml(stream_entry), target_account.keypair) |
||||
salmon.post(target_account.salmon_url, envelope) |
||||
end |
||||
|
||||
private |
||||
|
||||
def entry_xml(stream_entry) |
||||
Nokogiri::XML::Builder.new do |xml| |
||||
entry(xml, true) do |
||||
author(xml) do |
||||
include_author xml, stream_entry.account |
||||
end |
||||
|
||||
include_entry xml, stream_entry |
||||
end |
||||
end.to_xml |
||||
end |
||||
|
||||
def salmon |
||||
@salmon ||= OStatus2::Salmon.new |
||||
end |
||||
end |
@ -0,0 +1,15 @@ |
||||
class UnfollowService < BaseService |
||||
# Unfollow and notify the remote user |
||||
# @param [Account] source_account Where to unfollow from |
||||
# @param [Account] target_account Which to unfollow |
||||
def call(source_account, target_account) |
||||
follow = source_account.unfollow!(target_account) |
||||
send_interaction_service.(follow.stream_entry, target_account) unless target_account.local? |
||||
end |
||||
|
||||
private |
||||
|
||||
def send_interaction_service |
||||
@send_interaction_service ||= SendInteractionService.new |
||||
end |
||||
end |
Loading…
Reference in new issue