From d1361ead6c9365c7f3dd0d07ad9301b3bb5c6b8b Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 23:06:43 +0100 Subject: [PATCH] Minor adjustments to the API methods --- .../Clients/GistCommentsClientTests.cs | 59 ++++--------------- Octokit.sln.DotSettings | 1 + Octokit/Clients/GistCommentsClient.cs | 25 +++----- Octokit/Clients/IGistCommentsClient.cs | 10 ++-- Octokit/Helpers/ApiUrls.cs | 4 +- Octokit/Models/Request/BodyWrapper.cs | 12 ++++ Octokit/Models/Response/GistComment.cs | 2 +- Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-MonoAndroid.csproj | 1 + Octokit/Octokit-Monotouch.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 12 files changed, 44 insertions(+), 74 deletions(-) create mode 100644 Octokit/Models/Request/BodyWrapper.cs diff --git a/Octokit.Tests/Clients/GistCommentsClientTests.cs b/Octokit.Tests/Clients/GistCommentsClientTests.cs index 6a899355..6d7db2a9 100644 --- a/Octokit.Tests/Clients/GistCommentsClientTests.cs +++ b/Octokit.Tests/Clients/GistCommentsClientTests.cs @@ -22,24 +22,13 @@ namespace Octokit.Tests.Clients public class TheGetMethod { - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new GistCommentsClient(Substitute.For()); - - await AssertEx.Throws(async () => await client.Get(null, "1337")); - await AssertEx.Throws(async () => await client.Get("24", null)); - await AssertEx.Throws(async () => await client.Get("", "1337")); - await AssertEx.Throws(async () => await client.Get("24", "")); - } - [Fact] public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Get("24", "1337"); + await client.Get(24, 1337); connection.Received().Get(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), null); } @@ -47,22 +36,13 @@ namespace Octokit.Tests.Clients public class TheGetForGistMethod { - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new GistCommentsClient(Substitute.For()); - - await AssertEx.Throws(async () => await client.GetForGist(null)); - await AssertEx.Throws(async () => await client.GetForGist("")); - } - [Fact] public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.GetForGist("24"); + await client.GetForGist(24); connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments")); } @@ -75,10 +55,8 @@ namespace Octokit.Tests.Clients { var client = new GistCommentsClient(Substitute.For()); - await AssertEx.Throws(async () => await client.Create(null, "Comment")); - await AssertEx.Throws(async () => await client.Create("24", null)); - await AssertEx.Throws(async () => await client.Create("", "Comment")); - await AssertEx.Throws(async () => await client.Create("24", "")); + await AssertEx.Throws(async () => await client.Create(24, null)); + await AssertEx.Throws(async () => await client.Create(24, "")); } [Fact] @@ -88,9 +66,9 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Create("24", comment); + await client.Create(24, comment); - connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), comment); + connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), Arg.Is(x => x.Body == comment)); } } @@ -101,12 +79,8 @@ namespace Octokit.Tests.Clients { var client = new GistCommentsClient(Substitute.For()); - await AssertEx.Throws(async () => await client.Update(null, "1337", "Comment")); - await AssertEx.Throws(async () => await client.Update("24", null, "Comment")); - await AssertEx.Throws(async () => await client.Update("24", "1337", null)); - await AssertEx.Throws(async () => await client.Update("", "1337", "Comment")); - await AssertEx.Throws(async () => await client.Update("24", "", "Comment")); - await AssertEx.Throws(async () => await client.Update("24", "1337", "")); + await AssertEx.Throws(async () => await client.Update(24, 1337, null)); + await AssertEx.Throws(async () => await client.Update(24, 1337, "")); } [Fact] @@ -116,32 +90,21 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Update("24", "1337", comment); + await client.Update(24, 1337, comment); - connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), comment); + connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), Arg.Is(x => x.Body == comment)); } } public class TheDeleteMethod { - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new GistCommentsClient(Substitute.For()); - - await AssertEx.Throws(async () => await client.Delete(null, "1337")); - await AssertEx.Throws(async () => await client.Delete("24", null)); - await AssertEx.Throws(async () => await client.Delete("", "1337")); - await AssertEx.Throws(async () => await client.Delete("24", "")); - } - [Fact] public async Task PostsToCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Delete("24", "1337"); + await client.Delete(24, 1337); connection.Received().Delete(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); } diff --git a/Octokit.sln.DotSettings b/Octokit.sln.DotSettings index 36aa1792..202116c9 100644 --- a/Octokit.sln.DotSettings +++ b/Octokit.sln.DotSettings @@ -262,4 +262,5 @@ II.2.12 <HandlesEvent /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + True \ No newline at end of file diff --git a/Octokit/Clients/GistCommentsClient.cs b/Octokit/Clients/GistCommentsClient.cs index aa717cb6..1b708e43 100644 --- a/Octokit/Clients/GistCommentsClient.cs +++ b/Octokit/Clients/GistCommentsClient.cs @@ -16,11 +16,8 @@ namespace Octokit /// The id of the gist /// The id of the comment /// Task{GistComment}. - public Task Get(string gistId, string commentId) + public Task Get(int gistId, int commentId) { - Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); - Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); - return ApiConnection.Get(ApiUrls.GistComment(gistId, commentId)); } @@ -30,10 +27,8 @@ namespace Octokit /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist /// The id of the gist /// Task{IReadOnlyList{GistComment}}. - public Task> GetForGist(string gistId) + public Task> GetForGist(int gistId) { - Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); - return ApiConnection.GetAll(ApiUrls.GistComments(gistId)); } @@ -44,12 +39,11 @@ namespace Octokit /// The id of the gist /// The body of the comment /// Task{GistComment}. - public Task Create(string gistId, string comment) + public Task Create(int gistId, string comment) { - Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); - return ApiConnection.Post(ApiUrls.GistComments(gistId), comment); + return ApiConnection.Post(ApiUrls.GistComments(gistId), new BodyWrapper(comment)); } /// @@ -60,13 +54,11 @@ namespace Octokit /// The id of the comment /// The updated body of the comment /// Task{GistComment}. - public Task Update(string gistId, string commentId, string comment) + public Task Update(int gistId, int commentId, string comment) { - Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); - Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); - return ApiConnection.Patch(ApiUrls.GistComment(gistId, commentId), comment); + return ApiConnection.Patch(ApiUrls.GistComment(gistId, commentId), new BodyWrapper(comment)); } /// @@ -76,11 +68,8 @@ namespace Octokit /// The id of the gist /// The id of the comment /// Task. - public Task Delete(string gistId, string commentId) + public Task Delete(int gistId, int commentId) { - Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); - Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); - return ApiConnection.Delete(ApiUrls.GistComment(gistId, commentId)); } } diff --git a/Octokit/Clients/IGistCommentsClient.cs b/Octokit/Clients/IGistCommentsClient.cs index 49005986..a9a5aeb8 100644 --- a/Octokit/Clients/IGistCommentsClient.cs +++ b/Octokit/Clients/IGistCommentsClient.cs @@ -15,7 +15,7 @@ namespace Octokit /// Task{GistComment}. [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] - Task Get(string gistId, string commentId); + Task Get(int gistId, int commentId); /// /// Gets all comments for the gist with the specified id. @@ -23,7 +23,7 @@ namespace Octokit /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist /// The id of the gist /// Task{IReadOnlyList{GistComment}}. - Task> GetForGist(string gistId); + Task> GetForGist(int gistId); /// /// Creates a comment for the gist with the specified id. @@ -32,7 +32,7 @@ namespace Octokit /// The id of the gist /// The body of the comment /// Task{GistComment}. - Task Create(string gistId, string comment); + Task Create(int gistId, string comment); /// /// Updates the comment with the specified gist- and comment id. @@ -42,7 +42,7 @@ namespace Octokit /// The id of the comment /// The updated body of the comment /// Task{GistComment}. - Task Update(string gistId, string commentId, string comment); + Task Update(int gistId, int commentId, string comment); /// /// Deletes the comment with the specified gist- and comment id. @@ -51,6 +51,6 @@ namespace Octokit /// The id of the gist /// The id of the comment /// Task. - Task Delete(string gistId, string commentId); + Task Delete(int gistId, int commentId); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 06f6a8e5..78586961 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -461,7 +461,7 @@ namespace Octokit /// Returns the for the comments for the specified gist. /// /// The id of the gist - public static Uri GistComments(string gistId) + public static Uri GistComments(int gistId) { return "gists/{0}/comments".FormatUri(gistId); } @@ -471,7 +471,7 @@ namespace Octokit /// /// The id of the gist /// The id of the comment - public static Uri GistComment(string gistId, string commentId) + public static Uri GistComment(int gistId, int commentId) { return "gists/{0}/comments/{1}".FormatUri(gistId, commentId); } diff --git a/Octokit/Models/Request/BodyWrapper.cs b/Octokit/Models/Request/BodyWrapper.cs new file mode 100644 index 00000000..2c1d332f --- /dev/null +++ b/Octokit/Models/Request/BodyWrapper.cs @@ -0,0 +1,12 @@ +namespace Octokit +{ + public class BodyWrapper + { + public BodyWrapper(string body) + { + Body = body; + } + + public string Body { get; private set; } + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/GistComment.cs b/Octokit/Models/Response/GistComment.cs index e23945ed..f37023e0 100644 --- a/Octokit/Models/Response/GistComment.cs +++ b/Octokit/Models/Response/GistComment.cs @@ -7,7 +7,7 @@ namespace Octokit /// /// The gist comment id. /// - public string Id { get; set; } + public int Id { get; set; } /// /// The URL for this gist comment. diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index b4f5a9e2..80d77f4e 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -232,6 +232,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index f422fadc..549a850c 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -242,6 +242,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 01144c1a..40a3ea02 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -237,6 +237,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 6a66cba1..f621cbd4 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -230,6 +230,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 8eb92c0e..e1c46319 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -59,6 +59,7 @@ +