-
Notifications
You must be signed in to change notification settings - Fork 2
/
ChaptersAPI.swift
239 lines (197 loc) · 13.5 KB
/
ChaptersAPI.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
//
// ChaptersAPI.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//
import Foundation
#if canImport(AnyCodable)
import AnyCodable
#endif
open class ChaptersAPI {
/**
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 data and the error objects.
*/
@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)
}
}
}
/**
Upload a chapter
- POST /videos/{videoId}/chapters/{language}
- Upload a VTT file to add chapters to your video. Chapters help break the video into sections. Read our [tutorial](https://api.video/blog/tutorials/adding-chapters-to-your-videos) for more details.
- 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.
- returns: RequestBuilder<Chapter>
*/
open class func uploadWithRequestBuilder(videoId: String, language: String, file: URL) -> RequestBuilder<Chapter> {
var localVariablePath = "/videos/{videoId}/chapters/{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<Chapter>.Type = ApiVideoClient.requestBuilderFactory.getBuilder()
return localVariableRequestBuilder.init(method: "POST", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
}
/**
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 data and the error objects.
*/
@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)
}
}
}
/**
Retrieve a chapter
- GET /videos/{videoId}/chapters/{language}
- Retrieve a chapter for a video in a specific language. Chapters help your viewers find the sections of the video they are most interested in viewing. Tutorials that use the [chapters endpoint](https://api.video/blog/endpoints/chapters).
- 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.
- returns: RequestBuilder<Chapter>
*/
open class func getWithRequestBuilder(videoId: String, language: String) -> RequestBuilder<Chapter> {
var localVariablePath = "/videos/{videoId}/chapters/{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<Chapter>.Type = ApiVideoClient.requestBuilderFactory.getBuilder()
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
}
/**
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 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 chapter
- DELETE /videos/{videoId}/chapters/{language}
- Delete a chapter in a specific language by providing the video ID for the video you want to delete the chapter from and the language the chapter is in.
- 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.
- returns: RequestBuilder<Void>
*/
open class func deleteWithRequestBuilder(videoId: String, language: String) -> RequestBuilder<Void> {
var localVariablePath = "/videos/{videoId}/chapters/{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 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 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: 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)
}
}
}
/**
List video chapters
- GET /videos/{videoId}/chapters
- Retrieve a list of all chapters for a specified video.
- 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)
- returns: RequestBuilder<ChaptersListResponse>
*/
open class func listWithRequestBuilder(videoId: String, currentPage: Int? = nil, pageSize: Int? = nil) -> RequestBuilder<ChaptersListResponse> {
var localVariablePath = "/videos/{videoId}/chapters"
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<ChaptersListResponse>.Type = ApiVideoClient.requestBuilderFactory.getBuilder()
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
}
}