Implement observable oauth client

Rx will never die
This commit is contained in:
Haacked
2014-04-22 08:38:53 -07:00
parent 5d70f885b7
commit 9e0fb886ca
5 changed files with 61 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
using System;
namespace Octokit.Reactive
{
public interface IObservableOauthClient
{
/// <summary>
/// Gets the URL used in the first step of the web flow. The Web application should redirect to this URL.
/// </summary>
/// <param name="request">Parameters to the Oauth web flow login url</param>
/// <returns></returns>
IObservable<Uri> GetGitHubLoginUrl(OauthLoginRequest request);
/// <summary>
/// Makes a request to get an access token using the code returned when GitHub.com redirects back from the URL
/// <see cref="GetGitHubLoginUrl">GitHub login url</see> to the application.
/// </summary>
/// <remarks>
/// If the user accepts your request, GitHub redirects back to your site with a temporary code in a code
/// parameter as well as the state you provided in the previous step in a state parameter. If the states dont
/// match, the request has been created by a third party and the process should be aborted. Exchange this for
/// an access token using this method.
/// </remarks>
/// <param name="request"></param>
/// <returns></returns>
IObservable<OauthToken> CreateAccessToken(OauthTokenRequest request);
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
{
public class ObservableOauthClient : IObservableOauthClient
{
readonly IGitHubClient _client;
public ObservableOauthClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client;
}
public IObservable<Uri> GetGitHubLoginUrl(OauthLoginRequest request)
{
return Observable.Return(_client.Oauth.GetGitHubLoginUrl(request));
}
public IObservable<OauthToken> CreateAccessToken(OauthTokenRequest request)
{
return _client.Oauth.CreateAccessToken(request).ToObservable();
}
}
}

View File

@@ -8,6 +8,7 @@
IObservableActivitiesClient Activity { get; } IObservableActivitiesClient Activity { get; }
IObservableIssuesClient Issue { get; } IObservableIssuesClient Issue { get; }
IObservableMiscellaneousClient Miscellaneous { get; } IObservableMiscellaneousClient Miscellaneous { get; }
IObservableOauthClient Oauth { get; }
IObservableOrganizationsClient Organization { get; } IObservableOrganizationsClient Organization { get; }
IObservableRepositoriesClient Repository { get; } IObservableRepositoriesClient Repository { get; }
IObservableGistsClient Gist { get; } IObservableGistsClient Gist { get; }

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Net.Http.Headers;
namespace Octokit.Reactive namespace Octokit.Reactive
{ {
@@ -37,6 +36,7 @@ namespace Octokit.Reactive
Issue = new ObservableIssuesClient(gitHubClient); Issue = new ObservableIssuesClient(gitHubClient);
Miscellaneous = new ObservableMiscellaneousClient(gitHubClient.Miscellaneous); Miscellaneous = new ObservableMiscellaneousClient(gitHubClient.Miscellaneous);
Notification = new ObservableNotificationsClient(gitHubClient); Notification = new ObservableNotificationsClient(gitHubClient);
Oauth = new ObservableOauthClient(gitHubClient);
Organization = new ObservableOrganizationsClient(gitHubClient); Organization = new ObservableOrganizationsClient(gitHubClient);
Repository = new ObservableRepositoriesClient(gitHubClient); Repository = new ObservableRepositoriesClient(gitHubClient);
SshKey = new ObservableSshKeysClient(gitHubClient); SshKey = new ObservableSshKeysClient(gitHubClient);
@@ -56,6 +56,7 @@ namespace Octokit.Reactive
public IObservableActivitiesClient Activity { get; private set; } public IObservableActivitiesClient Activity { get; private set; }
public IObservableIssuesClient Issue { get; private set; } public IObservableIssuesClient Issue { get; private set; }
public IObservableMiscellaneousClient Miscellaneous { get; private set; } public IObservableMiscellaneousClient Miscellaneous { get; private set; }
public IObservableOauthClient Oauth { get; private set; }
public IObservableOrganizationsClient Organization { get; private set; } public IObservableOrganizationsClient Organization { get; private set; }
public IObservableRepositoriesClient Repository { get; private set; } public IObservableRepositoriesClient Repository { get; private set; }
public IObservableGistsClient Gist { get; private set; } public IObservableGistsClient Gist { get; private set; }

View File

@@ -73,7 +73,9 @@
<Compile Include="..\SolutionInfo.cs"> <Compile Include="..\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link> <Link>Properties\SolutionInfo.cs</Link>
</Compile> </Compile>
<Compile Include="Clients\IObservableOauthClient.cs" />
<Compile Include="Clients\IObservableRepositoryCommitsClients.cs" /> <Compile Include="Clients\IObservableRepositoryCommitsClients.cs" />
<Compile Include="Clients\ObservableOauthClient.cs" />
<Compile Include="Clients\ObservableRepositoryCommentsClient.cs" /> <Compile Include="Clients\ObservableRepositoryCommentsClient.cs" />
<Compile Include="Clients\IObservableRepositoryCommentsClient.cs" /> <Compile Include="Clients\IObservableRepositoryCommentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentsClient.cs" /> <Compile Include="Clients\IObservableDeploymentsClient.cs" />
@@ -161,7 +163,6 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="DocPlagiarizer.README.md" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>