The code powering m.abunchtell.com https://m.abunchtell.com
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
794 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'], params['hub.verify_token'])
  6. @account.update(subscription_expires_at: Time.now + (params['hub.lease_seconds'].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. if @account.subscription(api_subscription_url(@account.id)).verify(body, request.headers['HTTP_X_HUB_SIGNATURE'])
  15. ProcessFeedService.new.(body, @account)
  16. head 201
  17. else
  18. head 202
  19. end
  20. end
  21. private
  22. def set_account
  23. @account = Account.find(params[:id])
  24. end
  25. end