This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
2016-02-24 12:57:29 +01:00
|
|
|
class SendInteractionService < BaseService
|
2016-02-29 19:42:08 +01:00
|
|
|
include AtomBuilderHelper
|
2016-02-24 12:57:29 +01:00
|
|
|
|
|
|
|
# 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)
|
2016-02-28 15:46:29 +01:00
|
|
|
envelope = salmon.pack(entry_xml(stream_entry), stream_entry.account.keypair)
|
2016-02-24 12:57:29 +01:00
|
|
|
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
|