about summary refs log tree commit diff
path: root/app/controllers/api
diff options
context:
space:
mode:
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