class FetchRemoteAccountService < BaseService
include AuthorExtractor
- def call(url, prefetched_body = nil)
+ def call(url, prefetched_body = nil, protocol = :ostatus)
if prefetched_body.nil?
resource_url, body, protocol = FetchAtomService.new.call(url)
else
resource_url = url
body = prefetched_body
- protocol = :ostatus
end
case protocol
# frozen_string_literal: true
class FetchRemoteResourceService < BaseService
+ include JsonLdHelper
+
attr_reader :url
def call(url)
private
def process_url
- case xml_root
- when 'feed'
- FetchRemoteAccountService.new.call(atom_url, body)
- when 'entry'
- FetchRemoteStatusService.new.call(atom_url, body)
+ case type
+ when 'Person'
+ FetchRemoteAccountService.new.call(atom_url, body, protocol)
+ when 'Note'
+ FetchRemoteStatusService.new.call(atom_url, body, protocol)
end
end
fetched_atom_feed.second
end
+ def protocol
+ fetched_atom_feed.third
+ end
+
+ def type
+ return json_data['type'] if protocol == :activitypub
+
+ case xml_root
+ when 'feed'
+ 'Person'
+ when 'entry'
+ 'Note'
+ end
+ end
+
+ def json_data
+ @_json_data ||= body_to_json(body)
+ end
+
def xml_root
xml_data.root.name
end
class FetchRemoteStatusService < BaseService
include AuthorExtractor
- def call(url, prefetched_body = nil)
+ def call(url, prefetched_body = nil, protocol = :ostatus)
if prefetched_body.nil?
resource_url, body, protocol = FetchAtomService.new.call(url)
else
resource_url = url
body = prefetched_body
- protocol = :ostatus
end
case protocol
_result = subject.call(url)
- expect(account_service).to have_received(:call).with(feed_url, feed_content)
+ expect(account_service).to have_received(:call).with(feed_url, feed_content, nil)
end
it 'fetches remote statuses for entry types' do
_result = subject.call(url)
- expect(account_service).to have_received(:call).with(feed_url, feed_content)
+ expect(account_service).to have_received(:call).with(feed_url, feed_content, nil)
end
end
end