about summary refs log tree commit diff
path: root/app/controllers/api
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-02-29 19:42:08 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-02-29 19:42:08 +0100
commit0e8f59c16fcb21301c736ecbc4424cb4c5388c42 (patch)
tree344ac1e0b2d165ba4fe3870f786e854710970ce1 /app/controllers/api
parent11ff92c9d7b27c2c9ed86f649aef8d956cc8b989 (diff)
Refactoring Grape API methods into normal controllers & other things
Diffstat (limited to 'app/controllers/api')
-rw-r--r--app/controllers/api/salmon_controller.rb14
-rw-r--r--app/controllers/api/subscriptions_controller.rb28
2 files changed, 42 insertions, 0 deletions
diff --git a/app/controllers/api/salmon_controller.rb b/app/controllers/api/salmon_controller.rb
new file mode 100644
index 000000000..99ec15bff
--- /dev/null
+++ b/app/controllers/api/salmon_controller.rb
@@ -0,0 +1,14 @@
+class Api::SalmonController < ApplicationController
+  before_action :set_account
+
+  def update
+    ProcessInteractionService.new.(request.body.read, @account)
+    render nothing: true, status: 201
+  end
+
+  private
+
+  def set_account
+    @account = Account.find(params[:id])
+  end
+end
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