Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 { Response.authenticated($0) }
- .flatMapError { .just(Response.failed($0.reason)) }
- self.credentials = credentials.toObserver()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement