Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public class Authentication {
  2.  
  3. public typealias Credentials = (username: String, password: String)
  4.  
  5. public enum Response {
  6. case authenticated(Token)
  7. case failed(String)
  8. }
  9.  
  10. public let credentials: SafeObserver<Credentials>
  11. public let response: SafeSignal<Response>
  12.  
  13. public init(client: Client) {
  14.  
  15. let credentials = SafePublishSubject<Credentials>()
  16.  
  17. self.response = credentials
  18. .flatMapLatest { username, password in
  19. return client.response(for: API.User.login(username: username, password: password))
  20. }
  21. .map { Response.authenticated($0) }
  22. .flatMapError { .just(Response.failed($0.reason)) }
  23.  
  24. self.credentials = credentials.toObserver()
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement