2021-06-11 21:11:59 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftyJSON
|
|
|
|
|
2021-06-14 18:05:02 +00:00
|
|
|
final class ChannelVideosProvider: DataProvider {
|
2021-06-11 21:11:59 +00:00
|
|
|
@Published var videos = [Video]()
|
|
|
|
|
|
|
|
var channelID: String? = ""
|
|
|
|
|
|
|
|
func load() {
|
2021-06-14 18:05:02 +00:00
|
|
|
guard channelID != nil else {
|
|
|
|
return
|
|
|
|
}
|
2021-06-11 21:11:59 +00:00
|
|
|
|
|
|
|
let searchPath = "channels/\(channelID!)"
|
|
|
|
DataProvider.request(searchPath).responseJSON { response in
|
|
|
|
switch response.result {
|
|
|
|
case let .success(value):
|
|
|
|
if let channelVideos = JSON(value).dictionaryValue["latestVideos"] {
|
|
|
|
self.videos = channelVideos.arrayValue.map { Video($0) }
|
|
|
|
}
|
|
|
|
case let .failure(error):
|
|
|
|
print(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|