Module: X::Uploader::API
- Included in:
- Client
- Defined in:
- x-uploader/lib/x/uploader/api.rb
Overview
The upload methods mixed into a client, each of which calls an uploader with the client
The x gem includes it into X::Client. With x-core and x-uploader alone, include it yourself: X::Client.include(X::Uploader::API). Each method passes the object it is included into to an uploader as its client, which is an X::Client, so it belongs in X::Client or a subclass.
Instance Method Summary collapse
-
#add_alt_text(media, text) ⇒ UploadedMedia
Describe uploaded media with alt text, for people who cannot see it.
-
#add_subtitles(video, subtitles, language_code, **options) ⇒ UploadedMedia
Attach uploaded subtitles to an uploaded video.
-
#await_media_processing(media, **options) ⇒ UploadedMedia
Wait until media has been processed, whether its processing succeeded or failed.
-
#await_media_processing!(media, **options) ⇒ UploadedMedia
Wait until media has been processed, raising if its processing failed.
-
#chunked_upload_media(media, **options) ⇒ UploadedMedia
Upload media in chunks, without waiting for it to be processed.
-
#update_profile_banner(media, **options) ⇒ void
Update the profile banner of the authenticated user from a file.
-
#update_profile_image(media) ⇒ void
Update the profile image of the authenticated user from a file.
-
#upload_media(media, **options) ⇒ UploadedMedia
Upload media and wait for it to be processed.
Instance Method Details
#add_alt_text(media, text) ⇒ UploadedMedia
Describe uploaded media with alt text, for people who cannot see it
209 210 211 |
# File 'x-uploader/lib/x/uploader/api.rb', line 209 def add_alt_text(media, text) Metadata.add_alt_text(media, text, client: _ = self) end |
#add_subtitles(video, subtitles, language_code, **options) ⇒ UploadedMedia
Attach uploaded subtitles to an uploaded video
234 235 236 |
# File 'x-uploader/lib/x/uploader/api.rb', line 234 def add_subtitles(video, subtitles, language_code, **) # steep:ignore DifferentMethodParameterKind Metadata.add_subtitles(video, subtitles, language_code, client: _ = self, **Utils.without_client()) end |
#await_media_processing(media, **options) ⇒ UploadedMedia
Wait until media has been processed, whether its processing succeeded or failed
It returns the status X reported, which failed? tells a failure by, and ready? a success by, since a status in no state X documents is neither; await_media_processing! raises for either instead. Media that already says its processing succeeded or failed, or holds an upload response that names no processing, such as that of an image, is returned as it is, without a request.
167 168 169 |
# File 'x-uploader/lib/x/uploader/api.rb', line 167 def await_media_processing(media, **) # steep:ignore DifferentMethodParameterKind MediaUpload.await_processing(media, client: _ = self, **Utils.without_client()) end |
#await_media_processing!(media, **options) ⇒ UploadedMedia
Wait until media has been processed, raising if its processing failed
190 191 192 |
# File 'x-uploader/lib/x/uploader/api.rb', line 190 def await_media_processing!(media, **) # steep:ignore DifferentMethodParameterKind MediaUpload.await_processing!(media, client: _ = self, **Utils.without_client()) end |
#chunked_upload_media(media, **options) ⇒ UploadedMedia
Upload media in chunks, without waiting for it to be processed
It is the way to upload media without waiting for X to process it: #upload_media waits for the processing of media X processes, such as a video, and this does not. It uploads the media as #upload_media uploads a video, a chunk at a time, but returns once the upload is finalized, so that the caller can go on while X processes a long video, and wait for it with #await_media_processing or #await_media_processing! when it needs it. It uploads in chunks whatever the media, an image as well, and adds no alt text. The chunks are sent by threads of their own, so the on_response of the client runs on those threads for the response of each chunk.
Each chunk is a request a rate limit can refuse, which fails the upload with ChunkedUploadFailed unless the client retries it, which it does only max_rate_limit_retries times, 0 by default, so upload a large video with a client whose max_rate_limit_retries is set, such as X::Client.new(max_rate_limit_retries: 3).
140 141 142 |
# File 'x-uploader/lib/x/uploader/api.rb', line 140 def chunked_upload_media(media, **) # steep:ignore DifferentMethodParameterKind MediaUpload.chunked_upload(media, client: _ = self, **Utils.without_client()) end |
#update_profile_banner(media, **options) ⇒ void
This method returns an undefined value.
Update the profile banner of the authenticated user from a file
272 273 274 |
# File 'x-uploader/lib/x/uploader/api.rb', line 272 def (media, **) # steep:ignore DifferentMethodParameterKind Account.(media, client: _ = self, **Utils.without_client()) end |
#update_profile_image(media) ⇒ void
This method returns an undefined value.
Update the profile image of the authenticated user from a file
249 250 251 |
# File 'x-uploader/lib/x/uploader/api.rb', line 249 def update_profile_image(media) Account.update_profile_image(media, client: _ = self) end |
#upload_media(media, **options) ⇒ UploadedMedia
Upload media and wait for it to be processed
The media is a path, or an IO open on it. Media given as a String or a Pathname is read from the file it names, and media given as a File or a Tempfile through that IO, a chunk at a time, so media of any size uploads without being held in memory; media given as any other IO, such as a StringIO, is read to its end and held.
A video or subtitles upload in chunks, which send their media type, as a single request does not. The media category is inferred from the bytes the media begins with, or else from the name of its file, unless media_category says what it is. The chunks are sent by threads of their own, so the on_response of the client runs on those threads for the response of each chunk.
An image, and a GIF that a single request takes, upload in a single request, which takes no chunks and no media type, so chunk_size, concurrency, and media_type are ignored for them: a chunk_size or a concurrency that is not valid still raises, but none is sent. Media given shared: true uploads in chunks, and uses all three.
Each chunk is a request a rate limit can refuse, which fails the upload with ChunkedUploadFailed unless the client retries it, which it does only max_rate_limit_retries times, 0 by default, so upload a large video with a client whose max_rate_limit_retries is set, such as X::Client.new(max_rate_limit_retries: 3).
89 90 91 |
# File 'x-uploader/lib/x/uploader/api.rb', line 89 def upload_media(media, **) # steep:ignore DifferentMethodParameterKind MediaUpload.upload(media, client: _ = self, **Utils.without_client()) end |