You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
595 B

  1. # frozen_string_literal: true
  2. class SubscribeService < BaseService
  3. def call(account)
  4. account.secret = SecureRandom.hex
  5. subscription = account.subscription(api_subscription_url(account.id))
  6. response = subscription.subscribe
  7. unless response.successful?
  8. account.secret = ''
  9. Rails.logger.debug "PuSH subscription request for #{account.acct} failed: #{response.message}"
  10. end
  11. account.save!
  12. rescue HTTP::Error, OpenSSL::SSL::SSLError
  13. Rails.logger.debug "PuSH subscription request for #{account.acct} could not be made due to HTTP or SSL error"
  14. end
  15. end