Created
June 21, 2013 14:53
-
-
Save rnystrom/5831736 to your computer and use it in GitHub Desktop.
Login to Github and display user info
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.nameLabel, text) = RACAble([GHDataStore sharedStore], client.user.name); | |
| RAC(self.emailLabel, text) = RACAble([GHDataStore sharedStore], client.user.email); | |
| RAC(self.companyLabel, text) = RACAble([GHDataStore sharedStore], client.user.company); | |
| RAC(self.loginLabel, text) = RACAble([GHDataStore sharedStore], client.user.login); | |
| RAC(self.reposLabel, text) = [[RACSignal combineLatest:@[ | |
| RACAble([GHDataStore sharedStore], client.user.publicRepoCount), | |
| RACAble([GHDataStore sharedStore], client.user.privateRepoCount) | |
| ] reduce:^NSString *(NSNumber *public, NSNumber *private) { | |
| NSUInteger total = public.integerValue + private.integerValue; | |
| NSLog(@"%i",total); | |
| if (total > 0) { | |
| return [NSString stringWithFormat:@"%i",total]; | |
| } | |
| return @"No repos"; | |
| }] deliverOn:RACScheduler.mainThreadScheduler]; | |
| [RACAble([GHDataStore sharedStore], client.user.avatarURL) subscribeNext:^(NSURL *url) { | |
| [self.imageView setImageWithURL:url]; | |
| }]; | |
| 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] deliverOn:[RACScheduler mainThreadScheduler]] | |
| subscribeNext:^(OCTUser *fetchedUser) { | |
| [self.activity stopAnimating]; | |
| [[GHDataStore sharedStore] persistUser:fetchedUser withPassword:self.passwordTextField.text]; | |
| } | |
| error:^(NSError *error) { | |
| [self.activity stopAnimating]; | |
| NSLog(@"Fetching error: %@",error.localizedDescription); | |
| }]; | |
| }]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment