From db5185659a1fa07bc15aa98e5d4933b5ba3802d9 Mon Sep 17 00:00:00 2001 From: Nicholas Galasso Date: Sun, 3 Nov 2024 20:39:09 -0500 Subject: [PATCH] Allow setting alt_text for uploaded media --- lib/x/media_uploader.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/x/media_uploader.rb b/lib/x/media_uploader.rb index f6c6bc9..cdf6b56 100644 --- a/lib/x/media_uploader.rb +++ b/lib/x/media_uploader.rb @@ -45,6 +45,13 @@ def await_processing(client:, media:) end end + def set_alt_text(client:, media_id:, alt_text:) + post_body = "{ \"media_id\" : \"#{media_id}\", \"alt_text\" : { \"text\" : \"#{alt_text}\" } }" + headers = {"Content-Type" => "application/json"} + upload_client = client.dup.tap { |c| c.base_url = "https://upload.twitter.com/1.1/" } + upload_client.post("media/metadata/create.json", post_body, headers:) + end + private def validate!(file_path:, media_category:)