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.

62 lines
1.5 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. module Mastodon
  2. class Ostatus < Grape::API
  3. format :txt
  4. before do
  5. @account = Account.find(params[:id])
  6. end
  7. resource :subscriptions do
  8. helpers do
  9. include ApplicationHelper
  10. end
  11. desc 'Receive updates from an account'
  12. params do
  13. requires :id, type: String, desc: 'Account ID'
  14. end
  15. post ':id' do
  16. body = request.body.read
  17. if @account.subscription(subscription_url(@account)).verify(body, env['HTTP_X_HUB_SIGNATURE'])
  18. ProcessFeedService.new.(body, @account)
  19. status 201
  20. else
  21. status 202
  22. end
  23. end
  24. desc 'Confirm PuSH subscription to an account'
  25. params do
  26. requires :id, type: String, desc: 'Account ID'
  27. requires 'hub.topic', type: String, desc: 'Topic URL'
  28. requires 'hub.verify_token', type: String, desc: 'Verification token'
  29. requires 'hub.challenge', type: String, desc: 'Hub challenge'
  30. end
  31. get ':id' do
  32. if @account.subscription(subscription_url(@account)).valid?(params['hub.topic'], params['hub.verify_token'])
  33. params['hub.challenge']
  34. else
  35. error! :not_found, 404
  36. end
  37. end
  38. end
  39. resource :salmon do
  40. desc 'Receive Salmon updates targeted to account'
  41. params do
  42. requires :id, type: String, desc: 'Account ID'
  43. end
  44. post ':id' do
  45. ProcessInteractionService.new.(request.body.read, @account)
  46. status 201
  47. end
  48. end
  49. end
  50. end