Initial commit
This commit is contained in:
commit
9c4856bdb1
73 changed files with 1393 additions and 0 deletions
8
app/api/mastodon/api.rb
Normal file
8
app/api/mastodon/api.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
module Mastodon
|
||||
class API < Grape::API
|
||||
rescue_from :all
|
||||
|
||||
mount Mastodon::Ostatus
|
||||
mount Mastodon::Rest
|
||||
end
|
||||
end
|
21
app/api/mastodon/entities.rb
Normal file
21
app/api/mastodon/entities.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Mastodon
|
||||
module Entities
|
||||
class Account < Grape::Entity
|
||||
expose :username
|
||||
expose :domain
|
||||
end
|
||||
|
||||
class Status < Grape::Entity
|
||||
format_with(:iso_timestamp) { |dt| dt.iso8601 }
|
||||
|
||||
expose :uri
|
||||
expose :text
|
||||
expose :account, using: Mastodon::Entities::Account
|
||||
|
||||
with_options(format_with: :iso_timestamp) do
|
||||
expose :created_at
|
||||
expose :updated_at
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
63
app/api/mastodon/ostatus.rb
Normal file
63
app/api/mastodon/ostatus.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
module Mastodon
|
||||
class Ostatus < Grape::API
|
||||
format :txt
|
||||
|
||||
before do
|
||||
@account = Account.find(params[:id])
|
||||
end
|
||||
|
||||
resource :subscriptions do
|
||||
helpers do
|
||||
def subscription_url(account)
|
||||
"https://649841dc.ngrok.io/api#{subscriptions_path(id: account.id)}"
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Receive updates from a feed'
|
||||
|
||||
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'])
|
||||
ProcessFeedUpdateService.new.(body, @account)
|
||||
status 201
|
||||
else
|
||||
status 202
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Confirm PuSH subscription to a feed'
|
||||
|
||||
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'
|
||||
|
||||
params do
|
||||
requires :id, type: String, desc: 'Account ID'
|
||||
end
|
||||
|
||||
post ':id' do
|
||||
# todo
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
13
app/api/mastodon/rest.rb
Normal file
13
app/api/mastodon/rest.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
module Mastodon
|
||||
class Rest < Grape::API
|
||||
version 'v1', using: :path
|
||||
format :json
|
||||
|
||||
resource :statuses do
|
||||
desc 'Return a public timeline'
|
||||
get :all do
|
||||
present Status.all, with: Mastodon::Entities::Status
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue