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.

35 lines
651 B

  1. # frozen_string_literal: true
  2. class Api::SalmonController < Api::BaseController
  3. before_action :set_account
  4. respond_to :txt
  5. def update
  6. if verify_payload?
  7. process_salmon
  8. head 202
  9. elsif payload.present?
  10. [signature_verification_failure_reason, 401]
  11. else
  12. head 400
  13. end
  14. end
  15. private
  16. def set_account
  17. @account = Account.find(params[:id])
  18. end
  19. def payload
  20. @_payload ||= request.body.read
  21. end
  22. def verify_payload?
  23. payload.present? && VerifySalmonService.new.call(payload)
  24. end
  25. def process_salmon
  26. SalmonWorker.perform_async(@account.id, payload.force_encoding('UTF-8'))
  27. end
  28. end