2016-11-15 16:56:29 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-20 00:39:03 +02:00
|
|
|
class SubscribeService < BaseService
|
|
|
|
def call(account)
|
2016-09-20 02:43:20 +02:00
|
|
|
account.secret = SecureRandom.hex
|
2016-09-20 00:39:03 +02:00
|
|
|
|
|
|
|
subscription = account.subscription(api_subscription_url(account.id))
|
|
|
|
response = subscription.subscribe
|
|
|
|
|
|
|
|
unless response.successful?
|
2016-09-20 02:43:20 +02:00
|
|
|
account.secret = ''
|
2016-09-20 00:39:03 +02:00
|
|
|
Rails.logger.debug "PuSH subscription request for #{account.acct} failed: #{response.message}"
|
|
|
|
end
|
|
|
|
|
|
|
|
account.save!
|
|
|
|
rescue HTTP::Error, OpenSSL::SSL::SSLError
|
|
|
|
Rails.logger.debug "PuSH subscription request for #{account.acct} could not be made due to HTTP or SSL error"
|
|
|
|
end
|
|
|
|
end
|