Adjust mastodon syndication format
This commit is contained in:
@@ -14,17 +14,18 @@ module Adamantium
|
|||||||
return Failure(:no_mastodon_credentials)
|
return Failure(:no_mastodon_credentials)
|
||||||
end
|
end
|
||||||
|
|
||||||
text = (post[:name] != "") ? post[:name] : post[:content]
|
content = if post[:name]
|
||||||
text_with_link = "#{text} — #{settings.micropub_site_url}/post/#{post[:slug]}"
|
"#{post[:name]} — #{settings.micropub_site_url}/post/#{post[:slug]}"
|
||||||
tags = post[:category].map { |tag| "##{tag}" }.join(" ")
|
else
|
||||||
text_with_tags = "#{text_with_link} #{tags}"
|
post[:content]
|
||||||
|
end
|
||||||
|
|
||||||
|
text_with_tags = "#{content} #{tags}"
|
||||||
|
|
||||||
key = Digest::MD5.hexdigest text_with_tags
|
key = Digest::MD5.hexdigest text_with_tags
|
||||||
mastodon_token = settings.mastodon_token
|
mastodon_token = settings.mastodon_token
|
||||||
mastodon_server = settings.mastodon_server.split("@").first
|
mastodon_server = settings.mastodon_server.split("@").first
|
||||||
|
|
||||||
logger.info("Syndicating to: #{mastodon_server}api/v1/statuses")
|
|
||||||
|
|
||||||
response = HTTParty.post("#{mastodon_server}api/v1/statuses", {
|
response = HTTParty.post("#{mastodon_server}api/v1/statuses", {
|
||||||
headers: {
|
headers: {
|
||||||
"Idempotency-Key": key,
|
"Idempotency-Key": key,
|
||||||
@@ -37,7 +38,6 @@ module Adamantium
|
|||||||
|
|
||||||
if response.code >= 200 && response.code < 300
|
if response.code >= 200 && response.code < 300
|
||||||
status = JSON.parse(response.body, symbolize_names: true)
|
status = JSON.parse(response.body, symbolize_names: true)
|
||||||
logger.info("Syndicated to Mastodon: #{response.body}")
|
|
||||||
Success("#{mastodon_server}/#{status[:id]}")
|
Success("#{mastodon_server}/#{status[:id]}")
|
||||||
else
|
else
|
||||||
logger.info("Failed to syndicate to Mastodon: #{response.message}")
|
logger.info("Failed to syndicate to Mastodon: #{response.message}")
|
||||||
|
Reference in New Issue
Block a user