From 041d58a4b7f1354c96722cae6f68eeb5825a9e07 Mon Sep 17 00:00:00 2001 From: Haacked Date: Sun, 27 Jan 2013 21:06:16 -0800 Subject: [PATCH] Add SshKeysEndpoint --- Octopi/Endpoints/SshKeysEndpoint.cs | 58 +++++++++++++++++++++++++++++ Octopi/GitHubModels.cs | 37 +++++++++++++++++- Octopi/ISshKeysEndpoint.cs | 58 +++++++++++++++++++++++++++++ Octopi/Octopi.csproj | 2 + Octopi/OctopiRT.csproj | 2 + 5 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 Octopi/Endpoints/SshKeysEndpoint.cs create mode 100644 Octopi/ISshKeysEndpoint.cs diff --git a/Octopi/Endpoints/SshKeysEndpoint.cs b/Octopi/Endpoints/SshKeysEndpoint.cs new file mode 100644 index 00000000..8a04cff2 --- /dev/null +++ b/Octopi/Endpoints/SshKeysEndpoint.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Octopi.Http; + +namespace Octopi.Endpoints +{ + public class SshKeysEndpoint : ApiEndpoint, ISshKeysEndpoint + { + public SshKeysEndpoint(IConnection connection) : base(connection) + { + } + + public async Task Get(long id) + { + var endpoint = new Uri(string.Format("/user/keys/{0}", id), UriKind.Relative); + + return await Get(endpoint); + } + + public async Task> GetAll(string user) + { + var endpoint = new Uri(string.Format("/users/{0}/keys", user), UriKind.Relative); + + return await GetAll(endpoint); + } + + public async Task> GetAllForCurrent() + { + var endpoint = new Uri("/user/keys", UriKind.Relative); + + return await GetAll(endpoint); + } + + public async Task Create(SshKeyUpdate key) + { + Ensure.ArgumentNotNull(key, "key"); + + var endpoint = new Uri("/user/keys", UriKind.Relative); + return await Create(endpoint, key); + } + + public async Task Update(long id, SshKeyUpdate key) + { + Ensure.ArgumentNotNull(key, "key"); + + var endpoint = new Uri(string.Format("/user/keys/{0}", id), UriKind.Relative); + return await Update(endpoint, key); + } + + public async Task Delete(long id) + { + var endpoint = new Uri(string.Format("/user/keys/{0}", id), UriKind.Relative); + + await Delete(endpoint); + } + } +} diff --git a/Octopi/GitHubModels.cs b/Octopi/GitHubModels.cs index ef6a9a15..0e085b6f 100644 --- a/Octopi/GitHubModels.cs +++ b/Octopi/GitHubModels.cs @@ -285,7 +285,42 @@ namespace Octopi /// The api URL for this organization. /// public string Url { get; set; } - + } + + public class SshKey + { + /// + /// The system-wide unique Id for this user. + /// + public long Id { get; set; } + + /// + /// The SSH Key + /// + public string Key { get; set; } + + /// + /// The title of the SSH key + /// + public string Title { get; set; } + + /// + /// The api URL for this organization. + /// + public string Url { get; set; } + } + + public class SshKeyUpdate + { + /// + /// The SSH Key + /// + public string Key { get; set; } + + /// + /// The title of the SSH key + /// + public string Title { get; set; } } /// diff --git a/Octopi/ISshKeysEndpoint.cs b/Octopi/ISshKeysEndpoint.cs new file mode 100644 index 00000000..183886fd --- /dev/null +++ b/Octopi/ISshKeysEndpoint.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octopi +{ + public interface ISshKeysEndpoint + { + /// + /// Retrieves the for the specified id. + /// + /// The ID of the SSH key. + /// A + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] + Task Get(long id); + + /// + /// Retrieves the for the specified id. + /// + /// The login of the user. + /// A of . + Task> GetAll(string user); + + /// + /// Retrieves the for the specified id. + /// + /// Thrown if the client is not authenticated. + /// A of . + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", + Justification = "Makes a network request")] + Task> GetAllForCurrent(); + + /// + /// Update the specified . + /// + /// + /// Thrown if the client is not authenticated. + /// A + Task Create(SshKeyUpdate key); + + /// + /// Update the specified . + /// + /// + /// + /// Thrown if the client is not authenticated. + /// A + Task Update(long id, SshKeyUpdate key); + + /// + /// Update the specified . + /// + /// The id of the SSH key + /// Thrown if the client is not authenticated. + /// A + Task Delete(long id); + } +} diff --git a/Octopi/Octopi.csproj b/Octopi/Octopi.csproj index c6eae1d5..4ba9ed1e 100644 --- a/Octopi/Octopi.csproj +++ b/Octopi/Octopi.csproj @@ -48,6 +48,7 @@ + @@ -61,6 +62,7 @@ + diff --git a/Octopi/OctopiRT.csproj b/Octopi/OctopiRT.csproj index 8d8e1aa2..a2da9ffb 100644 --- a/Octopi/OctopiRT.csproj +++ b/Octopi/OctopiRT.csproj @@ -114,6 +114,7 @@ + @@ -130,6 +131,7 @@ +