From 23bb76a1127b22b32bab9c87cbf7a566a6ef18b5 Mon Sep 17 00:00:00 2001 From: Haacked Date: Tue, 21 Apr 2015 13:40:26 -0700 Subject: [PATCH] Implement Authorizations Delete method with 2fa code When we delete an authorization, we often need to use basic authentication because the client might not have the associated token stored anymore. If 2fa is enabled, the client needs to be able to pass that along. --- .../IObservableAuthorizationsClient.cs | 30 +++++++++++++++-- .../Clients/ObservableAuthorizationsClient.cs | 33 +++++++++++++++++-- Octokit/Clients/IAuthorizationsClient.cs | 17 ++++++++++ Octokit/Http/ApiConnection.cs | 13 ++++++++ Octokit/Http/Connection.cs | 20 +++++++++++ Octokit/Http/IApiConnection.cs | 8 +++++ Octokit/Http/IConnection.cs | 8 +++++ 7 files changed, 123 insertions(+), 6 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs b/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs index 5109bc2c..48847f87 100644 --- a/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs @@ -133,10 +133,34 @@ namespace Octokit.Reactive IObservable Update(int id, AuthorizationUpdate authorizationUpdate); /// - /// Deletes an . + /// Deletes the specified . /// - /// The systemwide id of the authorization - /// + /// + /// This method requires authentication. + /// See the API + /// documentation for more details. + /// + /// The system-wide ID of the authorization to delete + /// + /// Thrown when the current user does not have permission to make the request. + /// + /// Thrown when a general API error occurs. IObservable Delete(int id); + + /// + /// Deletes the specified . + /// + /// + /// This method requires authentication. + /// See the API + /// documentation for more details. + /// + /// The system-wide ID of the authorization to delete + /// Two factor authorization code + /// + /// Thrown when the current user does not have permission to make the request. + /// + /// Thrown when a general API error occurs. + IObservable Delete(int id, string twoFactorAuthenticationCode); } } diff --git a/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs b/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs index 82453680..6b0bd124 100644 --- a/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs @@ -201,13 +201,40 @@ namespace Octokit.Reactive } /// - /// Deletes an . + /// Deletes the specified . /// - /// The systemwide id of the authorization - /// + /// + /// This method requires authentication. + /// See the API + /// documentation for more details. + /// + /// The system-wide ID of the authorization to delete + /// + /// Thrown when the current user does not have permission to make the request. + /// + /// Thrown when a general API error occurs. public IObservable Delete(int id) { return _client.Delete(id).ToObservable(); } + + /// + /// Deletes the specified . + /// + /// + /// This method requires authentication. + /// See the API + /// documentation for more details. + /// + /// The system-wide ID of the authorization to delete + /// Two factor authorization code + /// + /// Thrown when the current user does not have permission to make the request. + /// + /// Thrown when a general API error occurs. + public IObservable Delete(int id, string twoFactorAuthenticationCode) + { + return _client.Delete(id, twoFactorAuthenticationCode).ToObservable(); + } } } diff --git a/Octokit/Clients/IAuthorizationsClient.cs b/Octokit/Clients/IAuthorizationsClient.cs index 583bcd89..9d050d54 100644 --- a/Octokit/Clients/IAuthorizationsClient.cs +++ b/Octokit/Clients/IAuthorizationsClient.cs @@ -178,5 +178,22 @@ namespace Octokit /// Thrown when a general API error occurs. /// A for the request's execution. Task Delete(int id); + + /// + /// Deletes the specified . + /// + /// + /// This method requires authentication. + /// See the API + /// documentation for more details. + /// + /// The system-wide ID of the authorization to delete + /// Two factor authorization code + /// + /// Thrown when the current user does not have permission to make the request. + /// + /// Thrown when a general API error occurs. + /// A for the request's execution. + Task Delete(int id, string twoFactorAuthenticationCode); } } diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index dc6881dc..51113271 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -332,6 +332,19 @@ namespace Octokit return Connection.Delete(uri); } + /// + /// Deletes the API object at the specified URI. + /// + /// URI of the API resource to delete + /// Two Factor Code + /// A for the request's execution. + public Task Delete(Uri uri, string twoFactorAuthenticationCode) + { + Ensure.ArgumentNotNull(uri, "uri"); + + return Connection.Delete(uri, twoFactorAuthenticationCode); + } + /// /// Deletes the API object at the specified URI. /// diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 29dc6f1b..a4c88909 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -361,6 +361,26 @@ namespace Octokit return response.HttpResponse.StatusCode; } + /// + /// Performs an asynchronous HTTP DELETE request that expects an empty response. + /// + /// URI endpoint to send request to + /// Two Factor Code + /// The returned + public async Task Delete(Uri uri, string twoFactorAuthenticationCode) + { + Ensure.ArgumentNotNull(uri, "uri"); + + var response = await SendData( + uri, + HttpMethod.Delete, + null, + null, + CancellationToken.None, + twoFactorAuthenticationCode); + return response.HttpResponse.StatusCode; + } + /// /// Performs an asynchronous HTTP DELETE request that expects an empty response. /// diff --git a/Octokit/Http/IApiConnection.cs b/Octokit/Http/IApiConnection.cs index 18416063..5bf11f8b 100644 --- a/Octokit/Http/IApiConnection.cs +++ b/Octokit/Http/IApiConnection.cs @@ -203,6 +203,14 @@ namespace Octokit /// A for the request's execution. Task Delete(Uri uri); + /// + /// Deletes the API object at the specified URI. + /// + /// URI of the API resource to delete + /// Two Factor Code + /// A for the request's execution. + Task Delete(Uri uri, string twoFactorAuthenticationCode); + /// /// Deletes the API object at the specified URI. /// diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index 41b77e86..37a6c004 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -164,6 +164,14 @@ namespace Octokit /// The returned Task Delete(Uri uri); + /// + /// Performs an asynchronous HTTP DELETE request that expects an empty response. + /// + /// URI endpoint to send request to + /// Two Factor Code + /// The returned + Task Delete(Uri uri, string twoFactorAuthenticationCode); + /// /// Performs an asynchronous HTTP DELETE request that expects an empty response. ///