Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 0b32077

Browse files
Simplify ApiClient
1 parent 354c1f3 commit 0b32077

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@ class ApiClient : IApiClient
2727
private IKeychainAdapter keychainAdapter;
2828
private Connection connection;
2929

30-
public ApiClient(IKeychain keychain, IProcessManager processManager, ITaskManager taskManager, IEnvironment environment) :
31-
this(UriString.ToUriString(HostAddress.GitHubDotComHostAddress.WebUri), keychain, processManager, taskManager, environment)
30+
public ApiClient(IKeychain keychain, IProcessManager processManager, ITaskManager taskManager,
31+
IEnvironment environment, UriString host = null)
3232
{
33-
}
34-
35-
public ApiClient(UriString host, IKeychain keychain, IProcessManager processManager, ITaskManager taskManager, IEnvironment environment)
36-
{
37-
Guard.ArgumentNotNull(host, nameof(host));
3833
Guard.ArgumentNotNull(keychain, nameof(keychain));
3934

40-
host = new UriString(host.ToRepositoryUri().GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped));
35+
if (host == null)
36+
{
37+
host = UriString.ToUriString(HostAddress.GitHubDotComHostAddress.WebUri);
38+
}
39+
else
40+
{
41+
host = new UriString(host.ToRepositoryUri().GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped));
42+
}
43+
4144
HostAddress = HostAddress.Create(host);
4245

4346
this.keychain = keychain;

src/GitHub.Api/Authentication/OAuthCallbackManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public void Start()
6060

6161
public void Stop()
6262
{
63-
logger.Debug("Stop");
63+
logger.Trace("Stopping");
64+
cancelSource.Cancel();
6465
}
6566

6667
private void Listen()
@@ -86,15 +87,14 @@ private void Listen()
8687
}
8788

8889
context.Response.StatusCode = 200;
89-
context.Response.OutputStream.Flush();
9090
context.Response.Close();
9191
}
9292
}
9393
}
9494
}
9595
catch (Exception ex)
9696
{
97-
logger.Warning(ex, "OAuthCallbackManager Error");
97+
logger.Trace(ex.Message);
9898
}
9999
finally
100100
{

src/UnityExtension/Assets/Editor/GitHub.Unity/Services/AuthenticationService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ public AuthenticationService(UriString host, IKeychain keychain,
1616
IEnvironment environment
1717
)
1818
{
19-
client = host == null
20-
? new ApiClient(keychain, processManager, taskManager, environment)
21-
: new ApiClient(host, keychain, processManager, taskManager, environment);
19+
client = new ApiClient(keychain, processManager, taskManager, environment, host);
2220
}
2321

2422
public HostAddress HostAddress { get { return client.HostAddress; } }

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public override void InitializeView(IView parent)
3939
Logger.Trace(ex, "Error Starting OAuthCallbackManager");
4040
}
4141

42-
gitHubAuthenticationView.InitializeView(parent);
43-
gitHubEnterpriseAuthenticationView.InitializeView(parent);
42+
gitHubAuthenticationView.InitializeView(this);
43+
gitHubEnterpriseAuthenticationView.InitializeView(this);
4444

4545
hasGitHubDotComConnection = Platform.Keychain.Connections.Any(HostAddress.IsGitHubDotCom);
4646
hasGitHubEnterpriseConnection = Platform.Keychain.Connections.Any(connection => !HostAddress.IsGitHubDotCom(connection));
@@ -76,8 +76,8 @@ public override void OnDataUpdate()
7676

7777
public override void Finish(bool result)
7878
{
79-
base.Finish(result);
8079
OAuthCallbackManager.Stop();
80+
base.Finish(result);
8181
}
8282

8383
private void MaybeUpdateData()

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PopupWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ private void Open(PopupViewType popupViewType, Action<bool> onClose)
120120
var userHasAuthentication = false;
121121
foreach (var keychainConnection in Platform.Keychain.Connections.OrderByDescending(HostAddress.IsGitHubDotCom))
122122
{
123-
var apiClient = new ApiClient(keychainConnection.Host, Platform.Keychain, Platform.ProcessManager, TaskManager,
124-
Environment);
123+
var apiClient = new ApiClient(Platform.Keychain, Platform.ProcessManager, TaskManager,
124+
Environment, keychainConnection.Host);
125125

126126
try
127127
{

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PublishView.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ private IApiClient GetApiClient(Connection connection)
7979

8080
if (!clients.TryGetValue(connection.Host, out client))
8181
{
82-
client = HostAddress.IsGitHubDotCom(connection)
83-
? new ApiClient(Platform.Keychain, Platform.ProcessManager, TaskManager, Environment)
84-
: new ApiClient(connection.Host, Platform.Keychain, Platform.ProcessManager, TaskManager, Environment);
82+
client = new ApiClient(Platform.Keychain, Platform.ProcessManager, TaskManager, Environment, connection.Host);
8583

8684
clients.Add(connection.Host, client);
8785
}

0 commit comments

Comments
 (0)