You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
735 B

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