Last active
October 1, 2019 23:56
-
-
Save hassanvfx/11b89759c21dfc6868620ce5cbf24b09 to your computer and use it in GitHub Desktop.
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
import UIKit | |
import RxSwift | |
import Alamofire | |
import AlamofireObjectMapper | |
extension Reactive where Base:APIService{ | |
func call<K:APIResponse>(_ endpoint : APIEndpoints) -> Single<K> { | |
return Single<K>.create { single in | |
let finish:APIClosure<K> = { response in | |
guard let resource = response else { | |
assert(false, "Unexpected response format") | |
single(.error(Services.error.type(.networkFailure))) | |
} | |
DispatchQueue.main.async { | |
single(.success(resource)) | |
} | |
} | |
switch endpoint{ | |
case .getMovie: | |
APIService | |
.get(endpoint,completion: finish as! APIClosure<Movie>) | |
case .getMovieRelated, .getTrendingMovies: | |
APIService | |
.get(endpoint,completion: finish as! APIClosure<APIResponseMovieList>) | |
} | |
return Disposables.create() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment