Skip to content

Instantly share code, notes, and snippets.

@srdanrasic
Last active February 19, 2017 15:53
Show Gist options
  • Select an option

  • Save srdanrasic/a18e066948802aa35fd9a63b935e7d95 to your computer and use it in GitHub Desktop.

Select an option

Save srdanrasic/a18e066948802aa35fd9a63b935e7d95 to your computer and use it in GitHub Desktop.
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