Add syndication commands

This commit is contained in:
2023-01-29 11:47:47 +11:00
parent 01549d344f
commit 8c4fae3df5
4 changed files with 69 additions and 2 deletions

View File

@@ -12,13 +12,15 @@ module Adamantium
create_resolver: "commands.posts.creation_resolver",
delete_post: "commands.posts.delete",
undelete_post: "commands.posts.undelete",
update_post: "commands.posts.update"
update_post: "commands.posts.update",
syndicate: "commands.posts.syndicate"
]
def handle(req, res)
req_entity = post_param_parser.call(params: req.params.to_h)
action = req.params[:action]
# delete, undelete, update
if action
operation, permission_check = resolve_operation(action)
@@ -28,13 +30,16 @@ module Adamantium
else
res.status = 401
end
elsif req_entity
elsif req_entity # create
halt 401 unless verify_scope(req: req, scope: :create)
command, contract = create_resolver.call(entry_type: req_entity).values_at(:command, :validation)
validation = contract.call(req_entity.to_h)
if validation.success?
url = syndicate(validation.to_h) # TODO: set URL on post
post = command.call(validation.to_h)
res.status = 201

View File

@@ -0,0 +1,15 @@
module Adamantium
module Commands
module Posts
class Syndicate
include Deps["settings", "syndication.mastodon"]
def call(post)
if post.syndicate_to.include settings.mastodon_server
mastodon.call(post: post)
end
end
end
end
end
end