Last active
December 18, 2015 16:29
-
-
Save rnystrom/5811387 to your computer and use it in GitHub Desktop.
Example of logging into Github and getting user info using ReactiveCocoa and Octokit.
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
| - (void)viewDidLoad { | |
| [super viewDidLoad]; | |
| RAC(self.loginButton, enabled) = [RACSignal combineLatest:@[ | |
| self.usernameTextField.rac_textSignal, | |
| self.passwordTextField.rac_textSignal] | |
| reduce:^(NSString *username, NSString *password) { | |
| return @([username length] > 0 && [password length] > 0); | |
| }]; | |
| [[self.loginButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(UIButton *sender) { | |
| [self.activity startAnimating]; | |
| OCTUser *user = [OCTUser userWithLogin:self.usernameTextField.text server:OCTServer.dotComServer]; | |
| OCTClient *client = [OCTClient authenticatedClientWithUser:user password:self.passwordTextField.text]; | |
| [[client fetchUserInfo] subscribeNext:^(OCTUser *fetchedUser) { | |
| self.emailLabel.text = fetchedUser.email; | |
| } error:^(NSError *error) { | |
| NSLog(@"Fetching error: %@",error.localizedDescription); | |
| } completed:^{ | |
| [self.activity stopAnimating]; | |
| }]; | |
| }]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment