diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-09-29 21:28:21 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-09-29 21:28:21 +0200 |
commit | 927333f4f89403c5a6a2b421065112e517d88193 (patch) | |
tree | 1767e142ee9263b5b6968b5b43228ee0889232c5 /app/services | |
parent | e4aebad35afae12f4b7503fb6c3783fcd3809761 (diff) |
Improve code style
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/fetch_atom_service.rb | 4 | ||||
-rw-r--r-- | app/services/fetch_remote_account_service.rb | 4 | ||||
-rw-r--r-- | app/services/fetch_remote_status_service.rb | 8 | ||||
-rw-r--r-- | app/services/follow_remote_account_service.rb | 9 | ||||
-rw-r--r-- | app/services/follow_service.rb | 4 | ||||
-rw-r--r-- | app/services/post_status_service.rb | 4 | ||||
-rw-r--r-- | app/services/process_feed_service.rb | 12 | ||||
-rw-r--r-- | app/services/process_interaction_service.rb | 8 | ||||
-rw-r--r-- | app/services/process_mentions_service.rb | 2 | ||||
-rw-r--r-- | app/services/remove_status_service.rb | 2 |
10 files changed, 28 insertions, 29 deletions
diff --git a/app/services/fetch_atom_service.rb b/app/services/fetch_atom_service.rb index 819bea02ea4..4be7f635579 100644 --- a/app/services/fetch_atom_service.rb +++ b/app/services/fetch_atom_service.rb @@ -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']) diff --git a/app/services/fetch_remote_account_service.rb b/app/services/fetch_remote_account_service.rb index 072eb2cd3a1..5f45f9b2899 100644 --- a/app/services/fetch_remote_account_service.rb +++ b/app/services/fetch_remote_account_service.rb @@ -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 diff --git a/app/services/fetch_remote_status_service.rb b/app/services/fetch_remote_status_service.rb index 7613607b44e..24a63e8414d 100644 --- a/app/services/fetch_remote_status_service.rb +++ b/app/services/fetch_remote_status_service.rb @@ -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 diff --git a/app/services/follow_remote_account_service.rb b/app/services/follow_remote_account_service.rb index ef3949e3682..9fbf17091d2 100644 --- a/app/services/follow_remote_account_service.rb +++ b/app/services/follow_remote_account_service.rb @@ -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 - diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index fb782e87108..6dd85dd7ddb 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -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 diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 930e7ec9e13..6e53c7e526f 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -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 diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb index 47992b2460a..fdf59b41c15 100644 --- a/app/services/process_feed_service.rb +++ b/app/services/process_feed_service.rb @@ -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)) diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb index 1e3ed6b1279..96dae30da32 100644 --- a/app/services/process_interaction_service.rb +++ b/app/services/process_interaction_service.rb @@ -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) diff --git a/app/services/process_mentions_service.rb b/app/services/process_mentions_service.rb index 5ea1842527b..2d09fc2cdf5 100644 --- a/app/services/process_mentions_service.rb +++ b/app/services/process_mentions_service.rb @@ -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 diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index b64f04a14b5..030d23ff6ab 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -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 |