mirror of
https://github.com/tappollo/WWDC.git
synced 2026-06-11 15:43:45 +08:00
49 lines
1.4 KiB
Swift
49 lines
1.4 KiB
Swift
//
|
|
// SyncEngine.swift
|
|
// WWDC
|
|
//
|
|
// Created by Guilherme Rambo on 22/04/17.
|
|
// Copyright © 2017 Guilherme Rambo. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import RxSwift
|
|
|
|
extension Notification.Name {
|
|
public static let SyncEngineDidSyncSessionsAndSchedule = Notification.Name("SyncEngineDidSyncSessionsAndSchedule")
|
|
}
|
|
|
|
public final class SyncEngine {
|
|
|
|
public let storage: Storage
|
|
public let client: AppleAPIClient
|
|
|
|
public init(storage: Storage, client: AppleAPIClient) {
|
|
self.storage = storage
|
|
self.client = client
|
|
}
|
|
|
|
public func syncSessionsAndSchedule() {
|
|
client.fetchSessions { [weak self] sessionsResult in
|
|
DispatchQueue.main.async {
|
|
self?.client.fetchSchedule { scheduleResult in
|
|
DispatchQueue.main.async {
|
|
self?.storage.store(sessionsResult: sessionsResult, scheduleResult: scheduleResult) {
|
|
NotificationCenter.default.post(name: .SyncEngineDidSyncSessionsAndSchedule, object: self)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public func syncLiveVideos() {
|
|
client.fetchLiveVideoAssets { [weak self] result in
|
|
DispatchQueue.main.async {
|
|
self?.storage.store(liveVideosResult: result)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|