send_interaction_service.rb 704 B

123456789101112131415161718192021222324252627
  1. class SendInteractionService < BaseService
  2. # Send an Atom representation of an interaction to a remote Salmon endpoint
  3. # @param [StreamEntry] stream_entry
  4. # @param [Account] target_account
  5. def call(stream_entry, target_account)
  6. envelope = salmon.pack(entry_xml(stream_entry), stream_entry.account.keypair)
  7. salmon.post(target_account.salmon_url, envelope)
  8. end
  9. private
  10. def entry_xml(stream_entry)
  11. Nokogiri::XML::Builder.new do |xml|
  12. entry(xml, true) do
  13. author(xml) do
  14. include_author xml, stream_entry.account
  15. end
  16. include_entry xml, stream_entry
  17. end
  18. end.to_xml
  19. end
  20. def salmon
  21. @salmon ||= OStatus2::Salmon.new
  22. end
  23. end