Improve code style
This commit is contained in:
@ -17,7 +17,7 @@ class FetchAtomService < BaseService
|
||||
private
|
||||
|
||||
def process_html(body)
|
||||
Rails.logger.debug "Processing HTML"
|
||||
Rails.logger.debug 'Processing HTML'
|
||||
|
||||
page = Nokogiri::HTML(body)
|
||||
alternate_link = page.xpath('//link[@rel="alternate"]').find { |link| link['type'] == 'application/atom+xml' }
|
||||
@ -27,7 +27,7 @@ class FetchAtomService < BaseService
|
||||
end
|
||||
|
||||
def process_headers(url, response)
|
||||
Rails.logger.debug "Processing link header"
|
||||
Rails.logger.debug 'Processing link header'
|
||||
|
||||
link_header = LinkHeader.parse(response['Link'].is_a?(Array) ? response['Link'].first : response['Link'])
|
||||
alternate_link = link_header.find_link(['rel', 'alternate'], ['type', 'application/atom+xml'])
|
||||
|
@ -1,6 +1,6 @@
|
||||
class FetchRemoteAccountService < BaseService
|
||||
def call(url)
|
||||
atom_url, body = FetchAtomService.new.(url)
|
||||
atom_url, body = FetchAtomService.new.call(url)
|
||||
|
||||
return nil if atom_url.nil?
|
||||
return process_atom(atom_url, body)
|
||||
@ -18,6 +18,6 @@ class FetchRemoteAccountService < BaseService
|
||||
|
||||
Rails.logger.debug "Going to webfinger #{username}@#{domain}"
|
||||
|
||||
return FollowRemoteAccountService.new.("#{username}@#{domain}")
|
||||
return FollowRemoteAccountService.new.call("#{username}@#{domain}")
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
class FetchRemoteStatusService < BaseService
|
||||
def call(url)
|
||||
atom_url, body = FetchAtomService.new.(url)
|
||||
atom_url, body = FetchAtomService.new.call(url)
|
||||
|
||||
return nil if atom_url.nil?
|
||||
return process_atom(atom_url, body)
|
||||
@ -9,14 +9,14 @@ class FetchRemoteStatusService < BaseService
|
||||
private
|
||||
|
||||
def process_atom(url, body)
|
||||
Rails.logger.debug "Processing Atom for remote status"
|
||||
Rails.logger.debug 'Processing Atom for remote status'
|
||||
|
||||
xml = Nokogiri::XML(body)
|
||||
account = extract_author(url, xml)
|
||||
|
||||
return nil if account.nil?
|
||||
|
||||
statuses = ProcessFeedService.new.(body, account)
|
||||
statuses = ProcessFeedService.new.call(body, account)
|
||||
|
||||
return statuses.first
|
||||
end
|
||||
@ -30,6 +30,6 @@ class FetchRemoteStatusService < BaseService
|
||||
|
||||
Rails.logger.debug "Going to webfinger #{username}@#{domain}"
|
||||
|
||||
return FollowRemoteAccountService.new.("#{username}@#{domain}")
|
||||
return FollowRemoteAccountService.new.call("#{username}@#{domain}")
|
||||
end
|
||||
end
|
||||
|
@ -28,11 +28,11 @@ class FollowRemoteAccountService < BaseService
|
||||
hubs = feed.xpath('//xmlns:link[@rel="hub"]')
|
||||
|
||||
if hubs.empty? || hubs.first.attribute('href').nil?
|
||||
raise Goldfinger::Error, "No PubSubHubbub hubs found"
|
||||
raise Goldfinger::Error, 'No PubSubHubbub hubs found'
|
||||
end
|
||||
|
||||
if feed.at_xpath('/xmlns:feed/xmlns:author/xmlns:uri').nil?
|
||||
raise Goldfinger::Error, "No author URI found"
|
||||
raise Goldfinger::Error, 'No author URI found'
|
||||
end
|
||||
|
||||
account.uri = feed.at_xpath('/xmlns:feed/xmlns:author/xmlns:uri').content
|
||||
@ -53,12 +53,12 @@ class FollowRemoteAccountService < BaseService
|
||||
|
||||
def get_profile(xml, account)
|
||||
author = xml.at_xpath('/xmlns:feed/xmlns:author')
|
||||
update_remote_profile_service.(author, account)
|
||||
update_remote_profile_service.call(author, account)
|
||||
end
|
||||
|
||||
def magic_key_to_pem(magic_key)
|
||||
_, modulus, exponent = magic_key.split('.')
|
||||
modulus, exponent = [modulus, exponent].map { |n| Base64.urlsafe_decode64(n).bytes.inject(0) { |num, byte| (num << 8) | byte } }
|
||||
modulus, exponent = [modulus, exponent].map { |n| Base64.urlsafe_decode64(n).bytes.inject(0) { |a, e| (a << 8) | e } }
|
||||
|
||||
key = OpenSSL::PKey::RSA.new
|
||||
key.n = modulus
|
||||
@ -75,4 +75,3 @@ class FollowRemoteAccountService < BaseService
|
||||
HTTP.timeout(:per_operation, write: 20, connect: 20, read: 50)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,7 @@ class FollowService < BaseService
|
||||
# @param [Account] source_account From which to follow
|
||||
# @param [String] uri User URI to follow in the form of username@domain
|
||||
def call(source_account, uri)
|
||||
target_account = follow_remote_account_service.(uri)
|
||||
target_account = follow_remote_account_service.call(uri)
|
||||
|
||||
return nil if target_account.nil? || target_account.id == source_account.id
|
||||
|
||||
@ -12,7 +12,7 @@ class FollowService < BaseService
|
||||
if target_account.local?
|
||||
NotificationMailer.follow(target_account, source_account).deliver_later
|
||||
else
|
||||
subscribe_service.(target_account)
|
||||
subscribe_service.call(target_account)
|
||||
NotificationWorker.perform_async(follow.stream_entry.id, target_account.id)
|
||||
end
|
||||
|
||||
|
@ -8,7 +8,7 @@ class PostStatusService < BaseService
|
||||
def call(account, text, in_reply_to = nil, media_ids = nil)
|
||||
status = account.statuses.create!(text: text, thread: in_reply_to)
|
||||
attach_media(status, media_ids)
|
||||
process_mentions_service.(status)
|
||||
process_mentions_service.call(status)
|
||||
DistributionWorker.perform_async(status.id)
|
||||
account.ping!(account_url(account, format: 'atom'), [Rails.configuration.x.hub_url])
|
||||
status
|
||||
@ -19,7 +19,7 @@ class PostStatusService < BaseService
|
||||
def attach_media(status, media_ids)
|
||||
return if media_ids.nil? || !media_ids.is_a?(Enumerable)
|
||||
|
||||
media = MediaAttachment.where(status_id: nil).where(id: media_ids.take(4).map { |id| id.to_i })
|
||||
media = MediaAttachment.where(status_id: nil).where(id: media_ids.take(4).map(&:to_i))
|
||||
media.update(status_id: status.id)
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,7 @@ class ProcessFeedService < BaseService
|
||||
# @return [Enumerable] created statuses
|
||||
def call(body, account)
|
||||
xml = Nokogiri::XML(body)
|
||||
update_remote_profile_service.(xml.at_xpath('/xmlns:feed/xmlns:author'), account) unless xml.at_xpath('/xmlns:feed').nil?
|
||||
update_remote_profile_service.call(xml.at_xpath('/xmlns:feed/xmlns:author'), account) unless xml.at_xpath('/xmlns:feed').nil?
|
||||
xml.xpath('//xmlns:entry').reverse_each.map { |entry| process_entry(account, entry) }.compact
|
||||
end
|
||||
|
||||
@ -60,7 +60,7 @@ class ProcessFeedService < BaseService
|
||||
href_val = mention_link.attribute('href').value
|
||||
|
||||
next if href_val == 'http://activityschema.org/collection/public'
|
||||
|
||||
|
||||
href = Addressable::URI.parse(href_val)
|
||||
|
||||
if href.host == Rails.configuration.x.local_domain
|
||||
@ -77,7 +77,7 @@ class ProcessFeedService < BaseService
|
||||
mentioned_account = Account.find_by(url: href.to_s)
|
||||
|
||||
if mentioned_account.nil?
|
||||
mentioned_account = FetchRemoteAccountService.new.(href)
|
||||
mentioned_account = FetchRemoteAccountService.new.call(href)
|
||||
end
|
||||
|
||||
unless mentioned_account.nil?
|
||||
@ -94,7 +94,7 @@ class ProcessFeedService < BaseService
|
||||
media = MediaAttachment.where(status: status, remote_url: enclosure_link.attribute('href').value).first
|
||||
|
||||
next unless media.nil?
|
||||
|
||||
|
||||
media = MediaAttachment.new(account: status.account, status: status, remote_url: enclosure_link.attribute('href').value)
|
||||
media.file_remote_url = enclosure_link.attribute('href').value
|
||||
media.save
|
||||
@ -128,7 +128,7 @@ class ProcessFeedService < BaseService
|
||||
end
|
||||
|
||||
def delete_post!(status)
|
||||
remove_status_service.(status)
|
||||
remove_status_service.call(status)
|
||||
end
|
||||
|
||||
def find_original_status(_xml, id)
|
||||
@ -148,7 +148,7 @@ class ProcessFeedService < BaseService
|
||||
account = Account.find_by(username: username, domain: domain)
|
||||
|
||||
if account.nil?
|
||||
account = follow_remote_account_service.("#{username}@#{domain}")
|
||||
account = follow_remote_account_service.call("#{username}@#{domain}")
|
||||
end
|
||||
|
||||
status = Status.new(account: account, uri: target_id(xml), text: target_content(xml), url: target_url(xml), created_at: published(xml), updated_at: updated(xml))
|
||||
|
@ -14,11 +14,11 @@ class ProcessInteractionService < BaseService
|
||||
account = Account.find_by(username: username, domain: domain)
|
||||
|
||||
if account.nil?
|
||||
account = follow_remote_account_service.("#{username}@#{domain}")
|
||||
account = follow_remote_account_service.call("#{username}@#{domain}")
|
||||
end
|
||||
|
||||
if salmon.verify(envelope, account.keypair)
|
||||
update_remote_profile_service.(xml.at_xpath('/xmlns:entry/xmlns:author'), account)
|
||||
update_remote_profile_service.call(xml.at_xpath('/xmlns:entry/xmlns:author'), account)
|
||||
|
||||
case verb(xml)
|
||||
when :follow
|
||||
@ -71,7 +71,7 @@ class ProcessInteractionService < BaseService
|
||||
return if status.nil?
|
||||
|
||||
if account.id == status.account_id
|
||||
remove_status_service.(status)
|
||||
remove_status_service.call(status)
|
||||
end
|
||||
end
|
||||
|
||||
@ -82,7 +82,7 @@ class ProcessInteractionService < BaseService
|
||||
end
|
||||
|
||||
def add_post!(body, account)
|
||||
process_feed_service.(body, account)
|
||||
process_feed_service.call(body, account)
|
||||
end
|
||||
|
||||
def status(xml)
|
||||
|
@ -12,7 +12,7 @@ class ProcessMentionsService < BaseService
|
||||
|
||||
if mentioned_account.nil? && !domain.nil?
|
||||
begin
|
||||
mentioned_account = follow_remote_account_service.("#{match.first}")
|
||||
mentioned_account = follow_remote_account_service.call(match.first.to_s)
|
||||
rescue Goldfinger::Error, HTTP::Error
|
||||
mentioned_account = nil
|
||||
end
|
||||
|
@ -39,7 +39,7 @@ class RemoveStatusService < BaseService
|
||||
|
||||
def remove_reblogs(status)
|
||||
status.reblogs.each do |reblog|
|
||||
RemoveStatusService.new.(reblog)
|
||||
RemoveStatusService.new.call(reblog)
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user