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.
metu.life/app/api/mastodon/ostatus.rb

63 lines
1.5 KiB

9 years ago
module Mastodon
class Ostatus < Grape::API
format :txt
before do
@account = Account.find(params[:id])
end
resource :subscriptions do
helpers do
include ApplicationHelper
9 years ago
end
desc 'Receive updates from an account'
9 years ago
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'])
ProcessFeedService.new.(body, @account)
9 years ago
status 201
else
status 202
end
end
desc 'Confirm PuSH subscription to an account'
9 years ago
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
desc 'Receive Salmon updates targeted to account'
9 years ago
params do
requires :id, type: String, desc: 'Account ID'
end
post ':id' do
ProcessInteractionService.new.(request.body.read, @account)
status 201
9 years ago
end
end
end
end