From 0e8f59c16fcb21301c736ecbc4424cb4c5388c42 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 29 Feb 2016 19:42:08 +0100 Subject: Refactoring Grape API methods into normal controllers & other things --- app/controllers/api/subscriptions_controller.rb | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 app/controllers/api/subscriptions_controller.rb (limited to 'app/controllers/api/subscriptions_controller.rb') diff --git a/app/controllers/api/subscriptions_controller.rb b/app/controllers/api/subscriptions_controller.rb new file mode 100644 index 000000000..56deae10c --- /dev/null +++ b/app/controllers/api/subscriptions_controller.rb @@ -0,0 +1,28 @@ +class Api::SubscriptionsController < ApplicationController + before_action :set_account + + def show + if @account.subscription(api_subscription_url(@account.id)).valid?(params['hub.topic'], params['hub.verify_token']) + render text: params['hub.challenge'], status: 200 + else + render nothing: true, status: 404 + end + end + + def update + body = request.body.read + + if @account.subscription(api_subscription_url(@account.id)).verify(body, env['HTTP_X_HUB_SIGNATURE']) + ProcessFeedService.new.(body, @account) + render nothing: true, status: 201 + else + render nothing: true, status: 202 + end + end + + private + + def set_account + @account = Account.find(params[:id]) + end +end -- cgit