Refactoring Grape API methods into normal controllers & other things

This commit is contained in:
Eugen Rochko 2016-02-29 19:42:08 +01:00
parent 11ff92c9d7
commit 0e8f59c16f
63 changed files with 336 additions and 406 deletions

View file

@ -1,3 +1,4 @@
class BaseService
include RoutingHelper
include ApplicationHelper
end

View file

@ -38,7 +38,7 @@ class FollowRemoteAccountService < BaseService
account.secret = SecureRandom.hex
account.verify_token = SecureRandom.hex
subscription = account.subscription(subscription_url(account))
subscription = account.subscription(api_subscription_url(account.id))
subscription.subscribe
account.save!

View file

@ -9,7 +9,7 @@ class FollowService < BaseService
follow = source_account.follow!(target_account)
send_interaction_service.(follow.stream_entry, target_account)
source_account.ping!(atom_user_stream_url(id: source_account.id), [HUB_URL])
source_account.ping!(account_url(account, format: 'atom'), [HUB_URL])
end
private

View file

@ -7,7 +7,7 @@ class PostStatusService < BaseService
def call(account, text, in_reply_to = nil)
status = account.statuses.create!(text: text, thread: in_reply_to)
process_mentions_service.(status)
account.ping!(atom_user_stream_url(id: account.id), [HUB_URL])
account.ping!(account_url(account, format: 'atom'), [HUB_URL])
status
end

View file

@ -43,7 +43,7 @@ class ProcessInteractionService < BaseService
end
def mentions_account?(xml, account)
xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]').each { |mention_link| return true if mention_link.attribute('href').value == profile_url(account) }
xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]').each { |mention_link| return true if mention_link.attribute('href').value == url_for_target(account) }
false
end

View file

@ -5,7 +5,7 @@ class ReblogService < BaseService
# @return [Status]
def call(account, reblogged_status)
reblog = account.statuses.create!(reblog: reblogged_status, text: '')
account.ping!(atom_user_stream_url(id: account.id), [HUB_URL])
account.ping!(account_url(account, format: 'atom'), [HUB_URL])
return reblog if reblogged_status.local?
send_interaction_service.(reblog.stream_entry, reblogged_status.account)
reblog

View file

@ -1,5 +1,5 @@
class SendInteractionService < BaseService
include AtomHelper
include AtomBuilderHelper
# Send an Atom representation of an interaction to a remote Salmon endpoint
# @param [StreamEntry] stream_entry