Send Salmon interactions
This commit is contained in:
parent
10eb47a33e
commit
fa7868675d
15 changed files with 118 additions and 25 deletions
29
app/services/send_interaction_service.rb
Normal file
29
app/services/send_interaction_service.rb
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue