-
Notifications
You must be signed in to change notification settings - Fork 2
/
CaptionsAPI.swift
297 lines (244 loc) · 16.7 KB
/
CaptionsAPI.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
//
// CaptionsAPI.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//
import Foundation
#if canImport(AnyCodable)
import AnyCodable
#endif
open class CaptionsAPI {
/**
Upload a caption
- parameter videoId: (path) The unique identifier for the video you want to add a caption to.
- parameter language: (path) A valid BCP 47 language representation.
- 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 data and the error objects.
*/
@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)
}
}
}
/**
Upload a caption
- POST /videos/{videoId}/captions/{language}
- Upload a VTT file to add captions to your video. Read our [captioning tutorial](https://api.video/blog/tutorials/adding-captions) for more details.
- parameter videoId: (path) The unique identifier for the video you want to add a caption to.
- parameter language: (path) A valid BCP 47 language representation.
- parameter file: (form) The video text track (VTT) you want to upload.
- returns: RequestBuilder<Caption>
*/
open class func uploadWithRequestBuilder(videoId: String, language: String, file: URL) -> RequestBuilder<Caption> {
var localVariablePath = "/videos/{videoId}/captions/{language}"
let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))"
let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
localVariablePath = localVariablePath.replacingOccurrences(of: "{videoId}", with: videoIdPostEscape, options: .literal, range: nil)
let languagePreEscape = "\(APIHelper.mapValueToPathItem(language))"
let languagePostEscape = languagePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
localVariablePath = localVariablePath.replacingOccurrences(of: "{language}", with: languagePostEscape, options: .literal, range: nil)
let localVariableURLString = ApiVideoClient.basePath + localVariablePath
let localVariableFormParams: [String: Any?] = [
"file": file.encodeToJSON(),
]
let localVariableNonNullParameters = APIHelper.rejectNil(localVariableFormParams)
let localVariableParameters = APIHelper.convertBoolToString(localVariableNonNullParameters)
let localVariableUrlComponents = URLComponents(string: localVariableURLString)
let localVariableNillableHeaders: [String: Any?] = [
"Content-Type": "multipart/form-data",
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
let localVariableRequestBuilder: RequestBuilder<Caption>.Type = ApiVideoClient.requestBuilderFactory.getBuilder()
return localVariableRequestBuilder.init(method: "POST", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
}
/**
Retrieve a caption
- parameter videoId: (path) The unique identifier for the video you want captions 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 data and the error objects.
*/
@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)
}
}
}
/**
Retrieve a caption
- GET /videos/{videoId}/captions/{language}
- Retrieve a caption for a video in a specific language. If the language is available, the caption is returned. Otherwise, you will get a error indicating the caption was not found.
Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/captions).
- parameter videoId: (path) The unique identifier for the video you want captions for.
- parameter language: (path) A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation
- returns: RequestBuilder<Caption>
*/
open class func getWithRequestBuilder(videoId: String, language: String) -> RequestBuilder<Caption> {
var localVariablePath = "/videos/{videoId}/captions/{language}"
let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))"
let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
localVariablePath = localVariablePath.replacingOccurrences(of: "{videoId}", with: videoIdPostEscape, options: .literal, range: nil)
let languagePreEscape = "\(APIHelper.mapValueToPathItem(language))"
let languagePostEscape = languagePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
localVariablePath = localVariablePath.replacingOccurrences(of: "{language}", with: languagePostEscape, options: .literal, range: nil)
let localVariableURLString = ApiVideoClient.basePath + localVariablePath
let localVariableParameters: [String: Any]? = nil
let localVariableUrlComponents = URLComponents(string: localVariableURLString)
let localVariableNillableHeaders: [String: Any?] = [
:
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
let localVariableRequestBuilder: RequestBuilder<Caption>.Type = ApiVideoClient.requestBuilderFactory.getBuilder()
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
}
/**
Update a caption
- parameter videoId: (path) The unique identifier for the video you want to have automatic captions for.
- parameter language: (path) A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation.
- parameter captionsUpdatePayload: (body)
- parameter apiResponseQueue: The queue on which api response is dispatched.
- parameter completion: completion handler to receive the data and the error objects.
*/
@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)
}
}
}
/**
Update a caption
- PATCH /videos/{videoId}/captions/{language}
- To have the captions on automatically, use this method to set default: true.
- parameter videoId: (path) The unique identifier for the video you want to have automatic captions for.
- parameter language: (path) A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation.
- parameter captionsUpdatePayload: (body)
- returns: RequestBuilder<Caption>
*/
open class func updateWithRequestBuilder(videoId: String, language: String, captionsUpdatePayload: CaptionsUpdatePayload) -> RequestBuilder<Caption> {
var localVariablePath = "/videos/{videoId}/captions/{language}"
let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))"
let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
localVariablePath = localVariablePath.replacingOccurrences(of: "{videoId}", with: videoIdPostEscape, options: .literal, range: nil)
let languagePreEscape = "\(APIHelper.mapValueToPathItem(language))"
let languagePostEscape = languagePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
localVariablePath = localVariablePath.replacingOccurrences(of: "{language}", with: languagePostEscape, options: .literal, range: nil)
let localVariableURLString = ApiVideoClient.basePath + localVariablePath
let localVariableParameters = JSONEncodingHelper.encodingParameters(forEncodableObject: captionsUpdatePayload)
let localVariableUrlComponents = URLComponents(string: localVariableURLString)
let localVariableNillableHeaders: [String: Any?] = [
:
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
let localVariableRequestBuilder: RequestBuilder<Caption>.Type = ApiVideoClient.requestBuilderFactory.getBuilder()
return localVariableRequestBuilder.init(method: "PATCH", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
}
/**
Delete a caption
- parameter videoId: (path) The unique identifier for the video you want to delete a caption 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 data and the error objects.
*/
@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)
}
}
}
/**
Delete a caption
- DELETE /videos/{videoId}/captions/{language}
- Delete a caption in a specific language by providing the video ID for the video you want to delete the caption from and the language the caption is in.
- parameter videoId: (path) The unique identifier for the video you want to delete a caption from.
- parameter language: (path) A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation.
- returns: RequestBuilder<Void>
*/
open class func deleteWithRequestBuilder(videoId: String, language: String) -> RequestBuilder<Void> {
var localVariablePath = "/videos/{videoId}/captions/{language}"
let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))"
let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
localVariablePath = localVariablePath.replacingOccurrences(of: "{videoId}", with: videoIdPostEscape, options: .literal, range: nil)
let languagePreEscape = "\(APIHelper.mapValueToPathItem(language))"
let languagePostEscape = languagePreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
localVariablePath = localVariablePath.replacingOccurrences(of: "{language}", with: languagePostEscape, options: .literal, range: nil)
let localVariableURLString = ApiVideoClient.basePath + localVariablePath
let localVariableParameters: [String: Any]? = nil
let localVariableUrlComponents = URLComponents(string: localVariableURLString)
let localVariableNillableHeaders: [String: Any?] = [
:
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
let localVariableRequestBuilder: RequestBuilder<Void>.Type = ApiVideoClient.requestBuilderFactory.getNonDecodableBuilder()
return localVariableRequestBuilder.init(method: "DELETE", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
}
/**
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 data and the error objects.
*/
@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)
}
}
}
/**
List video captions
- GET /videos/{videoId}/captions
- Retrieve a list of available captions for the videoId you provide.
- 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)
- returns: RequestBuilder<CaptionsListResponse>
*/
open class func listWithRequestBuilder(videoId: String, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder<CaptionsListResponse> {
var localVariablePath = "/videos/{videoId}/captions"
let videoIdPreEscape = "\(APIHelper.mapValueToPathItem(videoId))"
let videoIdPostEscape = videoIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
localVariablePath = localVariablePath.replacingOccurrences(of: "{videoId}", with: videoIdPostEscape, options: .literal, range: nil)
let localVariableURLString = ApiVideoClient.basePath + localVariablePath
let localVariableParameters: [String: Any]? = nil
var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"currentPage": currentPage?.encodeToJSON(),
"pageSize": pageSize?.encodeToJSON(),
])
let localVariableNillableHeaders: [String: Any?] = [
:
]
let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)
let localVariableRequestBuilder: RequestBuilder<CaptionsListResponse>.Type = ApiVideoClient.requestBuilderFactory.getBuilder()
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
}
}