De-syndicate posts

This commit is contained in:
2024-01-30 20:29:51 +11:00
parent 4833ae01c1
commit 6569060ba0
6 changed files with 78 additions and 0 deletions

View File

@@ -78,6 +78,27 @@ module Adamantium
JSON.parse(response.body, symbolize_names: true).fetch(:id, nil)
end
def remove_post(post_id:)
unless settings.mastodon_token && settings.mastodon_server
return Failure(:no_mastodon_credentials)
end
mastodon_token = settings.mastodon_token
mastodon_server = settings.mastodon_server.split("@").first
response = HTTParty.delete("#{mastodon_server}api/v1/statuses/#{post_id}", {
headers: {
"Idempotency-Key": key,
Authorization: "Bearer #{mastodon_token}"
}
})
if response.code >= 200 && response.code < 300
Success(post_id)
else
Failure(response.message)
end
end
private
def sanitze_post(content)

View File

@@ -20,6 +20,16 @@ module Adamantium
Failure(:failed_to_syndicate)
end
end
def de_syndicate(post_id:)
response = mastodon_client.remove_post(post_id: post_id)
if response.success?
Success(response.value!)
else
Failure(:failed_to_de_syndicate)
end
end
end
end
end