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
830 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. Rails.logger.debug "PuSH confirmation: #{params.inspect}"
  7. @account.update(subscription_expires_at: Time.now + (params['hub.lease_seconds'].to_i).seconds)
  8. render plain: HTMLEntities.new.encode(params['hub.challenge']), status: 200
  9. else
  10. head 404
  11. end
  12. end
  13. def update
  14. body = request.body.read
  15. if @account.subscription(api_subscription_url(@account.id)).verify(body, request.headers['HTTP_X_HUB_SIGNATURE'])
  16. ProcessFeedService.new.(body, @account)
  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