Skip to content

Commit e139f0e

Browse files
committed
Add documentation
1 parent 3338363 commit e139f0e

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

Sources/Twift+Media.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension Twift {
1313
return try await finalizeUpload(mediaKey: initializeResponse.mediaIdString)
1414
}
1515

16-
/// Allows the user to provide additional information about the uploaded `mediaId`. This feature is currently only supported for images and GIFs.
16+
/// Allows the user to provide alt text for the `mediaId`. This feature is currently only supported for images and GIFs.
1717
///
1818
/// Usage:
1919
/// 1. Upload media using the `upload(mediaData)` method
@@ -53,6 +53,9 @@ extension Twift {
5353
}
5454
}
5555

56+
/// Checks to see whether the `mediaId` has finished processing successfully. This method will wait for the `GET /1.1/media/upload.json?command=STATUS` endpoint to return either `succeeded` or `failed`; for large videos, this may take some time.
57+
/// - Parameter mediaId: The media ID to check the upload status of
58+
/// - Returns: A `Bool` indicating whether the media has uploaded successfully (`true`) or not (`false`).
5659
public func checkMediaUploadSuccessful(_ mediaId: Media.ID) async throws -> Bool {
5760
var urlComponents = baseMediaURLComponents()
5861
urlComponents.queryItems = [
@@ -217,29 +220,62 @@ fileprivate struct MediaInitResponse: Codable {
217220
let expiresAfterSecs: Int
218221
}
219222

223+
/// A response object containing information about the uploaded media
220224
public struct MediaUploadResponse: Codable {
225+
/// The uploaded media's unique Integer ID
221226
public let mediaId: Int
227+
228+
/// The uploaded media's ID represented as a `String`. The string representation of the ID is preferred for ensuring precision.
222229
public let mediaIdString: String
230+
231+
/// The size of the uploaded media
223232
public let size: Int?
233+
234+
/// When this media upload will expire, if not attached to a Tweet
224235
public let expiresAfterSecs: Int?
236+
237+
/// Information about the media's processing status. Most images are processed instantly, but large gifs and videos may take longer to process before they can be used in a Tweet.
238+
///
239+
/// Use the ``Twift.checkMediaUploadSuccessful()`` method to wait until the media is successfully processed.
225240
public let processingInfo: MediaProcessingInfo?
226241

242+
/// An object containing information about the media's processing status.
227243
public struct MediaProcessingInfo: Codable {
244+
/// The current processing state of the media
228245
public let state: State
246+
247+
/// How many seconds the user is advised to wait before checking the status of the media again
229248
public let checkAfterSecs: Int?
249+
250+
/// The percent completion of the media processing
230251
public let progressPercent: Int?
252+
253+
/// Any errors that caused the media processing to fail
231254
public let error: ProcessingError?
232255

233256
public enum State: String, Codable {
257+
/// The media is queued to be processed
234258
case pending
259+
260+
/// The media is currently being processed
235261
case inProgress = "in_progress"
262+
263+
/// The media could not be processed
236264
case failed
265+
266+
/// The media was successfully processed and is ready to be attached to a Tweet
237267
case succeeded
238268
}
239269

270+
/// An error associated with media processing
240271
public struct ProcessingError: Codable {
272+
/// The status code for this error
241273
public let code: Int
274+
275+
/// The name of the error
242276
public let name: String
277+
278+
/// A longer description of the processing error
243279
public let message: String?
244280
}
245281
}

0 commit comments

Comments
 (0)