{"action":"created","comment":{"url":"https://api.github.com/repos/toggl/mobileapp/pulls/comments/124192105","pull_request_review_id":46456304,"id":124192105,"diff_hunk":"@@ -0,0 +1,54 @@\n+﻿using System;\n+using System.Reactive.Linq;\n+using Toggl.Foundation.DataSources;\n+using Toggl.Foundation.Models;\n+using Toggl.Multivac;\n+using Toggl.PrimeRadiant;\n+using Toggl.Ultrawave.Network;\n+\n+namespace Toggl.Foundation.Login\n+{\n+    public interface ILoginManager\n+    {\n+        IObservable<ITogglDataSource> Login(LoginCredentials login);\n+    }\n+\n+    public class LoginManager : ILoginManager\n+    {\n+        public delegate ITogglDatabase DatabaseFactory();\n+\n+        private readonly IApiFactory apiFactory;\n+        private readonly DatabaseFactory databaseFactory;\n+\n+        public LoginManager(IApiFactory apiFactory, DatabaseFactory databaseFactory)\n+        {\n+            Ensure.Argument.IsNotNull(apiFactory, nameof(apiFactory));\n+            Ensure.Argument.IsNotNull(databaseFactory, nameof(databaseFactory));\n+\n+            this.apiFactory = apiFactory;\n+            this.databaseFactory = databaseFactory;\n+        }\n+\n+        public IObservable<ITogglDataSource> Login(LoginCredentials login)\n+        {\n+            Ensure.Argument.IsNotNull(login, nameof(login));\n+\n+            var database = databaseFactory();\n+            var credentials = Credentials.WithPassword(login.Email, login.Password);\n+\n+            return \n+                database\n+                    .Clear()\n+                    .SelectMany(_ => apiFactory.CreateApiWith(credentials).User.Get())\n+                    .Select(User.Clean)","path":"Toggl.Foundation/Login/LoginManager.cs","position":43,"original_position":43,"commit_id":"2a19d7c19fdd66dbcdd274ad72c1ac01ca759249","original_commit_id":"2a19d7c19fdd66dbcdd274ad72c1ac01ca759249","user":{"login":"amulware","id":3987892,"avatar_url":"https://avatars1.githubusercontent.com/u/3987892?v=3","gravatar_id":"","url":"https://api.github.com/users/amulware","html_url":"https://github.com/amulware","followers_url":"https://api.github.com/users/amulware/followers","following_url":"https://api.github.com/users/amulware/following{/other_user}","gists_url":"https://api.github.com/users/amulware/gists{/gist_id}","starred_url":"https://api.github.com/users/amulware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amulware/subscriptions","organizations_url":"https://api.github.com/users/amulware/orgs","repos_url":"https://api.github.com/users/amulware/repos","events_url":"https://api.github.com/users/amulware/events{/privacy}","received_events_url":"https://api.github.com/users/amulware/received_events","type":"User","site_admin":false},"body":"The clean-ness should be tested.","created_at":"2017-06-27T07:02:57Z","updated_at":"2017-06-27T07:15:07Z","html_url":"https://github.com/toggl/mobileapp/pull/235#discussion_r124192105","pull_request_url":"https://api.github.com/repos/toggl/mobileapp/pulls/235","_links":{"self":{"href":"https://api.github.com/repos/toggl/mobileapp/pulls/comments/124192105"},"html":{"href":"https://github.com/toggl/mobileapp/pull/235#discussion_r124192105"},"pull_request":{"href":"https://api.github.com/repos/toggl/mobileapp/pulls/235"}}},"pull_request":{"url":"https://api.github.com/repos/toggl/mobileapp/pulls/235","id":127519963,"html_url":"https://github.com/toggl/mobileapp/pull/235","diff_url":"https://github.com/toggl/mobileapp/pull/235.diff","patch_url":"https://github.com/toggl/mobileapp/pull/235.patch","issue_url":"https://api.github.com/repos/toggl/mobileapp/issues/235","number":235,"state":"open","locked":false,"title":"Use LoginManager to handle authentication","user":{"login":"willsb","id":7688727,"avatar_url":"https://avatars0.githubusercontent.com/u/7688727?v=3","gravatar_id":"","url":"https://api.github.com/users/willsb","html_url":"https://github.com/willsb","followers_url":"https://api.github.com/users/willsb/followers","following_url":"https://api.github.com/users/willsb/following{/other_user}","gists_url":"https://api.github.com/users/willsb/gists{/gist_id}","starred_url":"https://api.github.com/users/willsb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willsb/subscriptions","organizations_url":"https://api.github.com/users/willsb/orgs","repos_url":"https://api.github.com/users/willsb/repos","events_url":"https://api.github.com/users/willsb/events{/privacy}","received_events_url":"https://api.github.com/users/willsb/received_events","type":"User","site_admin":false},"body":"This PR removes the need of many dependency shenanigans that we have to deal right now (like using the Service Locator thrice in order to register a simple item).\r\n\r\nChanges:\r\n\r\n- We now have a LoginManager class\r\n- Dependencies are no longer registered on Start up, but rather when needed\r\n- The data dependencies are singletons now\r\n- No dependency on the ITogglDataSource in order to login\r\n\r\nOnce the whole Login flow is completed, the App class can simply register the singletons on start up using the saved credentials and everything will work just fine 😄\r\n\r\n(this supersedes #231 because it misbehaved, for some reason)","created_at":"2017-06-26T17:18:55Z","updated_at":"2017-06-27T07:15:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f660eb8970e02975d23774757a718e4304f1fcb0","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/toggl/mobileapp/pulls/235/commits","review_comments_url":"https://api.github.com/repos/toggl/mobileapp/pulls/235/comments","review_comment_url":"https://api.github.com/repos/toggl/mobileapp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/toggl/mobileapp/issues/235/comments","statuses_url":"https://api.github.com/repos/toggl/mobileapp/statuses/2a19d7c19fdd66dbcdd274ad72c1ac01ca759249","head":{"label":"toggl:config-registration","ref":"config-registration","sha":"2a19d7c19fdd66dbcdd274ad72c1ac01ca759249","user":{"login":"toggl","id":316475,"avatar_url":"https://avatars0.githubusercontent.com/u/316475?v=3","gravatar_id":"","url":"https://api.github.com/users/toggl","html_url":"https://github.com/toggl","followers_url":"https://api.github.com/users/toggl/followers","following_url":"https://api.github.com/users/toggl/following{/other_user}","gists_url":"https://api.github.com/users/toggl/gists{/gist_id}","starred_url":"https://api.github.com/users/toggl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/toggl/subscriptions","organizations_url":"https://api.github.com/users/toggl/orgs","repos_url":"https://api.github.com/users/toggl/repos","events_url":"https://api.github.com/users/toggl/events{/privacy}","received_events_url":"https://api.github.com/users/toggl/received_events","type":"Organization","site_admin":false},"repo":{"id":87079363,"name":"mobileapp","full_name":"toggl/mobileapp","owner":{"login":"toggl","id":316475,"avatar_url":"https://avatars0.githubusercontent.com/u/316475?v=3","gravatar_id":"","url":"https://api.github.com/users/toggl","html_url":"https://github.com/toggl","followers_url":"https://api.github.com/users/toggl/followers","following_url":"https://api.github.com/users/toggl/following{/other_user}","gists_url":"https://api.github.com/users/toggl/gists{/gist_id}","starred_url":"https://api.github.com/users/toggl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/toggl/subscriptions","organizations_url":"https://api.github.com/users/toggl/orgs","repos_url":"https://api.github.com/users/toggl/repos","events_url":"https://api.github.com/users/toggl/events{/privacy}","received_events_url":"https://api.github.com/users/toggl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/toggl/mobileapp","description":"Toggl's new mobile app","fork":false,"url":"https://api.github.com/repos/toggl/mobileapp","forks_url":"https://api.github.com/repos/toggl/mobileapp/forks","keys_url":"https://api.github.com/repos/toggl/mobileapp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/toggl/mobileapp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/toggl/mobileapp/teams","hooks_url":"https://api.github.com/repos/toggl/mobileapp/hooks","issue_events_url":"https://api.github.com/repos/toggl/mobileapp/issues/events{/number}","events_url":"https://api.github.com/repos/toggl/mobileapp/events","assignees_url":"https://api.github.com/repos/toggl/mobileapp/assignees{/user}","branches_url":"https://api.github.com/repos/toggl/mobileapp/branches{/branch}","tags_url":"https://api.github.com/repos/toggl/mobileapp/tags","blobs_url":"https://api.github.com/repos/toggl/mobileapp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/toggl/mobileapp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/toggl/mobileapp/git/refs{/sha}","trees_url":"https://api.github.com/repos/toggl/mobileapp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/toggl/mobileapp/statuses/{sha}","languages_url":"https://api.github.com/repos/toggl/mobileapp/languages","stargazers_url":"https://api.github.com/repos/toggl/mobileapp/stargazers","contributors_url":"https://api.github.com/repos/toggl/mobileapp/contributors","subscribers_url":"https://api.github.com/repos/toggl/mobileapp/subscribers","subscription_url":"https://api.github.com/repos/toggl/mobileapp/subscription","commits_url":"https://api.github.com/repos/toggl/mobileapp/commits{/sha}","git_commits_url":"https://api.github.com/repos/toggl/mobileapp/git/commits{/sha}","comments_url":"https://api.github.com/repos/toggl/mobileapp/comments{/number}","issue_comment_url":"https://api.github.com/repos/toggl/mobileapp/issues/comments{/number}","contents_url":"https://api.github.com/repos/toggl/mobileapp/contents/{+path}","compare_url":"https://api.github.com/repos/toggl/mobileapp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/toggl/mobileapp/merges","archive_url":"https://api.github.com/repos/toggl/mobileapp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/toggl/mobileapp/downloads","issues_url":"https://api.github.com/repos/toggl/mobileapp/issues{/number}","pulls_url":"https://api.github.com/repos/toggl/mobileapp/pulls{/number}","milestones_url":"https://api.github.com/repos/toggl/mobileapp/milestones{/number}","notifications_url":"https://api.github.com/repos/toggl/mobileapp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/toggl/mobileapp/labels{/name}","releases_url":"https://api.github.com/repos/toggl/mobileapp/releases{/id}","deployments_url":"https://api.github.com/repos/toggl/mobileapp/deployments","created_at":"2017-04-03T13:48:06Z","updated_at":"2017-06-17T03:38:15Z","pushed_at":"2017-06-26T18:08:09Z","git_url":"git://github.com/toggl/mobileapp.git","ssh_url":"git@github.com:toggl/mobileapp.git","clone_url":"https://github.com/toggl/mobileapp.git","svn_url":"https://github.com/toggl/mobileapp","homepage":null,"size":596,"stargazers_count":11,"watchers_count":11,"language":"C#","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":32,"forks":4,"open_issues":32,"watchers":11,"default_branch":"develop"}},"base":{"label":"toggl:develop","ref":"develop","sha":"aa877bf7e39b49e02d0e54f18ba1a02cb2b0e9d9","user":{"login":"toggl","id":316475,"avatar_url":"https://avatars0.githubusercontent.com/u/316475?v=3","gravatar_id":"","url":"https://api.github.com/users/toggl","html_url":"https://github.com/toggl","followers_url":"https://api.github.com/users/toggl/followers","following_url":"https://api.github.com/users/toggl/following{/other_user}","gists_url":"https://api.github.com/users/toggl/gists{/gist_id}","starred_url":"https://api.github.com/users/toggl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/toggl/subscriptions","organizations_url":"https://api.github.com/users/toggl/orgs","repos_url":"https://api.github.com/users/toggl/repos","events_url":"https://api.github.com/users/toggl/events{/privacy}","received_events_url":"https://api.github.com/users/toggl/received_events","type":"Organization","site_admin":false},"repo":{"id":87079363,"name":"mobileapp","full_name":"toggl/mobileapp","owner":{"login":"toggl","id":316475,"avatar_url":"https://avatars0.githubusercontent.com/u/316475?v=3","gravatar_id":"","url":"https://api.github.com/users/toggl","html_url":"https://github.com/toggl","followers_url":"https://api.github.com/users/toggl/followers","following_url":"https://api.github.com/users/toggl/following{/other_user}","gists_url":"https://api.github.com/users/toggl/gists{/gist_id}","starred_url":"https://api.github.com/users/toggl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/toggl/subscriptions","organizations_url":"https://api.github.com/users/toggl/orgs","repos_url":"https://api.github.com/users/toggl/repos","events_url":"https://api.github.com/users/toggl/events{/privacy}","received_events_url":"https://api.github.com/users/toggl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/toggl/mobileapp","description":"Toggl's new mobile app","fork":false,"url":"https://api.github.com/repos/toggl/mobileapp","forks_url":"https://api.github.com/repos/toggl/mobileapp/forks","keys_url":"https://api.github.com/repos/toggl/mobileapp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/toggl/mobileapp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/toggl/mobileapp/teams","hooks_url":"https://api.github.com/repos/toggl/mobileapp/hooks","issue_events_url":"https://api.github.com/repos/toggl/mobileapp/issues/events{/number}","events_url":"https://api.github.com/repos/toggl/mobileapp/events","assignees_url":"https://api.github.com/repos/toggl/mobileapp/assignees{/user}","branches_url":"https://api.github.com/repos/toggl/mobileapp/branches{/branch}","tags_url":"https://api.github.com/repos/toggl/mobileapp/tags","blobs_url":"https://api.github.com/repos/toggl/mobileapp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/toggl/mobileapp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/toggl/mobileapp/git/refs{/sha}","trees_url":"https://api.github.com/repos/toggl/mobileapp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/toggl/mobileapp/statuses/{sha}","languages_url":"https://api.github.com/repos/toggl/mobileapp/languages","stargazers_url":"https://api.github.com/repos/toggl/mobileapp/stargazers","contributors_url":"https://api.github.com/repos/toggl/mobileapp/contributors","subscribers_url":"https://api.github.com/repos/toggl/mobileapp/subscribers","subscription_url":"https://api.github.com/repos/toggl/mobileapp/subscription","commits_url":"https://api.github.com/repos/toggl/mobileapp/commits{/sha}","git_commits_url":"https://api.github.com/repos/toggl/mobileapp/git/commits{/sha}","comments_url":"https://api.github.com/repos/toggl/mobileapp/comments{/number}","issue_comment_url":"https://api.github.com/repos/toggl/mobileapp/issues/comments{/number}","contents_url":"https://api.github.com/repos/toggl/mobileapp/contents/{+path}","compare_url":"https://api.github.com/repos/toggl/mobileapp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/toggl/mobileapp/merges","archive_url":"https://api.github.com/repos/toggl/mobileapp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/toggl/mobileapp/downloads","issues_url":"https://api.github.com/repos/toggl/mobileapp/issues{/number}","pulls_url":"https://api.github.com/repos/toggl/mobileapp/pulls{/number}","milestones_url":"https://api.github.com/repos/toggl/mobileapp/milestones{/number}","notifications_url":"https://api.github.com/repos/toggl/mobileapp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/toggl/mobileapp/labels{/name}","releases_url":"https://api.github.com/repos/toggl/mobileapp/releases{/id}","deployments_url":"https://api.github.com/repos/toggl/mobileapp/deployments","created_at":"2017-04-03T13:48:06Z","updated_at":"2017-06-17T03:38:15Z","pushed_at":"2017-06-26T18:08:09Z","git_url":"git://github.com/toggl/mobileapp.git","ssh_url":"git@github.com:toggl/mobileapp.git","clone_url":"https://github.com/toggl/mobileapp.git","svn_url":"https://github.com/toggl/mobileapp","homepage":null,"size":596,"stargazers_count":11,"watchers_count":11,"language":"C#","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":32,"forks":4,"open_issues":32,"watchers":11,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/toggl/mobileapp/pulls/235"},"html":{"href":"https://github.com/toggl/mobileapp/pull/235"},"issue":{"href":"https://api.github.com/repos/toggl/mobileapp/issues/235"},"comments":{"href":"https://api.github.com/repos/toggl/mobileapp/issues/235/comments"},"review_comments":{"href":"https://api.github.com/repos/toggl/mobileapp/pulls/235/comments"},"review_comment":{"href":"https://api.github.com/repos/toggl/mobileapp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/toggl/mobileapp/pulls/235/commits"},"statuses":{"href":"https://api.github.com/repos/toggl/mobileapp/statuses/2a19d7c19fdd66dbcdd274ad72c1ac01ca759249"}}}}
{"actor":{"display_login":"amulware"}}