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.

31 lines
846 B

  1. class Api::SubscriptionsController < ApiController
  2. before_action :set_account
  3. respond_to :txt
  4. def show
  5. if @account.subscription(api_subscription_url(@account.id)).valid?(params['hub.topic'])
  6. @account.update(subscription_expires_at: Time.now.utc + (params['hub.lease_seconds'] || 86_400).to_i.seconds)
  7. render plain: HTMLEntities.new.encode(params['hub.challenge']), status: 200
  8. else
  9. head 404
  10. end
  11. end
  12. def update
  13. body = request.body.read
  14. subscription = @account.subscription(api_subscription_url(@account.id))
  15. if subscription.verify(body, request.headers['HTTP_X_HUB_SIGNATURE'])
  16. ProcessingWorker.perform_async(@account.id, body.force_encoding('UTF-8'))
  17. head 201
  18. else
  19. head 202
  20. end
  21. end
  22. private
  23. def set_account
  24. @account = Account.find(params[:id])
  25. end
  26. end