diff options
author | Matt Jankowski <mjankowski@thoughtbot.com> | 2017-05-09 13:58:18 -0400 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-09 19:58:18 +0200 |
commit | 441d6dc734d2590b14ca010076496e652d6ef676 (patch) | |
tree | b7543a42509b6f0aed0dfd7a0ee5931b9483dfc3 /app/services/pubsubhubbub | |
parent | d5cabfe5c65ac29d2f9c151b46c01a9fd885a9e0 (diff) |
Spec and refactor for pubsubhubbub/unsubscribe service (#2946)
* Add coverage for pubsub unsubscribe service * Refactor pubsub unsubscribe service
Diffstat (limited to 'app/services/pubsubhubbub')
-rw-r--r-- | app/services/pubsubhubbub/unsubscribe_service.rb | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/app/services/pubsubhubbub/unsubscribe_service.rb b/app/services/pubsubhubbub/unsubscribe_service.rb index 7adadf8ed..99fec8b14 100644 --- a/app/services/pubsubhubbub/unsubscribe_service.rb +++ b/app/services/pubsubhubbub/unsubscribe_service.rb @@ -1,15 +1,31 @@ # frozen_string_literal: true class Pubsubhubbub::UnsubscribeService < BaseService - def call(account, callback) - return ['Invalid topic URL', 422] if account.nil? + attr_reader :account, :callback_url - subscription = Subscription.find_by(account: account, callback_url: callback) + def call(account, callback_url) + @account = account + @callback_url = callback_url - unless subscription.nil? - Pubsubhubbub::ConfirmationWorker.perform_async(subscription.id, 'unsubscribe') + process_unsubscribe + end + + private + + def process_unsubscribe + if account.nil? + ['Invalid topic URL', 422] + else + confirm_unsubscribe unless subscription.nil? + ['', 202] end + end + + def confirm_unsubscribe + Pubsubhubbub::ConfirmationWorker.perform_async(subscription.id, 'unsubscribe') + end - ['', 202] + def subscription + @_subscription ||= Subscription.find_by(account: account, callback_url: callback_url) end end |