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:



38
39
40
41
42
# File 'lib/mastodon/rest/media.rb', line 38

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

#update_media_focus(media_id, focus_x, focus_y) ⇒ Mastodon::Media

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

associated to a status

Parameters:

  • media_id (Integer)

    Id of the media, returned by upload_media

  • focal_x (Float)

    X position of the focus

  • focal_y (Float)

    Y position of the focus

Returns:



50
51
52
53
54
# File 'lib/mastodon/rest/media.rb', line 50

def update_media_focus(media_id, focus_x, focus_y)
  perform_request_with_object(:put, "/api/v1/media/#{media_id}",
                              { focus: "#{focus_x},#{focus_y}" },
                              Mastodon::Media)
end

#upload_media(file, description = nil, *focus) ⇒ 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.

  • focus (Array)

    Array of floats that set the focal point of the image

Returns:



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

def upload_media(file, description = nil, *focus)
  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?
  payload[:focus] = focus.collect{|f| f.to_s}.join(',') unless focus.nil?
  perform_request_with_object(:post, '/api/v1/media', payload,
                              Mastodon::Media)
end