Refactor syndication
This commit is contained in:
@@ -5,7 +5,6 @@ module Adamantium
|
||||
module Posts
|
||||
class CreateBookmark < Command
|
||||
include Deps["repos.post_repo",
|
||||
add_post_syndication_source: "commands.posts.add_syndication_source",
|
||||
syndicate: "commands.posts.syndicate"
|
||||
]
|
||||
|
||||
@@ -14,10 +13,7 @@ module Adamantium
|
||||
def call(bookmark)
|
||||
created_bookmark = post_repo.create(bookmark)
|
||||
|
||||
syndicate.call(bookmark).bind do |result|
|
||||
source, url = result
|
||||
add_post_syndication_source.call(created_bookmark.id, source, url)
|
||||
end
|
||||
syndicate.call(created_bookmark.id, bookmark)
|
||||
|
||||
Success(created_bookmark)
|
||||
end
|
||||
|
@@ -9,7 +9,6 @@ module Adamantium
|
||||
renderer: "renderers.markdown",
|
||||
syndicate: "commands.posts.syndicate",
|
||||
send_to_dayone: "syndication.dayone",
|
||||
add_post_syndication_source: "commands.posts.add_syndication_source",
|
||||
send_webmentions: "commands.posts.send_webmentions",
|
||||
]
|
||||
|
||||
@@ -20,13 +19,7 @@ module Adamantium
|
||||
created_post = post_repo.create(post_params)
|
||||
|
||||
send_to_dayone.call(name: post.name, content: post.content) if post[:category].include? "weekly"
|
||||
|
||||
syndicate.call(post).bind do |results|
|
||||
results.each do |result|
|
||||
source, url = result
|
||||
add_post_syndication_source.call(created_post.id, source, url)
|
||||
end
|
||||
end
|
||||
syndicate.call(created_post.id, post)
|
||||
|
||||
# decorated_post = Decorators::Posts::Decorator.new(created_post)
|
||||
|
||||
|
@@ -10,27 +10,24 @@ module Adamantium
|
||||
|
||||
include Deps["settings",
|
||||
"syndication.mastodon",
|
||||
"syndication.pinboard"
|
||||
add_post_syndication_source: "commands.posts.add_syndication_source",
|
||||
send_to_dayone: "syndication.dayone",
|
||||
]
|
||||
|
||||
def call(post)
|
||||
def call(post_id, post)
|
||||
syndicate_to = syndication_targets(post[:syndicate_to])
|
||||
syndicated_to = []
|
||||
|
||||
if syndicate_to.include? :mastodon
|
||||
res = mastodon.call(post: post)
|
||||
|
||||
syndicated_to << [:mastodon, res.value!] if res.success?
|
||||
add_post_syndication_source.call(post_id, :mastodon, res.value!) if res.success?
|
||||
end
|
||||
|
||||
if syndicate_to.include? :pinboard
|
||||
res = pinboard.call(post: post)
|
||||
|
||||
syndicated_to << [:pinboard, res.value!] if res.success?
|
||||
if post[:category].include? "weekly"
|
||||
send_to_dayone.call(name: post.name, content: post.content)
|
||||
end
|
||||
|
||||
return Success(syndicated_to) unless syndicated_to.empty?
|
||||
|
||||
Failure(:no_syndication_targets)
|
||||
Success()
|
||||
end
|
||||
|
||||
private
|
||||
@@ -38,7 +35,6 @@ module Adamantium
|
||||
def syndication_targets(syndicate_to)
|
||||
targets = []
|
||||
targets << :mastodon if syndicate_to.any? { |url| settings.mastodon_server.match(/#{url}/) }
|
||||
targets << :pinboard if syndicate_to.any? { |url| "https://pinboard.in".match(/#{url}/) }
|
||||
targets
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user