diff --git a/Sources/APIs/AdvancedAuthenticationAPI.swift b/Sources/APIs/AdvancedAuthenticationAPI.swift index 59b03ca..0c97bb2 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 = ApiVideoUploader.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 = ApiVideoUploader.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 = ApiVideoUploader.basePath + localVariablePath let localVariableParameters = JSONEncodingHelper.encodingParameters(forEncodableObject: authenticatePayload) @@ -67,14 +79,26 @@ open class AdvancedAuthenticationAPI { */ @discardableResult open class func refresh(refreshTokenPayload: RefreshTokenPayload, apiResponseQueue: DispatchQueue = ApiVideoUploader.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 = ApiVideoUploader.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 = ApiVideoUploader.basePath + localVariablePath let localVariableParameters = JSONEncodingHelper.encodingParameters(forEncodableObject: refreshTokenPayload) diff --git a/Sources/APIs/VideosAPI.swift b/Sources/APIs/VideosAPI.swift index ae9038e..39a7d86 100644 --- a/Sources/APIs/VideosAPI.swift +++ b/Sources/APIs/VideosAPI.swift @@ -23,17 +23,31 @@ open class VideosAPI { */ @discardableResult open class func upload(videoId: String, file: URL, onProgressReady: ((Progress) -> Void)? = nil, apiResponseQueue: DispatchQueue = ApiVideoUploader.apiResponseQueue, completion: @escaping ((_ data: Video?, _ error: Error?) -> Void)) throws -> RequestTask { + return try upload(videoId: videoId, file: file, onProgressReady: onProgressReady, apiResponseQueue: apiResponseQueue) { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) + } + } + } + + /** + Upload a video + + - parameter videoId: (path) Enter the videoId you want to use to upload your video. + - parameter file: (form) The path to the video you would like to upload. The path must be local. If you want to use a video from an online source, you must use the \\\"/videos\\\" endpoint and add the \\\"source\\\" parameter when you create a new video. + - parameter onProgressReady: progress handler to receive request progress. + - 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, file: URL, onProgressReady: ((Progress) -> Void)? = nil, apiResponseQueue: DispatchQueue = ApiVideoUploader.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) throws -> RequestTask { if (try file.isMultiChunk) { return try UploadChunkRequestTaskQueue(videoId: videoId, file: file, onProgressReady: onProgressReady, apiResponseQueue: apiResponseQueue, completion: completion) } else { - return uploadWithRequestBuilder(videoId: videoId, file: file, onProgressReady: onProgressReady).execute(apiResponseQueue) { result in - switch result { - case let .success(response): - completion(response.body, nil) - case let .failure(error): - completion(nil, error) - } - } + return uploadWithRequestBuilder(videoId: videoId, file: file, onProgressReady: onProgressReady).execute(apiResponseQueue, completion) } } @@ -77,14 +91,26 @@ open class VideosAPI { uploadPart(file: file, partId: partId, isLastPart: true, onProgressReady: onProgressReady, apiResponseQueue: apiResponseQueue, completion: completion) } - public func uploadPart(file: URL, partId: Int, isLastPart: Bool, onProgressReady: ((Progress) -> Void)? = nil, apiResponseQueue: DispatchQueue = ApiVideoUploader.apiResponseQueue, completion: @escaping ((_ data: Video?, _ error: Error?) -> Void)) -> RequestTask { + public func uploadPart(file: URL, partId: Int, isLastPart: Bool, onProgressReady: ((Progress) -> Void)? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping ((_ data: Video?, _ error: Error?) -> Void)) -> RequestTask { + let requestTask = uploadPart(file: file, partId: partId, isLastPart: isLastPart, onProgressReady: onProgressReady, completion: { result in + switch result { + case let .success(response): + completion(response.body, nil) + case let .failure(error): + completion(nil, error) + } + }) + return requestTask + } + + public func uploadPart(file: URL, partId: Int, isLastPart: Bool, onProgressReady: ((Progress) -> Void)? = nil, apiResponseQueue: DispatchQueue = ApiVideoClient.apiResponseQueue, completion: @escaping (_ result: Swift.Result, ErrorResponse>) -> Void) -> RequestTask { var numOfChunks: Int? = nil if (isLastPart) { numOfChunks = partId } let requestBuilder = uploadWithRequestBuilder(videoId: videoId, file: file, chunkId: partId, numOfChunks: numOfChunks, onProgressReady: onProgressReady) - execute(requestBuilder, apiResponseQueue: apiResponseQueue) { data, error in - completion(data, error) + execute(requestBuilder, apiResponseQueue: apiResponseQueue) { result in + completion(result) } return requestBuilder.requestTask } @@ -121,7 +147,7 @@ The latter allows you to split a video source into X chunks and send those chunk - parameter onProgressReady: progress handler to receive request progress. - returns: RequestBuilder