From 733b27fc25ea44e58ab49e5f88b308bee0a4f0cf Mon Sep 17 00:00:00 2001 From: ThibaultBee Date: Wed, 24 Apr 2024 09:23:20 +0000 Subject: [PATCH] feat(swift5): add support for rate limit --- README.md | 24 +- Sources/APIs/AdvancedAuthenticationAPI.swift | 56 ++- Sources/APIs/AnalyticsAPI.swift | 66 +++- Sources/APIs/CaptionsAPI.swift | 148 ++++++-- Sources/APIs/ChaptersAPI.swift | 118 ++++-- Sources/APIs/LiveStreamsAPI.swift | 203 ++++++++--- Sources/APIs/PlayerThemesAPI.swift | 202 ++++++++--- Sources/APIs/UploadTokensAPI.swift | 115 ++++-- Sources/APIs/VideosAPI.swift | 341 +++++++++++++----- Sources/APIs/WatermarksAPI.swift | 87 +++-- Sources/APIs/WebhooksAPI.swift | 114 ++++-- Sources/Upload/RequestTaskQueue.swift | 13 +- .../Upload/UploadChunkRequestTaskQueue.swift | 29 +- docs/AdvancedAuthenticationAPI.md | 2 + docs/AnalyticsAPI.md | 2 + docs/CaptionsAPI.md | 5 + docs/ChaptersAPI.md | 4 + docs/LiveStreamsAPI.md | 7 + docs/PlayerThemesAPI.md | 7 + docs/UploadTokensAPI.md | 4 + docs/VideosAPI.md | 10 + docs/WatermarksAPI.md | 3 + docs/WebhooksAPI.md | 4 + 23 files changed, 1145 insertions(+), 419 deletions(-) diff --git a/README.md b/README.md index 882fb7d..5920598 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ import ApiVideoClient // If you rather like to use the sandbox environment: // ApiVideoClient.basePath = Environment.sandbox.rawValue -try VideosAPI.uploadWithUploadToken(token: "MY_VIDEO_TOKEN", file: url) { video, error in +try VideosAPI.uploadWithUploadToken(token: "MY_UPLOAD_TOKEN", file: url) { video, error in if let video = video { // Manage upload with upload token success here } @@ -341,7 +341,27 @@ Method | HTTP request | Description - [WebhooksListResponse](https://github.com/apivideo/api.video-swift-client/blob/main/docs/WebhooksListResponse.md) -### Documentation for Authorization +### Rate limiting + +api.video implements rate limiting to ensure fair usage and stability of the service. The API provides the rate limit values in the response headers for any API requests you make. The /auth endpoint is the only route without rate limitation. + +In this client, you can access these headers by using the methods with the `completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void)` parameters. These methods return both the response body and the headers, allowing you to check the `X-RateLimit-Limit`, `X-RateLimit-Remaining`, and `X-RateLimit-Retry-After` headers to understand your current rate limit status. +Read more about these response headers in the [API reference](https://docs.api.video/reference#limitation). + +```swift +try VideosAPI.uploadWithUploadToken(token: "MY_UPLOAD_TOKEN", file: url) { result in + switch result { + case .success(let response): + print("X-RateLimit-Limit: \(String(describing: response.header["X-RateLimit-Limit"]))") + print("X-RateLimit-Remaining: \(String(describing: response.header["X-RateLimit-Remaining"]))") + print("X-RateLimit-Retry-After: \(String(describing: response.header["X-RateLimit-Retry-After"]))") + case .failure(_): + break + } +} +``` + +### Authorization #### API key diff --git a/Sources/APIs/AdvancedAuthenticationAPI.swift b/Sources/APIs/AdvancedAuthenticationAPI.swift index f38612c..663f790 100644 --- a/Sources/APIs/AdvancedAuthenticationAPI.swift +++ b/Sources/APIs/AdvancedAuthenticationAPI.swift @@ -21,14 +21,26 @@ open class AdvancedAuthenticationAPI { */ @discardableResult open class func authenticate(authenticatePayload: AuthenticatePayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: AccessToken?, _ error: Error?) -> Void)) -> RequestTask { - return authenticateWithRequestBuilder(authenticatePayload: authenticatePayload).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return authenticate(authenticatePayload: authenticatePayload, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Get Bearer Token + + - parameter authenticatePayload: (body) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func authenticate(authenticatePayload: AuthenticatePayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return authenticateWithRequestBuilder(authenticatePayload: authenticatePayload).execute(apiResponseQueue, completion) } @@ -39,7 +51,7 @@ open class AdvancedAuthenticationAPI { - parameter authenticatePayload: (body) - returns: RequestBuilder */ - open class func authenticateWithRequestBuilder(authenticatePayload: AuthenticatePayload) -> RequestBuilder { + internal class func authenticateWithRequestBuilder(authenticatePayload: AuthenticatePayload) -> RequestBuilder { let localVariablePath = "/auth/api-key" let localVariableURLString = ApiVideoClient.basePath + localVariablePath let localVariableParameters = JSONEncodingHelper.encodingParameters(forEncodableObject: authenticatePayload) @@ -67,14 +79,26 @@ open class AdvancedAuthenticationAPI { */ @discardableResult open class func refresh(refreshTokenPayload: RefreshTokenPayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: AccessToken?, _ error: Error?) -> Void)) -> RequestTask { - return refreshWithRequestBuilder(refreshTokenPayload: refreshTokenPayload).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return refresh(refreshTokenPayload: refreshTokenPayload, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Refresh Bearer Token + + - parameter refreshTokenPayload: (body) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func refresh(refreshTokenPayload: RefreshTokenPayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return refreshWithRequestBuilder(refreshTokenPayload: refreshTokenPayload).execute(apiResponseQueue, completion) } @@ -85,7 +109,7 @@ open class AdvancedAuthenticationAPI { - parameter refreshTokenPayload: (body) - returns: RequestBuilder */ - open class func refreshWithRequestBuilder(refreshTokenPayload: RefreshTokenPayload) -> RequestBuilder { + internal class func refreshWithRequestBuilder(refreshTokenPayload: RefreshTokenPayload) -> RequestBuilder { let localVariablePath = "/auth/refresh" let localVariableURLString = ApiVideoClient.basePath + localVariablePath let localVariableParameters = JSONEncodingHelper.encodingParameters(forEncodableObject: refreshTokenPayload) diff --git a/Sources/APIs/AnalyticsAPI.swift b/Sources/APIs/AnalyticsAPI.swift index 34d65e4..c1acaa4 100644 --- a/Sources/APIs/AnalyticsAPI.swift +++ b/Sources/APIs/AnalyticsAPI.swift @@ -38,14 +38,31 @@ open class AnalyticsAPI { */ @discardableResult open class func getLiveStreamsPlays(from: Date, dimension: DimensionGetLiveStreamsPlays, to: Date? = nil, filter: String? = nil, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: AnalyticsPlaysResponse?, _ error: Error?) -> Void)) -> RequestTask { - return getLiveStreamsPlaysWithRequestBuilder(from: from, dimension: dimension, to: to, filter: filter, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return getLiveStreamsPlays(from: from, dimension: dimension, to: to, filter: filter, currentPage: currentPage, pageSize: pageSize, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Get play events for live stream + + - parameter from: (query) Use this query parameter to set the start date for the time period that you want analytics for. - The API returns analytics data including the day you set in `from`. - The date you set must be **within the last 30 days**. - The value you provide must follow the `YYYY-MM-DD` format. + - parameter dimension: (query) Use this query parameter to define the dimension that you want analytics for. - `liveStreamId`: Returns analytics based on the public live stream identifiers. - `emittedAt`: Returns analytics based on the times of the play events. The API returns data in specific interval groups. When the date period you set in `from` and `to` is less than or equals to 2 days, the response for this dimension is grouped in hourly intervals. Otherwise, it is grouped in daily intervals. - `country`: Returns analytics based on the viewers' country. The list of supported country names are based on the [GeoNames public database](https://www.geonames.org/countries/). - `deviceType`: Returns analytics based on the type of device used by the viewers during the play event. Possible response values are: `computer`, `phone`, `tablet`, `tv`, `console`, `wearable`, `unknown`. - `operatingSystem`: Returns analytics based on the operating system used by the viewers during the play event. Response values include `windows`, `mac osx`, `android`, `ios`, `linux`. - `browser`: Returns analytics based on the browser used by the viewers during the play event. Response values include `chrome`, `firefox`, `edge`, `opera`. + - parameter to: (query) Use this optional query parameter to set the end date for the time period that you want analytics for. - If you do not specify a `to` date, the API returns analytics data starting from the `from` date up until today, and excluding today. - The date you set must be **within the last 30 days**. - The value you provide must follow the `YYYY-MM-DD` format. (optional) + - parameter filter: (query) Use this query parameter to filter your results to a specific live stream in a project that you want analytics for. You must use the `liveStreamId:` prefix when specifying a live stream ID. (optional) + - parameter currentPage: (query) Choose the number of search results to return per page. Minimum value: 1 (optional, default to 1) + - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func getLiveStreamsPlays(from: Date, dimension: DimensionGetLiveStreamsPlays, to: Date? = nil, filter: String? = nil, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return getLiveStreamsPlaysWithRequestBuilder(from: from, dimension: dimension, to: to, filter: filter, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue, completion) } @@ -62,7 +79,7 @@ open class AnalyticsAPI { - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) - returns: RequestBuilder */ - open class func getLiveStreamsPlaysWithRequestBuilder(from: Date, dimension: DimensionGetLiveStreamsPlays, to: Date? = nil, filter: String? = nil, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { + internal class func getLiveStreamsPlaysWithRequestBuilder(from: Date, dimension: DimensionGetLiveStreamsPlays, to: Date? = nil, filter: String? = nil, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { let localVariablePath = "/analytics/live-streams/plays" let localVariableURLString = ApiVideoClient.basePath + localVariablePath let localVariableParameters: [String: Any]? = nil @@ -115,14 +132,31 @@ open class AnalyticsAPI { */ @discardableResult open class func getVideosPlays(from: Date, dimension: DimensionGetVideosPlays, to: Date? = nil, filter: String? = nil, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: AnalyticsPlaysResponse?, _ error: Error?) -> Void)) -> RequestTask { - return getVideosPlaysWithRequestBuilder(from: from, dimension: dimension, to: to, filter: filter, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return getVideosPlays(from: from, dimension: dimension, to: to, filter: filter, currentPage: currentPage, pageSize: pageSize, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Get play events for video + + - parameter from: (query) Use this query parameter to set the start date for the time period that you want analytics for. - The API returns analytics data including the day you set in `from`. - The date you set must be **within the last 30 days**. - The value you provide must follow the `YYYY-MM-DD` format. + - parameter dimension: (query) Use this query parameter to define the dimension that you want analytics for. - `videoId`: Returns analytics based on the public video identifiers. - `emittedAt`: Returns analytics based on the times of the play events. The API returns data in specific interval groups. When the date period you set in `from` and `to` is less than or equals to 2 days, the response for this dimension is grouped in hourly intervals. Otherwise, it is grouped in daily intervals. - `country`: Returns analytics based on the viewers' country. The list of supported country names are based on the [GeoNames public database](https://www.geonames.org/countries/). - `deviceType`: Returns analytics based on the type of device used by the viewers during the play event. Possible response values are: `computer`, `phone`, `tablet`, `tv`, `console`, `wearable`, `unknown`. - `operatingSystem`: Returns analytics based on the operating system used by the viewers during the play event. Response values include `windows`, `mac osx`, `android`, `ios`, `linux`. - `browser`: Returns analytics based on the browser used by the viewers during the play event. Response values include `chrome`, `firefox`, `edge`, `opera`. + - parameter to: (query) Use this optional query parameter to set the end date for the time period that you want analytics for. - If you do not specify a `to` date, the API returns analytics data starting from the `from` date up until today, and excluding today. - The date you set must be **within the last 30 days**. - The value you provide must follow the `YYYY-MM-DD` format. (optional) + - parameter filter: (query) Use this query parameter to filter your results to a specific video in a project that you want analytics for. You must use the `videoId:` prefix when specifying a video ID. (optional) + - parameter currentPage: (query) Choose the number of search results to return per page. Minimum value: 1 (optional, default to 1) + - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func getVideosPlays(from: Date, dimension: DimensionGetVideosPlays, to: Date? = nil, filter: String? = nil, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return getVideosPlaysWithRequestBuilder(from: from, dimension: dimension, to: to, filter: filter, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue, completion) } @@ -139,7 +173,7 @@ open class AnalyticsAPI { - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) - returns: RequestBuilder */ - open class func getVideosPlaysWithRequestBuilder(from: Date, dimension: DimensionGetVideosPlays, to: Date? = nil, filter: String? = nil, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { + internal class func getVideosPlaysWithRequestBuilder(from: Date, dimension: DimensionGetVideosPlays, to: Date? = nil, filter: String? = nil, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { let localVariablePath = "/analytics/videos/plays" let localVariableURLString = ApiVideoClient.basePath + localVariablePath let localVariableParameters: [String: Any]? = nil diff --git a/Sources/APIs/CaptionsAPI.swift b/Sources/APIs/CaptionsAPI.swift index 80a6534..251f94a 100644 --- a/Sources/APIs/CaptionsAPI.swift +++ b/Sources/APIs/CaptionsAPI.swift @@ -23,14 +23,28 @@ open class CaptionsAPI { */ @discardableResult open class func upload(videoId: String, language: String, file: URL, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Caption?, _ error: Error?) -> Void)) -> RequestTask { - return uploadWithRequestBuilder(videoId: videoId, language: language, file: file).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return upload(videoId: videoId, language: language, file: file, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Upload a caption + + - parameter videoId: (path) The unique identifier for the video you want to add a caption to. + - parameter language: (path) A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). + - parameter file: (form) The video text track (VTT) you want to upload. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func upload(videoId: String, language: String, file: URL, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return uploadWithRequestBuilder(videoId: videoId, language: language, file: file).execute(apiResponseQueue, completion) } @@ -44,7 +58,7 @@ open class CaptionsAPI { - parameter file: (form) The video text track (VTT) you want to upload. - returns: RequestBuilder */ - open class func uploadWithRequestBuilder(videoId: String, language: String, file: URL) -> RequestBuilder { + internal class func uploadWithRequestBuilder(videoId: String, language: String, file: URL) -> RequestBuilder { var localVariablePath = "/videos/{videoId}/captions/{language}" let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))" let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -83,14 +97,27 @@ open class CaptionsAPI { */ @discardableResult open class func get(videoId: String, language: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Caption?, _ error: Error?) -> Void)) -> RequestTask { - return getWithRequestBuilder(videoId: videoId, language: language).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return get(videoId: videoId, language: language, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Retrieve a caption + + - parameter videoId: (path) The unique identifier for the video you want captions for. + - parameter language: (path) A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func get(videoId: String, language: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return getWithRequestBuilder(videoId: videoId, language: language).execute(apiResponseQueue, completion) } @@ -105,7 +132,7 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt - parameter language: (path) A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). - returns: RequestBuilder */ - open class func getWithRequestBuilder(videoId: String, language: String) -> RequestBuilder { + internal class func getWithRequestBuilder(videoId: String, language: String) -> RequestBuilder { var localVariablePath = "/videos/{videoId}/captions/{language}" let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))" let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -141,14 +168,28 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt */ @discardableResult open class func update(videoId: String, language: String, captionsUpdatePayload: CaptionsUpdatePayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Caption?, _ error: Error?) -> Void)) -> RequestTask { - return updateWithRequestBuilder(videoId: videoId, language: language, captionsUpdatePayload: captionsUpdatePayload).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return update(videoId: videoId, language: language, captionsUpdatePayload: captionsUpdatePayload, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Update a caption + + - parameter videoId: (path) The unique identifier for the video you want to have automatic captions for. + - parameter language: (path) A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). + - parameter captionsUpdatePayload: (body) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func update(videoId: String, language: String, captionsUpdatePayload: CaptionsUpdatePayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return updateWithRequestBuilder(videoId: videoId, language: language, captionsUpdatePayload: captionsUpdatePayload).execute(apiResponseQueue, completion) } @@ -162,7 +203,7 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt - parameter captionsUpdatePayload: (body) - returns: RequestBuilder */ - open class func updateWithRequestBuilder(videoId: String, language: String, captionsUpdatePayload: CaptionsUpdatePayload) -> RequestBuilder { + internal class func updateWithRequestBuilder(videoId: String, language: String, captionsUpdatePayload: CaptionsUpdatePayload) -> RequestBuilder { var localVariablePath = "/videos/{videoId}/captions/{language}" let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))" let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -197,14 +238,27 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt */ @discardableResult open class func delete(videoId: String, language: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { - return deleteWithRequestBuilder(videoId: videoId, language: language).execute(apiResponseQueue) { result in - switch result { - case .success: - completion((), nil) - case let .failure(error): - completion(nil, error) - } + return delete(videoId: videoId, language: language, apiResponseQueue: apiResponseQueue) { result in + switch result { + case .success: + completion((), nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Delete a caption + + - parameter videoId: (path) The unique identifier for the video you want to delete a caption from. + - parameter language: (path) A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func delete(videoId: String, language: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return deleteWithRequestBuilder(videoId: videoId, language: language).execute(apiResponseQueue, completion) } @@ -217,7 +271,7 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt - parameter language: (path) A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). - returns: RequestBuilder */ - open class func deleteWithRequestBuilder(videoId: String, language: String) -> RequestBuilder { + internal class func deleteWithRequestBuilder(videoId: String, language: String) -> RequestBuilder { var localVariablePath = "/videos/{videoId}/captions/{language}" let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))" let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -253,14 +307,28 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt */ @discardableResult open class func list(videoId: String, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: CaptionsListResponse?, _ error: Error?) -> Void)) -> RequestTask { - return listWithRequestBuilder(videoId: videoId, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return list(videoId: videoId, currentPage: currentPage, pageSize: pageSize, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + List video captions + + - parameter videoId: (path) The unique identifier for the video you want to retrieve a list of captions for. + - parameter currentPage: (query) Choose the number of search results to return per page. Minimum value: 1 (optional, default to 1) + - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func list(videoId: String, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return listWithRequestBuilder(videoId: videoId, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue, completion) } @@ -274,7 +342,7 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) - returns: RequestBuilder */ - open class func listWithRequestBuilder(videoId: String, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { + internal class func listWithRequestBuilder(videoId: String, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { var localVariablePath = "/videos/{videoId}/captions" let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))" let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" diff --git a/Sources/APIs/ChaptersAPI.swift b/Sources/APIs/ChaptersAPI.swift index f202b4f..a0af0de 100644 --- a/Sources/APIs/ChaptersAPI.swift +++ b/Sources/APIs/ChaptersAPI.swift @@ -23,14 +23,28 @@ open class ChaptersAPI { */ @discardableResult open class func upload(videoId: String, language: String, file: URL, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Chapter?, _ error: Error?) -> Void)) -> RequestTask { - return uploadWithRequestBuilder(videoId: videoId, language: language, file: file).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return upload(videoId: videoId, language: language, file: file, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Upload a chapter + + - parameter videoId: (path) The unique identifier for the video you want to upload a chapter for. + - parameter language: (path) A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation. + - parameter file: (form) The VTT file describing the chapters you want to upload. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func upload(videoId: String, language: String, file: URL, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return uploadWithRequestBuilder(videoId: videoId, language: language, file: file).execute(apiResponseQueue, completion) } @@ -44,7 +58,7 @@ open class ChaptersAPI { - parameter file: (form) The VTT file describing the chapters you want to upload. - returns: RequestBuilder */ - open class func uploadWithRequestBuilder(videoId: String, language: String, file: URL) -> RequestBuilder { + internal class func uploadWithRequestBuilder(videoId: String, language: String, file: URL) -> RequestBuilder { var localVariablePath = "/videos/{videoId}/chapters/{language}" let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))" let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -83,14 +97,27 @@ open class ChaptersAPI { */ @discardableResult open class func get(videoId: String, language: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Chapter?, _ error: Error?) -> Void)) -> RequestTask { - return getWithRequestBuilder(videoId: videoId, language: language).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return get(videoId: videoId, language: language, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Retrieve a chapter + + - parameter videoId: (path) The unique identifier for the video you want to show a chapter for. + - parameter language: (path) A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func get(videoId: String, language: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return getWithRequestBuilder(videoId: videoId, language: language).execute(apiResponseQueue, completion) } @@ -103,7 +130,7 @@ open class ChaptersAPI { - parameter language: (path) A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation. - returns: RequestBuilder */ - open class func getWithRequestBuilder(videoId: String, language: String) -> RequestBuilder { + internal class func getWithRequestBuilder(videoId: String, language: String) -> RequestBuilder { var localVariablePath = "/videos/{videoId}/chapters/{language}" let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))" let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -138,14 +165,27 @@ open class ChaptersAPI { */ @discardableResult open class func delete(videoId: String, language: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { - return deleteWithRequestBuilder(videoId: videoId, language: language).execute(apiResponseQueue) { result in - switch result { - case .success: - completion((), nil) - case let .failure(error): - completion(nil, error) - } + return delete(videoId: videoId, language: language, apiResponseQueue: apiResponseQueue) { result in + switch result { + case .success: + completion((), nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Delete a chapter + + - parameter videoId: (path) The unique identifier for the video you want to delete a chapter from. + - parameter language: (path) A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func delete(videoId: String, language: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return deleteWithRequestBuilder(videoId: videoId, language: language).execute(apiResponseQueue, completion) } @@ -158,7 +198,7 @@ open class ChaptersAPI { - parameter language: (path) A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation. - returns: RequestBuilder */ - open class func deleteWithRequestBuilder(videoId: String, language: String) -> RequestBuilder { + internal class func deleteWithRequestBuilder(videoId: String, language: String) -> RequestBuilder { var localVariablePath = "/videos/{videoId}/chapters/{language}" let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))" let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -194,14 +234,28 @@ open class ChaptersAPI { */ @discardableResult open class func list(videoId: String, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: ChaptersListResponse?, _ error: Error?) -> Void)) -> RequestTask { - return listWithRequestBuilder(videoId: videoId, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return list(videoId: videoId, currentPage: currentPage, pageSize: pageSize, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + List video chapters + + - parameter videoId: (path) The unique identifier for the video you want to retrieve a list of chapters for. + - parameter currentPage: (query) Choose the number of search results to return per page. Minimum value: 1 (optional, default to 1) + - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func list(videoId: String, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return listWithRequestBuilder(videoId: videoId, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue, completion) } @@ -215,7 +269,7 @@ open class ChaptersAPI { - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) - returns: RequestBuilder */ - open class func listWithRequestBuilder(videoId: String, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { + internal class func listWithRequestBuilder(videoId: String, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { var localVariablePath = "/videos/{videoId}/chapters" let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))" let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" diff --git a/Sources/APIs/LiveStreamsAPI.swift b/Sources/APIs/LiveStreamsAPI.swift index 14c0caf..e7f763a 100644 --- a/Sources/APIs/LiveStreamsAPI.swift +++ b/Sources/APIs/LiveStreamsAPI.swift @@ -21,14 +21,26 @@ open class LiveStreamsAPI { */ @discardableResult open class func create(liveStreamCreationPayload: LiveStreamCreationPayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: LiveStream?, _ error: Error?) -> Void)) -> RequestTask { - return createWithRequestBuilder(liveStreamCreationPayload: liveStreamCreationPayload).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return create(liveStreamCreationPayload: liveStreamCreationPayload, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Create live stream + + - parameter liveStreamCreationPayload: (body) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func create(liveStreamCreationPayload: LiveStreamCreationPayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return createWithRequestBuilder(liveStreamCreationPayload: liveStreamCreationPayload).execute(apiResponseQueue, completion) } @@ -40,7 +52,7 @@ open class LiveStreamsAPI { - parameter liveStreamCreationPayload: (body) - returns: RequestBuilder */ - open class func createWithRequestBuilder(liveStreamCreationPayload: LiveStreamCreationPayload) -> RequestBuilder { + internal class func createWithRequestBuilder(liveStreamCreationPayload: LiveStreamCreationPayload) -> RequestBuilder { let localVariablePath = "/live-streams" let localVariableURLString = ApiVideoClient.basePath + localVariablePath let localVariableParameters = JSONEncodingHelper.encodingParameters(forEncodableObject: liveStreamCreationPayload) @@ -68,14 +80,26 @@ open class LiveStreamsAPI { */ @discardableResult open class func get(liveStreamId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: LiveStream?, _ error: Error?) -> Void)) -> RequestTask { - return getWithRequestBuilder(liveStreamId: liveStreamId).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return get(liveStreamId: liveStreamId, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Retrieve live stream + + - parameter liveStreamId: (path) The unique ID for the live stream you want to watch. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func get(liveStreamId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return getWithRequestBuilder(liveStreamId: liveStreamId).execute(apiResponseQueue, completion) } @@ -87,7 +111,7 @@ open class LiveStreamsAPI { - parameter liveStreamId: (path) The unique ID for the live stream you want to watch. - returns: RequestBuilder */ - open class func getWithRequestBuilder(liveStreamId: String) -> RequestBuilder { + internal class func getWithRequestBuilder(liveStreamId: String) -> RequestBuilder { var localVariablePath = "/live-streams/{liveStreamId}" let liveStreamIdPreEscape = "\(APIHelper.mapValueToPathItem(liveStreamId))" let liveStreamIdPostEscape = liveStreamIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -119,14 +143,27 @@ open class LiveStreamsAPI { */ @discardableResult open class func update(liveStreamId: String, liveStreamUpdatePayload: LiveStreamUpdatePayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: LiveStream?, _ error: Error?) -> Void)) -> RequestTask { - return updateWithRequestBuilder(liveStreamId: liveStreamId, liveStreamUpdatePayload: liveStreamUpdatePayload).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return update(liveStreamId: liveStreamId, liveStreamUpdatePayload: liveStreamUpdatePayload, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Update a live stream + + - parameter liveStreamId: (path) The unique ID for the live stream that you want to update information for such as player details. + - parameter liveStreamUpdatePayload: (body) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func update(liveStreamId: String, liveStreamUpdatePayload: LiveStreamUpdatePayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return updateWithRequestBuilder(liveStreamId: liveStreamId, liveStreamUpdatePayload: liveStreamUpdatePayload).execute(apiResponseQueue, completion) } @@ -139,7 +176,7 @@ open class LiveStreamsAPI { - parameter liveStreamUpdatePayload: (body) - returns: RequestBuilder */ - open class func updateWithRequestBuilder(liveStreamId: String, liveStreamUpdatePayload: LiveStreamUpdatePayload) -> RequestBuilder { + internal class func updateWithRequestBuilder(liveStreamId: String, liveStreamUpdatePayload: LiveStreamUpdatePayload) -> RequestBuilder { var localVariablePath = "/live-streams/{liveStreamId}" let liveStreamIdPreEscape = "\(APIHelper.mapValueToPathItem(liveStreamId))" let liveStreamIdPostEscape = liveStreamIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -170,14 +207,26 @@ open class LiveStreamsAPI { */ @discardableResult open class func delete(liveStreamId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { - return deleteWithRequestBuilder(liveStreamId: liveStreamId).execute(apiResponseQueue) { result in - switch result { - case .success: - completion((), nil) - case let .failure(error): - completion(nil, error) - } + return delete(liveStreamId: liveStreamId, apiResponseQueue: apiResponseQueue) { result in + switch result { + case .success: + completion((), nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Delete a live stream + + - parameter liveStreamId: (path) The unique ID for the live stream that you want to remove. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func delete(liveStreamId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return deleteWithRequestBuilder(liveStreamId: liveStreamId).execute(apiResponseQueue, completion) } @@ -189,7 +238,7 @@ open class LiveStreamsAPI { - parameter liveStreamId: (path) The unique ID for the live stream that you want to remove. - returns: RequestBuilder */ - open class func deleteWithRequestBuilder(liveStreamId: String) -> RequestBuilder { + internal class func deleteWithRequestBuilder(liveStreamId: String) -> RequestBuilder { var localVariablePath = "/live-streams/{liveStreamId}" let liveStreamIdPreEscape = "\(APIHelper.mapValueToPathItem(liveStreamId))" let liveStreamIdPostEscape = liveStreamIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -242,14 +291,31 @@ open class LiveStreamsAPI { */ @discardableResult open class func list(streamKey: String? = nil, name: String? = nil, sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: LiveStreamListResponse?, _ error: Error?) -> Void)) -> RequestTask { - return listWithRequestBuilder(streamKey: streamKey, name: name, sortBy: sortBy, sortOrder: sortOrder, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return list(streamKey: streamKey, name: name, sortBy: sortBy, sortOrder: sortOrder, currentPage: currentPage, pageSize: pageSize, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + List all live streams + + - parameter streamKey: (query) The unique stream key that allows you to stream videos. (optional) + - parameter name: (query) You can filter live streams by their name or a part of their name. (optional) + - parameter sortBy: (query) Enables you to sort live stream results. Allowed attributes: `name`, `createdAt`, `updatedAt`. `name` - the name of the live stream. `createdAt` - the time a live stream was created. `updatedAt` - the time a live stream was last updated. When using `createdAt` or `updatedAt`, the API sorts the results based on the ISO-8601 time format. (optional) + - parameter sortOrder: (query) Allowed: asc, desc. Ascending for date and time means that earlier values precede later ones. Descending means that later values preced earlier ones. For title, it is 0-9 and A-Z ascending and Z-A, 9-0 descending. (optional) + - parameter currentPage: (query) Choose the number of search results to return per page. Minimum value: 1 (optional, default to 1) + - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func list(streamKey: String? = nil, name: String? = nil, sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return listWithRequestBuilder(streamKey: streamKey, name: name, sortBy: sortBy, sortOrder: sortOrder, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue, completion) } @@ -266,7 +332,7 @@ open class LiveStreamsAPI { - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) - returns: RequestBuilder */ - open class func listWithRequestBuilder(streamKey: String? = nil, name: String? = nil, sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { + internal class func listWithRequestBuilder(streamKey: String? = nil, name: String? = nil, sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { let localVariablePath = "/live-streams" let localVariableURLString = ApiVideoClient.basePath + localVariablePath let localVariableParameters: [String: Any]? = nil @@ -303,14 +369,27 @@ open class LiveStreamsAPI { */ @discardableResult open class func uploadThumbnail(liveStreamId: String, file: URL, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: LiveStream?, _ error: Error?) -> Void)) -> RequestTask { - return uploadThumbnailWithRequestBuilder(liveStreamId: liveStreamId, file: file).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return uploadThumbnail(liveStreamId: liveStreamId, file: file, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Upload a thumbnail + + - parameter liveStreamId: (path) The unique ID for the live stream you want to upload. + - parameter file: (form) The image to be added as a thumbnail. The mime type should be image/jpeg, image/png or image/webp. The max allowed size is 8 MiB. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func uploadThumbnail(liveStreamId: String, file: URL, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return uploadThumbnailWithRequestBuilder(liveStreamId: liveStreamId, file: file).execute(apiResponseQueue, completion) } @@ -323,7 +402,7 @@ open class LiveStreamsAPI { - parameter file: (form) The image to be added as a thumbnail. The mime type should be image/jpeg, image/png or image/webp. The max allowed size is 8 MiB. - returns: RequestBuilder */ - open class func uploadThumbnailWithRequestBuilder(liveStreamId: String, file: URL) -> RequestBuilder { + internal class func uploadThumbnailWithRequestBuilder(liveStreamId: String, file: URL) -> RequestBuilder { var localVariablePath = "/live-streams/{liveStreamId}/thumbnail" let liveStreamIdPreEscape = "\(APIHelper.mapValueToPathItem(liveStreamId))" let liveStreamIdPostEscape = liveStreamIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -358,14 +437,26 @@ open class LiveStreamsAPI { */ @discardableResult open class func deleteThumbnail(liveStreamId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: LiveStream?, _ error: Error?) -> Void)) -> RequestTask { - return deleteThumbnailWithRequestBuilder(liveStreamId: liveStreamId).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return deleteThumbnail(liveStreamId: liveStreamId, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Delete a thumbnail + + - parameter liveStreamId: (path) The unique identifier of the live stream whose thumbnail you want to delete. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func deleteThumbnail(liveStreamId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return deleteThumbnailWithRequestBuilder(liveStreamId: liveStreamId).execute(apiResponseQueue, completion) } @@ -377,7 +468,7 @@ open class LiveStreamsAPI { - parameter liveStreamId: (path) The unique identifier of the live stream whose thumbnail you want to delete. - returns: RequestBuilder */ - open class func deleteThumbnailWithRequestBuilder(liveStreamId: String) -> RequestBuilder { + internal class func deleteThumbnailWithRequestBuilder(liveStreamId: String) -> RequestBuilder { var localVariablePath = "/live-streams/{liveStreamId}/thumbnail" let liveStreamIdPreEscape = "\(APIHelper.mapValueToPathItem(liveStreamId))" let liveStreamIdPostEscape = liveStreamIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" diff --git a/Sources/APIs/PlayerThemesAPI.swift b/Sources/APIs/PlayerThemesAPI.swift index 2117c95..c0c103a 100644 --- a/Sources/APIs/PlayerThemesAPI.swift +++ b/Sources/APIs/PlayerThemesAPI.swift @@ -21,14 +21,26 @@ open class PlayerThemesAPI { */ @discardableResult open class func create(playerThemeCreationPayload: PlayerThemeCreationPayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: PlayerTheme?, _ error: Error?) -> Void)) -> RequestTask { - return createWithRequestBuilder(playerThemeCreationPayload: playerThemeCreationPayload).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return create(playerThemeCreationPayload: playerThemeCreationPayload, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Create a player + + - parameter playerThemeCreationPayload: (body) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func create(playerThemeCreationPayload: PlayerThemeCreationPayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return createWithRequestBuilder(playerThemeCreationPayload: playerThemeCreationPayload).execute(apiResponseQueue, completion) } @@ -40,7 +52,7 @@ open class PlayerThemesAPI { - parameter playerThemeCreationPayload: (body) - returns: RequestBuilder */ - open class func createWithRequestBuilder(playerThemeCreationPayload: PlayerThemeCreationPayload) -> RequestBuilder { + internal class func createWithRequestBuilder(playerThemeCreationPayload: PlayerThemeCreationPayload) -> RequestBuilder { let localVariablePath = "/players" let localVariableURLString = ApiVideoClient.basePath + localVariablePath let localVariableParameters = JSONEncodingHelper.encodingParameters(forEncodableObject: playerThemeCreationPayload) @@ -68,14 +80,26 @@ open class PlayerThemesAPI { */ @discardableResult open class func get(playerId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: PlayerTheme?, _ error: Error?) -> Void)) -> RequestTask { - return getWithRequestBuilder(playerId: playerId).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return get(playerId: playerId, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Retrieve a player + + - parameter playerId: (path) The unique identifier for the player you want to retrieve. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func get(playerId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return getWithRequestBuilder(playerId: playerId).execute(apiResponseQueue, completion) } @@ -87,7 +111,7 @@ open class PlayerThemesAPI { - parameter playerId: (path) The unique identifier for the player you want to retrieve. - returns: RequestBuilder */ - open class func getWithRequestBuilder(playerId: String) -> RequestBuilder { + internal class func getWithRequestBuilder(playerId: String) -> RequestBuilder { var localVariablePath = "/players/{playerId}" let playerIdPreEscape = "\(APIHelper.mapValueToPathItem(playerId))" let playerIdPostEscape = playerIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -119,14 +143,27 @@ open class PlayerThemesAPI { */ @discardableResult open class func update(playerId: String, playerThemeUpdatePayload: PlayerThemeUpdatePayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: PlayerTheme?, _ error: Error?) -> Void)) -> RequestTask { - return updateWithRequestBuilder(playerId: playerId, playerThemeUpdatePayload: playerThemeUpdatePayload).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return update(playerId: playerId, playerThemeUpdatePayload: playerThemeUpdatePayload, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Update a player + + - parameter playerId: (path) The unique identifier for the player. + - parameter playerThemeUpdatePayload: (body) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func update(playerId: String, playerThemeUpdatePayload: PlayerThemeUpdatePayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return updateWithRequestBuilder(playerId: playerId, playerThemeUpdatePayload: playerThemeUpdatePayload).execute(apiResponseQueue, completion) } @@ -139,7 +176,7 @@ open class PlayerThemesAPI { - parameter playerThemeUpdatePayload: (body) - returns: RequestBuilder */ - open class func updateWithRequestBuilder(playerId: String, playerThemeUpdatePayload: PlayerThemeUpdatePayload) -> RequestBuilder { + internal class func updateWithRequestBuilder(playerId: String, playerThemeUpdatePayload: PlayerThemeUpdatePayload) -> RequestBuilder { var localVariablePath = "/players/{playerId}" let playerIdPreEscape = "\(APIHelper.mapValueToPathItem(playerId))" let playerIdPostEscape = playerIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -170,14 +207,26 @@ open class PlayerThemesAPI { */ @discardableResult open class func delete(playerId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { - return deleteWithRequestBuilder(playerId: playerId).execute(apiResponseQueue) { result in - switch result { - case .success: - completion((), nil) - case let .failure(error): - completion(nil, error) - } + return delete(playerId: playerId, apiResponseQueue: apiResponseQueue) { result in + switch result { + case .success: + completion((), nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Delete a player + + - parameter playerId: (path) The unique identifier for the player you want to delete. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func delete(playerId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return deleteWithRequestBuilder(playerId: playerId).execute(apiResponseQueue, completion) } @@ -189,7 +238,7 @@ open class PlayerThemesAPI { - parameter playerId: (path) The unique identifier for the player you want to delete. - returns: RequestBuilder */ - open class func deleteWithRequestBuilder(playerId: String) -> RequestBuilder { + internal class func deleteWithRequestBuilder(playerId: String) -> RequestBuilder { var localVariablePath = "/players/{playerId}" let playerIdPreEscape = "\(APIHelper.mapValueToPathItem(playerId))" let playerIdPostEscape = playerIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -240,14 +289,29 @@ open class PlayerThemesAPI { */ @discardableResult open class func list(sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: PlayerThemesListResponse?, _ error: Error?) -> Void)) -> RequestTask { - return listWithRequestBuilder(sortBy: sortBy, sortOrder: sortOrder, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return list(sortBy: sortBy, sortOrder: sortOrder, currentPage: currentPage, pageSize: pageSize, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + List all player themes + + - parameter sortBy: (query) createdAt is the time the player was created. updatedAt is the time the player was last updated. The time is presented in ISO-8601 format. (optional) + - parameter sortOrder: (query) Allowed: asc, desc. Ascending for date and time means that earlier values precede later ones. Descending means that later values preced earlier ones. (optional) + - parameter currentPage: (query) Choose the number of search results to return per page. Minimum value: 1 (optional, default to 1) + - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func list(sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return listWithRequestBuilder(sortBy: sortBy, sortOrder: sortOrder, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue, completion) } @@ -262,7 +326,7 @@ open class PlayerThemesAPI { - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) - returns: RequestBuilder */ - open class func listWithRequestBuilder(sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { + internal class func listWithRequestBuilder(sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { let localVariablePath = "/players" let localVariableURLString = ApiVideoClient.basePath + localVariablePath let localVariableParameters: [String: Any]? = nil @@ -298,14 +362,28 @@ open class PlayerThemesAPI { */ @discardableResult open class func uploadLogo(playerId: String, file: URL, link: String? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: PlayerTheme?, _ error: Error?) -> Void)) -> RequestTask { - return uploadLogoWithRequestBuilder(playerId: playerId, file: file, link: link).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return uploadLogo(playerId: playerId, file: file, link: link, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Upload a logo + + - parameter playerId: (path) The unique identifier for the player. + - parameter file: (form) The name of the file you want to use for your logo. + - parameter link: (form) A public link that you want to advertise in your player. For example, you could add a link to your company. When a viewer clicks on your logo, they will be taken to this address. (optional) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func uploadLogo(playerId: String, file: URL, link: String? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return uploadLogoWithRequestBuilder(playerId: playerId, file: file, link: link).execute(apiResponseQueue, completion) } @@ -319,7 +397,7 @@ open class PlayerThemesAPI { - parameter link: (form) A public link that you want to advertise in your player. For example, you could add a link to your company. When a viewer clicks on your logo, they will be taken to this address. (optional) - returns: RequestBuilder */ - open class func uploadLogoWithRequestBuilder(playerId: String, file: URL, link: String? = nil) -> RequestBuilder { + internal class func uploadLogoWithRequestBuilder(playerId: String, file: URL, link: String? = nil) -> RequestBuilder { var localVariablePath = "/players/{playerId}/logo" let playerIdPreEscape = "\(APIHelper.mapValueToPathItem(playerId))" let playerIdPostEscape = playerIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -355,14 +433,26 @@ open class PlayerThemesAPI { */ @discardableResult open class func deleteLogo(playerId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { - return deleteLogoWithRequestBuilder(playerId: playerId).execute(apiResponseQueue) { result in - switch result { - case .success: - completion((), nil) - case let .failure(error): - completion(nil, error) - } + return deleteLogo(playerId: playerId, apiResponseQueue: apiResponseQueue) { result in + switch result { + case .success: + completion((), nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Delete logo + + - parameter playerId: (path) The unique identifier for the player. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func deleteLogo(playerId: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return deleteLogoWithRequestBuilder(playerId: playerId).execute(apiResponseQueue, completion) } @@ -374,7 +464,7 @@ open class PlayerThemesAPI { - parameter playerId: (path) The unique identifier for the player. - returns: RequestBuilder */ - open class func deleteLogoWithRequestBuilder(playerId: String) -> RequestBuilder { + internal class func deleteLogoWithRequestBuilder(playerId: String) -> RequestBuilder { var localVariablePath = "/players/{playerId}/logo" let playerIdPreEscape = "\(APIHelper.mapValueToPathItem(playerId))" let playerIdPostEscape = playerIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" diff --git a/Sources/APIs/UploadTokensAPI.swift b/Sources/APIs/UploadTokensAPI.swift index d8e6e42..5d88299 100644 --- a/Sources/APIs/UploadTokensAPI.swift +++ b/Sources/APIs/UploadTokensAPI.swift @@ -21,14 +21,26 @@ open class UploadTokensAPI { */ @discardableResult open class func createToken(tokenCreationPayload: TokenCreationPayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: UploadToken?, _ error: Error?) -> Void)) -> RequestTask { - return createTokenWithRequestBuilder(tokenCreationPayload: tokenCreationPayload).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return createToken(tokenCreationPayload: tokenCreationPayload, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Generate an upload token + + - parameter tokenCreationPayload: (body) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func createToken(tokenCreationPayload: TokenCreationPayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return createTokenWithRequestBuilder(tokenCreationPayload: tokenCreationPayload).execute(apiResponseQueue, completion) } @@ -40,7 +52,7 @@ open class UploadTokensAPI { - parameter tokenCreationPayload: (body) - returns: RequestBuilder */ - open class func createTokenWithRequestBuilder(tokenCreationPayload: TokenCreationPayload) -> RequestBuilder { + internal class func createTokenWithRequestBuilder(tokenCreationPayload: TokenCreationPayload) -> RequestBuilder { let localVariablePath = "/upload-tokens" let localVariableURLString = ApiVideoClient.basePath + localVariablePath let localVariableParameters = JSONEncodingHelper.encodingParameters(forEncodableObject: tokenCreationPayload) @@ -68,14 +80,26 @@ open class UploadTokensAPI { */ @discardableResult open class func getToken(uploadToken: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: UploadToken?, _ error: Error?) -> Void)) -> RequestTask { - return getTokenWithRequestBuilder(uploadToken: uploadToken).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return getToken(uploadToken: uploadToken, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Retrieve upload token + + - parameter uploadToken: (path) The unique identifier for the token you want information about. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func getToken(uploadToken: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return getTokenWithRequestBuilder(uploadToken: uploadToken).execute(apiResponseQueue, completion) } @@ -87,7 +111,7 @@ open class UploadTokensAPI { - parameter uploadToken: (path) The unique identifier for the token you want information about. - returns: RequestBuilder */ - open class func getTokenWithRequestBuilder(uploadToken: String) -> RequestBuilder { + internal class func getTokenWithRequestBuilder(uploadToken: String) -> RequestBuilder { var localVariablePath = "/upload-tokens/{uploadToken}" let uploadTokenPreEscape = "\(APIHelper.mapValueToPathItem(uploadToken))" let uploadTokenPostEscape = uploadTokenPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -118,14 +142,26 @@ open class UploadTokensAPI { */ @discardableResult open class func deleteToken(uploadToken: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { - return deleteTokenWithRequestBuilder(uploadToken: uploadToken).execute(apiResponseQueue) { result in - switch result { - case .success: - completion((), nil) - case let .failure(error): - completion(nil, error) - } + return deleteToken(uploadToken: uploadToken, apiResponseQueue: apiResponseQueue) { result in + switch result { + case .success: + completion((), nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Delete an upload token + + - parameter uploadToken: (path) The unique identifier for the upload token you want to delete. Deleting a token will make it so the token can no longer be used for authentication. + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func deleteToken(uploadToken: String, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return deleteTokenWithRequestBuilder(uploadToken: uploadToken).execute(apiResponseQueue, completion) } @@ -137,7 +173,7 @@ open class UploadTokensAPI { - parameter uploadToken: (path) The unique identifier for the upload token you want to delete. Deleting a token will make it so the token can no longer be used for authentication. - returns: RequestBuilder */ - open class func deleteTokenWithRequestBuilder(uploadToken: String) -> RequestBuilder { + internal class func deleteTokenWithRequestBuilder(uploadToken: String) -> RequestBuilder { var localVariablePath = "/upload-tokens/{uploadToken}" let uploadTokenPreEscape = "\(APIHelper.mapValueToPathItem(uploadToken))" let uploadTokenPostEscape = uploadTokenPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" @@ -187,14 +223,29 @@ open class UploadTokensAPI { */ @discardableResult open class func list(sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: TokenListResponse?, _ error: Error?) -> Void)) -> RequestTask { - return listWithRequestBuilder(sortBy: sortBy, sortOrder: sortOrder, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return list(sortBy: sortBy, sortOrder: sortOrder, currentPage: currentPage, pageSize: pageSize, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + List all active upload tokens + + - parameter sortBy: (query) Allowed: createdAt, ttl. You can use these to sort by when a token was created, or how much longer the token will be active (ttl - time to live). Date and time is presented in ISO-8601 format. (optional) + - parameter sortOrder: (query) Allowed: asc, desc. Ascending is 0-9 or A-Z. Descending is 9-0 or Z-A. (optional) + - parameter currentPage: (query) Choose the number of search results to return per page. Minimum value: 1 (optional, default to 1) + - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func list(sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return listWithRequestBuilder(sortBy: sortBy, sortOrder: sortOrder, currentPage: currentPage, pageSize: pageSize).execute(apiResponseQueue, completion) } @@ -209,7 +260,7 @@ open class UploadTokensAPI { - parameter pageSize: (query) Results per page. Allowed values 1-100, default is 25. (optional, default to 25) - returns: RequestBuilder */ - open class func listWithRequestBuilder(sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { + internal class func listWithRequestBuilder(sortBy: SortByList? = nil, sortOrder: SortOrderList? = nil, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder { let localVariablePath = "/upload-tokens" let localVariableURLString = ApiVideoClient.basePath + localVariablePath let localVariableParameters: [String: Any]? = nil diff --git a/Sources/APIs/VideosAPI.swift b/Sources/APIs/VideosAPI.swift index 150e65d..bff9ec0 100644 --- a/Sources/APIs/VideosAPI.swift +++ b/Sources/APIs/VideosAPI.swift @@ -21,14 +21,26 @@ open class VideosAPI { */ @discardableResult open class func create(videoCreationPayload: VideoCreationPayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Video?, _ error: Error?) -> Void)) -> RequestTask { - return createWithRequestBuilder(videoCreationPayload: videoCreationPayload).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } + return create(videoCreationPayload: videoCreationPayload, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) } + } + } + + /** + Create a video object + + - parameter videoCreationPayload: (body) video to create + - parameter apiResponseQueue: The queue on which api response is dispatched. + - parameter completion: completion handler to receive the result of the request (incl. headers). + */ + @discardableResult + open class func create(videoCreationPayload: VideoCreationPayload, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { + return createWithRequestBuilder(videoCreationPayload: videoCreationPayload).execute(apiResponseQueue, completion) } @@ -40,7 +52,7 @@ open class VideosAPI { - parameter videoCreationPayload: (body) video to create - returns: RequestBuilder