Skip to content

Instantly share code, notes, and snippets.

@rnystrom
Last active December 18, 2015 16:29
Show Gist options
  • Select an option

  • Save rnystrom/5811387 to your computer and use it in GitHub Desktop.

Select an option

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.
- (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