-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Here we have a good version of the CouchTrackerSync framework
* Only one entry point, the function `setupSyncModule(trakt:)` * To ensure the statement above, the tests run in DEBUG mode without importing the framework using `@testable` * I am using snapshot testing because the JSON is big, there is a lot of data about episodes, seasons and the tv show * I will probrably use the snapshot testing library for screenshot tests... excited for this
- Loading branch information
Pietro Caselani
committed
Jan 8, 2020
1 parent
324aace
commit 955d050
Showing
15 changed files
with
11,740 additions
and
2,986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import TraktSwift | ||
import RxSwift | ||
|
||
func syncWatchedShows(extended: [Extended]) -> Single<[BaseShow]> { | ||
return trakt.sync.rx.request(.watched(type: .shows, extended: extended)).map([BaseShow].self) | ||
} | ||
|
||
func watchedProgress(options: WatchedProgressOptions, showIds: ShowIds) -> Single<BaseShow> { | ||
return trakt.shows.rx.request( | ||
.watchedProgress( | ||
showId: showIds.realId, | ||
hidden: options.countSpecials, | ||
specials: options.countSpecials, | ||
countSpecials: options.countSpecials | ||
) | ||
).map(BaseShow.self) | ||
} | ||
|
||
func seasonsForShow(showIds: ShowIds, extended: [Extended]) -> Single<[Season]> { | ||
return trakt.seasons.rx | ||
.request(.summary(showId: showIds.realId, extended: extended)) | ||
.map([Season].self) | ||
} | ||
|
||
func genresForMoviesAndShows() -> Single<Set<Genre>> { | ||
let genresForType: (GenreType) -> Single<[Genre]> = { type in | ||
trakt.genres.rx.request(.list(type)).map([Genre].self) | ||
} | ||
|
||
return Single.zip(genresForType(.movies), genresForType(.shows)) { (movies, shows) in | ||
Set(movies + shows) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import TraktSwift | ||
|
||
//public func setupSyncModule(createTrakt: () -> TraktSwift) -> Sync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import TraktSwift | ||
|
||
struct ShowDataForSyncing: DataStruct { | ||
let progressShow: BaseShow | ||
let show: TraktSwift.Show | ||
let seasons: [Season] | ||
|
||
var showIds: ShowIds { | ||
return show.ids | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,28 @@ | ||
import TraktSwift | ||
import RxSwift | ||
|
||
private let trakt = Trakt(builder: TraktBuilder { | ||
$0.clientId = Secrets.Trakt.clientId | ||
$0.clientSecret = Secrets.Trakt.clientSecret | ||
$0.redirectURL = Secrets.Trakt.redirectURL | ||
$0.callbackQueue = DispatchQueue(label: "NetworkQueue", qos: .default) | ||
}) | ||
|
||
struct APIEnviront { | ||
public struct SyncEnvironment { | ||
public static let live = SyncEnvironment() | ||
|
||
public var syncWatchedShows: ([Extended]) -> Single<[BaseShow]> = syncWatchedShows(extended:) | ||
public var watchedProgress: (WatchedProgressOptions, ShowIds) -> Single<BaseShow> = watchedProgress(options:showIds:) | ||
public var seasonsForShow: (ShowIds, [Extended]) -> Single<[Season]> = seasonsForShow(showIds:extended:) | ||
public var genres: () -> Single<Set<Genre>> = genresForMoviesAndShows | ||
} | ||
|
||
struct DatabaseEnv { | ||
} | ||
var trakt: Trakt = { badTrakt! }() | ||
|
||
struct SyncEnvironment { | ||
var syncWatchedShows: ([Extended]) -> Observable<[BaseShow]> | ||
var watchedProgress: (WatchedProgressOptions, ShowIds) -> Observable<BaseShow> | ||
var seasonsForShow: (ShowIds, [Extended]) -> Observable<[Season]> | ||
var genres: () -> Observable<Set<Genre>> | ||
} | ||
var badTrakt: Trakt? | ||
|
||
extension SyncEnvironment { | ||
static let live = SyncEnvironment( | ||
syncWatchedShows: syncWatchedShows(extended:), | ||
watchedProgress: watchedProgress(options:showIds:), | ||
seasonsForShow: seasonsForShow(showIds:extended:), | ||
genres: genresForMoviesAndShows | ||
) | ||
public func setupSyncModule(trakt: Trakt) -> (SyncOptions) -> Observable<WatchedShow> { | ||
badTrakt = trakt | ||
return { options in | ||
startSync(options) | ||
} | ||
} | ||
|
||
#if DEBUG | ||
var Current = SyncEnvironment.live | ||
public var Current = SyncEnvironment.live | ||
#else | ||
let Current = SyncEnvironment.live | ||
public let Current = SyncEnvironment.live | ||
#endif | ||
|
||
private func syncWatchedShows(extended: [Extended]) -> Observable<[BaseShow]> { | ||
return trakt.sync.rx.request(.watched(type: .shows, extended: extended)).map([BaseShow].self).asObservable() | ||
} | ||
|
||
private func watchedProgress(options: WatchedProgressOptions, showIds: ShowIds) -> Observable<BaseShow> { | ||
return trakt.shows.rx.request( | ||
.watchedProgress( | ||
showId: showIds.realId, | ||
hidden: options.countSpecials, | ||
specials: options.countSpecials, | ||
countSpecials: options.countSpecials | ||
) | ||
).map(BaseShow.self).asObservable() | ||
} | ||
|
||
private func seasonsForShow(showIds: ShowIds, extended: [Extended]) -> Observable<[Season]> { | ||
return trakt.seasons.rx | ||
.request(.summary(showId: showIds.realId, extended: extended)) | ||
.map([Season].self) | ||
.asObservable() | ||
} | ||
|
||
private func genresForMoviesAndShows() -> Observable<Set<Genre>> { | ||
let genresForType: (GenreType) -> Single<[Genre]> = { type in | ||
trakt.genres.rx.request(.list(type)).map([Genre].self) | ||
} | ||
|
||
return Single.zip(genresForType(.movies), genresForType(.shows)) { (movies, shows) in | ||
Set(movies + shows) | ||
}.asObservable() | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.