Module: Mastodon::REST::Media

Includes:
Utils
Included in:
API
Defined in:
lib/mastodon/rest/media.rb

Instance Method Summary collapse

Methods included from Utils

#array_param, #perform_request, #perform_request_with_collection, #perform_request_with_object

Instance Method Details

#update_media_description(media_id, description) ⇒ Mastodon::Media

Update a media description, can only be updated while it’s not

associated to a status

Parameters:

  • media_id (Integer)

    Id of the media, returned by upload_media

  • description (String)

    A text description of the image, to be along with the image.

Returns:



35
36
37
38
39
# File 'lib/mastodon/rest/media.rb', line 35

def update_media_description(media_id, description)
  perform_request_with_object(:put, "/api/v1/media/#{media_id}",
                              { description: description },
                              Mastodon::Media)
end

#upload_media(file, description = nil) ⇒ Mastodon::Media

Upload a media file

Parameters:

  • file (File, StringIO, HTTP::FormData::File)

    file to upload. Will be converted to HTTP::FormData::File before upload

  • description (String) (defaults to: nil)

    A text description of the image, to be along with the image.

Returns:



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mastodon/rest/media.rb', line 17

def upload_media(file, description = nil)
  file = if file.is_a?(HTTP::FormData::File)
           file
         else
           HTTP::FormData::File.new(file)
         end
  payload = { file: file }
  payload[:description] = description unless description.nil?
  perform_request_with_object(:post, '/api/v1/media', payload,
                              Mastodon::Media)
end