GitHub PullRequestReviewCommentEvent at 2014-01-18 01:54:23
Repository: thingshub
Actor: cdzombak
Payload: {"comment":{"url":"https://api.github.com/repos/cdzombak/thingshub/pulls/comments/8985851","id":8985851,"diff_hunk":"@@ -22,69 +22,61 @@ - (BOOL)cdz_isGithubTwoFactorAuthRequiredError;\n \n @implementation CDZGithubAuthManager\n \n-+ (void)authenticatedClient:(void(^)(OCTClient *authenticatedClient, NSError *error))completionBlock forUsername:(NSString *)githubLogin {\n++ (RACSignal *)authenticatedClientForUsername:(NSString *)githubLogin {\n     NSParameterAssert(githubLogin);\n-    \n-    completionBlock = ^(OCTClient *client, NSError *error) {\n-        if (client && !error) {\n+\n+    [OCTClient setClientID:CDZThingsHubGithubClientID clientSecret:CDZThingsHubGithubClientSecret];\n+    OCTUser *user = [OCTUser userWithLogin:githubLogin server:OCTServer.dotComServer];\n+    NSString *storedToken = [SSKeychain passwordForService:CDZThingsHubKeychainServiceName account:githubLogin];\n+\n+    return [[[[RACSignal\n+        defer:^RACSignal *{\n+            if (storedToken) {\n+                return [RACSignal return:[OCTClient authenticatedClientWithUser:user token:storedToken]];\n+            }\n+            return [self authenticatedClientForUser:user];\n+        }]\n+        doNext:^(OCTClient *client) {\n             NSError *keychainError;\n-            BOOL success = [SSKeychain setPassword:client.token forService:CDZThingsHubKeychainServiceName account:client.user.login error:&keychainError];\n+            BOOL success = [SSKeychain setPassword:client.token\n+                                        forService:CDZThingsHubKeychainServiceName\n+                                           account:client.user.login\n+                                             error:&keychainError];\n             if (!success) {\n                 CDZCLILog(@\"Failed saving token into keychain: %@\", keychainError);\n             }\n-        }\n-        \n-        if (completionBlock) completionBlock(client, error);\n-    };\n-    \n-    [OCTClient setClientID:CDZThingsHubGithubClientID clientSecret:CDZThingsHubGithubClientSecret];\n-    OCTUser *user = [OCTUser userWithLogin:githubLogin server:OCTServer.dotComServer];\n-    \n-    NSString *storedToken = [SSKeychain passwordForService:CDZThingsHubKeychainServiceName account:githubLogin];\n-    \n-    if (storedToken) {\n-        OCTClient *client = [OCTClient authenticatedClientWithUser:user token:storedToken];\n-        completionBlock(client, nil);\n-    } else {\n-        [self attemptAuthFlowWithUser:user completion:completionBlock];\n-    }\n+        }]\n+   \t\treplayLazily]","path":"thingshub/CDZGithubAuthManager.m","position":49,"original_position":49,"commit_id":"64e055e8a57921bd9de56ac08423a08b00df0c0e","original_commit_id":"64e055e8a57921bd9de56ac08423a08b00df0c0e","user":{"login":"cdzombak","id":102904,"avatar_url":"https://gravatar.com/avatar/41cb878902c4207dacf61c7e8b602627?d=https%3A%2F%2Fidenticons.github.com%2F4bd1fb2dd3279549a4a351d40b271b0e.png&r=x","gravatar_id":"41cb878902c4207dacf61c7e8b602627","url":"https://api.github.com/users/cdzombak","html_url":"https://github.com/cdzombak","followers_url":"https://api.github.com/users/cdzombak/followers","following_url":"https://api.github.com/users/cdzombak/following{/other_user}","gists_url":"https://api.github.com/users/cdzombak/gists{/gist_id}","starred_url":"https://api.github.com/users/cdzombak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdzombak/subscriptions","organizations_url":"https://api.github.com/users/cdzombak/orgs","repos_url":"https://api.github.com/users/cdzombak/repos","events_url":"https://api.github.com/users/cdzombak/events{/privacy}","received_events_url":"https://api.github.com/users/cdzombak/received_events","type":"User","site_admin":false},"body":"@andrewsardone \r\n\r\nSo, to clarify: `-replayLazily` takes care of creating a multicast connection for the signal, so we don't duplicate side effects. It uses `-defer:` internally so as not to execute the underlying signal as soon as you call `replayLazily`.\r\n\r\n`defer` above, on line `33`, just ensures that we don't actually trigger login as soon as we create that signal — effectively transforming the hot signal there into a cold one.\r\n\r\n(right?)","created_at":"2014-01-18T01:54:23Z","updated_at":"2014-01-18T01:54:23Z","html_url":"https://github.com/cdzombak/thingshub/pull/1#discussion_r8985851","pull_request_url":"https://api.github.com/repos/cdzombak/thingshub/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/cdzombak/thingshub/pulls/comments/8985851"},"html":{"href":"https://github.com/cdzombak/thingshub/pull/1#discussion_r8985851"},"pull_request":{"href":"https://api.github.com/repos/cdzombak/thingshub/pulls/1"}}}}