hometown/app/api/mastodon/ostatus.rb

63 lines
1.5 KiB
Ruby
Raw Normal View History

2016-02-20 21:53:20 +00:00
module Mastodon
class Ostatus < Grape::API
format :txt
before do
@account = Account.find(params[:id])
end
resource :subscriptions do
helpers do
2016-02-22 15:00:20 +00:00
include ApplicationHelper
2016-02-20 21:53:20 +00:00
end
2016-02-22 15:00:20 +00:00
desc 'Receive updates from an account'
2016-02-20 21:53:20 +00:00
params do
requires :id, type: String, desc: 'Account ID'
end
post ':id' do
body = request.body.read
if @account.subscription(subscription_url(@account)).verify(body, env['HTTP_X_HUB_SIGNATURE'])
2016-02-22 15:00:20 +00:00
ProcessFeedService.new.(body, @account)
2016-02-20 21:53:20 +00:00
status 201
else
status 202
end
end
2016-02-22 15:00:20 +00:00
desc 'Confirm PuSH subscription to an account'
2016-02-20 21:53:20 +00:00
params do
requires :id, type: String, desc: 'Account ID'
requires 'hub.topic', type: String, desc: 'Topic URL'
requires 'hub.verify_token', type: String, desc: 'Verification token'
requires 'hub.challenge', type: String, desc: 'Hub challenge'
end
get ':id' do
if @account.subscription(subscription_url(@account)).valid?(params['hub.topic'], params['hub.verify_token'])
params['hub.challenge']
else
error! :not_found, 404
end
end
end
resource :salmon do
2016-02-22 15:00:20 +00:00
desc 'Receive Salmon updates targeted to account'
2016-02-20 21:53:20 +00:00
params do
requires :id, type: String, desc: 'Account ID'
end
post ':id' do
2016-02-22 15:00:20 +00:00
ProcessInteractionService.new.(request.body.read, @account)
status 201
2016-02-20 21:53:20 +00:00
end
end
end
end