Last active
February 19, 2017 15:53
-
-
Save srdanrasic/a18e066948802aa35fd9a63b935e7d95 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class Authentication { | |
| public typealias Credentials = (username: String, password: String) | |
| public enum Response { | |
| case authenticated(Token) | |
| case failed(String) | |
| } | |
| public let credentials: SafeObserver<Credentials> | |
| public let response: SafeSignal<Response> | |
| public init(client: Client) { | |
| let credentials = SafePublishSubject<Credentials>() | |
| self.response = credentials | |
| .flatMapLatest { username, password in | |
| return client.response(for: API.User.login(username: username, password: password)) | |
| } | |
| .map { .authenticated($0) } | |
| .recover(with: .failed("<message>")) | |
| self.credentials = credentials.toObserver() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment