From 3c05db4065a0773b46a6a1e459fc10d248a8720f Mon Sep 17 00:00:00 2001 From: Chris Simpson Date: Tue, 20 Sep 2022 20:37:49 +0100 Subject: [PATCH] Splitting out the misc client into separate clients as per current documentation (#2574) --- .../Clients/IObservableEmojiClient.cs | 20 +++++ .../Clients/IObservableGitIgnoreClient.cs | 25 ++++++ .../Clients/IObservableLicensesClient.cs | 35 ++++++++ .../Clients/IObservableMarkdownClient.cs | 29 +++++++ .../Clients/IObservableMetaClient.cs | 20 +++++ .../Clients/IObservableMiscellaneousClient.cs | 18 ++-- .../Clients/IObservableRateLimitClient.cs | 20 +++++ .../Clients/ObservableEmojiClient.cs | 34 ++++++++ .../Clients/ObservableGitIgnoreClient.cs | 42 +++++++++ .../Clients/ObservableLicensesClient.cs | 55 ++++++++++++ .../Clients/ObservableMarkdownClient.cs | 46 ++++++++++ .../Clients/ObservableMetaClient.cs | 34 ++++++++ .../Clients/ObservableMiscellaneousClient.cs | 14 ++- .../Clients/ObservableRateLimitClient.cs | 34 ++++++++ Octokit.Reactive/IObservableGitHubClient.cs | 6 ++ Octokit.Reactive/ObservableGitHubClient.cs | 12 +++ .../Clients/EmojisClientTests.cs | 18 ++++ .../Clients/GitIgnoreClientTests.cs | 18 ++++ .../Clients/LicensesClientTests.cs | 85 +++++++++++++++++++ .../Clients/MarkdownClientTests.cs | 18 ++++ .../Clients/MetaClientTests.cs | 26 ++++++ .../Clients/RateLimitClientTests.cs | 37 ++++++++ Octokit.Tests/Clients/EmojisClientTests.cs | 46 ++++++++++ Octokit.Tests/Clients/LicensesClientTests.cs | 59 +++++++++++++ Octokit.Tests/Clients/MarkdownClientTests.cs | 70 +++++++++++++++ Octokit.Tests/Clients/MetaClientTests.cs | 51 +++++++++++ Octokit.Tests/Clients/RateLimitClientTests.cs | 74 ++++++++++++++++ .../Reactive/ObservableEmojiClientTests.cs | 33 +++++++ .../ObservableGitIgnoreClientTests.cs | 47 ++++++++++ .../Reactive/ObservableLicensesClientTests.cs | 47 ++++++++++ .../Reactive/ObservableMarkdownClientTests.cs | 47 ++++++++++ .../Reactive/ObservableMetaClientTests.cs | 33 +++++++ .../ObservableRateLimitClientTests.cs | 33 +++++++ Octokit/Clients/EmojisClient.cs | 34 ++++++++ Octokit/Clients/GitIgnoreClient.cs | 46 ++++++++++ Octokit/Clients/IEmojisClient.cs | 22 +++++ Octokit/Clients/IGitIgnoreClient.cs | 29 +++++++ Octokit/Clients/ILicensesClient.cs | 36 ++++++++ Octokit/Clients/IMarkdownClient.cs | 29 +++++++ Octokit/Clients/IMetaClient.cs | 20 +++++ Octokit/Clients/IMiscellaneousClient.cs | 18 ++-- Octokit/Clients/IRateLimitClient.cs | 20 +++++ Octokit/Clients/LicensesClient.cs | 59 +++++++++++++ Octokit/Clients/MarkdownClient.cs | 46 ++++++++++ Octokit/Clients/MetaClient.cs | 35 ++++++++ Octokit/Clients/MiscellaneousClient.cs | 49 ++++++++--- Octokit/Clients/RateLimitClient.cs | 35 ++++++++ Octokit/GitHubClient.cs | 54 ++++++++++++ Octokit/IGitHubClient.cs | 41 +++++++++ 49 files changed, 1729 insertions(+), 30 deletions(-) create mode 100644 Octokit.Reactive/Clients/IObservableEmojiClient.cs create mode 100644 Octokit.Reactive/Clients/IObservableGitIgnoreClient.cs create mode 100644 Octokit.Reactive/Clients/IObservableLicensesClient.cs create mode 100644 Octokit.Reactive/Clients/IObservableMarkdownClient.cs create mode 100644 Octokit.Reactive/Clients/IObservableMetaClient.cs create mode 100644 Octokit.Reactive/Clients/IObservableRateLimitClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableEmojiClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableGitIgnoreClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableLicensesClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableMarkdownClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableMetaClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableRateLimitClient.cs create mode 100644 Octokit.Tests.Integration/Clients/EmojisClientTests.cs create mode 100644 Octokit.Tests.Integration/Clients/GitIgnoreClientTests.cs create mode 100644 Octokit.Tests.Integration/Clients/LicensesClientTests.cs create mode 100644 Octokit.Tests.Integration/Clients/MarkdownClientTests.cs create mode 100644 Octokit.Tests.Integration/Clients/MetaClientTests.cs create mode 100644 Octokit.Tests.Integration/Clients/RateLimitClientTests.cs create mode 100644 Octokit.Tests/Clients/EmojisClientTests.cs create mode 100644 Octokit.Tests/Clients/LicensesClientTests.cs create mode 100644 Octokit.Tests/Clients/MarkdownClientTests.cs create mode 100644 Octokit.Tests/Clients/MetaClientTests.cs create mode 100644 Octokit.Tests/Clients/RateLimitClientTests.cs create mode 100644 Octokit.Tests/Reactive/ObservableEmojiClientTests.cs create mode 100644 Octokit.Tests/Reactive/ObservableGitIgnoreClientTests.cs create mode 100644 Octokit.Tests/Reactive/ObservableLicensesClientTests.cs create mode 100644 Octokit.Tests/Reactive/ObservableMarkdownClientTests.cs create mode 100644 Octokit.Tests/Reactive/ObservableMetaClientTests.cs create mode 100644 Octokit.Tests/Reactive/ObservableRateLimitClientTests.cs create mode 100644 Octokit/Clients/EmojisClient.cs create mode 100644 Octokit/Clients/GitIgnoreClient.cs create mode 100644 Octokit/Clients/IEmojisClient.cs create mode 100644 Octokit/Clients/IGitIgnoreClient.cs create mode 100644 Octokit/Clients/ILicensesClient.cs create mode 100644 Octokit/Clients/IMarkdownClient.cs create mode 100644 Octokit/Clients/IMetaClient.cs create mode 100644 Octokit/Clients/IRateLimitClient.cs create mode 100644 Octokit/Clients/LicensesClient.cs create mode 100644 Octokit/Clients/MarkdownClient.cs create mode 100644 Octokit/Clients/MetaClient.cs create mode 100644 Octokit/Clients/RateLimitClient.cs diff --git a/Octokit.Reactive/Clients/IObservableEmojiClient.cs b/Octokit.Reactive/Clients/IObservableEmojiClient.cs new file mode 100644 index 0000000000..74f93fa5cf --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableEmojiClient.cs @@ -0,0 +1,20 @@ +using System; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's Emojis APIs. + /// + /// + /// See the Emojis API documentation for more details. + /// + public interface IObservableEmojisClient + { + /// + /// Gets all the emojis available to use on GitHub. + /// + /// Thrown when a general API error occurs. + /// An of emoji and their URI. + IObservable GetAllEmojis(); + } +} diff --git a/Octokit.Reactive/Clients/IObservableGitIgnoreClient.cs b/Octokit.Reactive/Clients/IObservableGitIgnoreClient.cs new file mode 100644 index 0000000000..b372620ade --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableGitIgnoreClient.cs @@ -0,0 +1,25 @@ +using System; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's gitignore APIs. + /// + /// + /// See the GitIgnore API documentation for more details. + /// + public interface IObservableGitIgnoreClient + { + /// + /// List all templates available to pass as an option when creating a repository. + /// + /// An observable list of gitignore template names. + IObservable GetAllGitIgnoreTemplates(); + + /// + /// Retrieves the source for a single GitIgnore template + /// + /// Returns the template source for the given template + IObservable GetGitIgnoreTemplate(string templateName); + } +} diff --git a/Octokit.Reactive/Clients/IObservableLicensesClient.cs b/Octokit.Reactive/Clients/IObservableLicensesClient.cs new file mode 100644 index 0000000000..030aa77578 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableLicensesClient.cs @@ -0,0 +1,35 @@ +using System; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's licenses APIs. + /// + /// + /// See the Licenses API documentation for more details. + /// + public interface IObservableLicensesClient + { + /// + /// Returns a list of the licenses shown in the license picker on GitHub.com. This is not a comprehensive + /// list of all possible OSS licenses. + /// + /// A list of licenses available on the site + IObservable GetAllLicenses(); + + /// + /// Returns a list of the licenses shown in the license picker on GitHub.com. This is not a comprehensive + /// list of all possible OSS licenses. + /// + /// Options for changing the API response + /// A list of licenses available on the site + IObservable GetAllLicenses(ApiOptions options); + + /// + /// Retrieves a license based on the license key such as "MIT" + /// + /// + /// A that includes the license key, text, and attributes of the license. + IObservable GetLicense(string key); + } +} diff --git a/Octokit.Reactive/Clients/IObservableMarkdownClient.cs b/Octokit.Reactive/Clients/IObservableMarkdownClient.cs new file mode 100644 index 0000000000..c779dfcc9e --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableMarkdownClient.cs @@ -0,0 +1,29 @@ +using System; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's markdown APIs. + /// + /// + /// See the Markdown API documentation for more details. + /// + public interface IObservableMarkdownClient + { + /// + /// Gets the rendered Markdown for an arbitrary markdown document. + /// + /// An arbitrary Markdown document + /// Thrown when a general API error occurs. + /// The rendered Markdown. + IObservable RenderArbitraryMarkdown(NewArbitraryMarkdown markdown); + + /// + /// Gets the rendered Markdown for the specified plain-text Markdown document. + /// + /// A plain-text Markdown document + /// Thrown when a general API error occurs. + /// The rendered Markdown. + IObservable RenderRawMarkdown(string markdown); + } +} diff --git a/Octokit.Reactive/Clients/IObservableMetaClient.cs b/Octokit.Reactive/Clients/IObservableMetaClient.cs new file mode 100644 index 0000000000..97d63d19e3 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableMetaClient.cs @@ -0,0 +1,20 @@ +using System; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's meta APIs. + /// + /// + /// See the Meta API documentation for more details. + /// + public interface IObservableMetaClient + { + /// + /// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation. + /// + /// Thrown when a general API error occurs. + /// An containing metadata about the GitHub instance. + IObservable GetMetadata(); + } +} diff --git a/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs b/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs index 2122d9be64..cfd6ad0dbe 100644 --- a/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs +++ b/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs @@ -1,8 +1,8 @@ using System; -using System.Diagnostics.CodeAnalysis; namespace Octokit.Reactive { + [Obsolete("Use individual clients for these methods")] public interface IObservableMiscellaneousClient { /// @@ -10,8 +10,7 @@ public interface IObservableMiscellaneousClient /// /// Thrown when a general API error occurs. /// An of emoji and their URI. - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", - Justification = "Makes a network request")] + [Obsolete("This client is being deprecated and will be removed in the future. Use EmojisClient.GetAllEmojis instead.")] IObservable GetAllEmojis(); /// @@ -20,6 +19,7 @@ public interface IObservableMiscellaneousClient /// An arbitrary Markdown document /// Thrown when a general API error occurs. /// The rendered Markdown. + [Obsolete("This client is being deprecated and will be removed in the future. Use MarkdownClient.RenderArbitraryMarkdown instead.")] IObservable RenderArbitraryMarkdown(NewArbitraryMarkdown markdown); /// @@ -28,19 +28,21 @@ public interface IObservableMiscellaneousClient /// A plain-text Markdown document /// Thrown when a general API error occurs. /// The rendered Markdown. + [Obsolete("This client is being deprecated and will be removed in the future. Use MarkdownClient.RenderRawMarkdown instead.")] IObservable RenderRawMarkdown(string markdown); /// /// List all templates available to pass as an option when creating a repository. /// /// An observable list of gitignore template names. - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [Obsolete("This client is being deprecated and will be removed in the future. Use GitIgnoreClient.GetAllGitIgnoreTemplates instead.")] IObservable GetAllGitIgnoreTemplates(); /// /// Retrieves the source for a single GitIgnore template /// /// Returns the template source for the given template + [Obsolete("This client is being deprecated and will be removed in the future. Use GitIgnoreClient.GetGitIgnoreTemplate instead.")] IObservable GetGitIgnoreTemplate(string templateName); /// @@ -48,7 +50,7 @@ public interface IObservableMiscellaneousClient /// list of all possible OSS licenses. /// /// A list of licenses available on the site - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [Obsolete("This client is being deprecated and will be removed in the future. Use LicensesClient.GetAllLicenses instead.")] IObservable GetAllLicenses(); /// @@ -57,6 +59,7 @@ public interface IObservableMiscellaneousClient /// /// Options for changing the API response /// A list of licenses available on the site + [Obsolete("This client is being deprecated and will be removed in the future. Use LicensesClient.GetAllLicenses instead.")] IObservable GetAllLicenses(ApiOptions options); /// @@ -64,6 +67,7 @@ public interface IObservableMiscellaneousClient /// /// /// A that includes the license key, text, and attributes of the license. + [Obsolete("This client is being deprecated and will be removed in the future. Use LicensesClient.GetLicense instead.")] IObservable GetLicense(string key); /// @@ -71,7 +75,7 @@ public interface IObservableMiscellaneousClient /// /// Thrown when a general API error occurs. /// An of Rate Limits. - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [Obsolete("This client is being deprecated and will be removed in the future. Use RateLimitClient.GetRateLimits instead.")] IObservable GetRateLimits(); /// @@ -79,7 +83,7 @@ public interface IObservableMiscellaneousClient /// /// Thrown when a general API error occurs. /// An containing metadata about the GitHub instance. - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [Obsolete("This client is being deprecated and will be removed in the future. Use MetaClient.GetMetadata instead.")] IObservable GetMetadata(); } } diff --git a/Octokit.Reactive/Clients/IObservableRateLimitClient.cs b/Octokit.Reactive/Clients/IObservableRateLimitClient.cs new file mode 100644 index 0000000000..62e3224dbc --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableRateLimitClient.cs @@ -0,0 +1,20 @@ +using System; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's rate-limit APIs. + /// + /// + /// See the Rate-Limit API documentation for more details. + /// + public interface IObservableRateLimitClient + { + /// + /// Gets API Rate Limits (API service rather than header info). + /// + /// Thrown when a general API error occurs. + /// An of Rate Limits. + IObservable GetRateLimits(); + } +} diff --git a/Octokit.Reactive/Clients/ObservableEmojiClient.cs b/Octokit.Reactive/Clients/ObservableEmojiClient.cs new file mode 100644 index 0000000000..1eca68c87a --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableEmojiClient.cs @@ -0,0 +1,34 @@ +using System; +using System.Reactive.Linq; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's Emojis APIs. + /// + /// + /// See the Emojis API documentation for more details. + /// + public class ObservableEmojisClient : IObservableEmojisClient + { + private readonly IEmojisClient _client; + + public ObservableEmojisClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, nameof(client)); + + _client = client.Emojis; + } + + /// + /// Gets all the emojis available to use on GitHub. + /// + /// Thrown when a general API error occurs. + /// An of emoji and their URI. + public IObservable GetAllEmojis() + { + return _client.GetAllEmojis().ToObservable().SelectMany(e => e); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableGitIgnoreClient.cs b/Octokit.Reactive/Clients/ObservableGitIgnoreClient.cs new file mode 100644 index 0000000000..4faca614fe --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableGitIgnoreClient.cs @@ -0,0 +1,42 @@ +using System; +using System.Reactive.Linq; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's gitignore APIs. + /// + /// + /// See the GitIgnore API documentation for more details. + /// + public class ObservableGitIgnoreClient : IObservableGitIgnoreClient + { + private readonly IGitIgnoreClient _client; + + public ObservableGitIgnoreClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, nameof(client)); + + _client = client.GitIgnore; + } + + /// + /// List all templates available to pass as an option when creating a repository. + /// + /// An observable list of gitignore template names. + public IObservable GetAllGitIgnoreTemplates() + { + return _client.GetAllGitIgnoreTemplates().ToObservable().SelectMany(t => t); + } + + /// + /// Retrieves the source for a single GitIgnore template + /// + /// Returns the template source for the given template + public IObservable GetGitIgnoreTemplate(string templateName) + { + return _client.GetGitIgnoreTemplate(templateName).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableLicensesClient.cs b/Octokit.Reactive/Clients/ObservableLicensesClient.cs new file mode 100644 index 0000000000..c247e018a3 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableLicensesClient.cs @@ -0,0 +1,55 @@ +using System; +using System.Reactive.Linq; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's licenses APIs. + /// + /// + /// See the Licenses API documentation for more details. + /// + public class ObservableLicensesClient : IObservableLicensesClient + { + private readonly ILicensesClient _client; + + public ObservableLicensesClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, nameof(client)); + + _client = client.Licenses; + } + + /// + /// Returns a list of the licenses shown in the license picker on GitHub.com. This is not a comprehensive + /// list of all possible OSS licenses. + /// + /// A list of licenses available on the site + public IObservable GetAllLicenses() + { + return GetAllLicenses(ApiOptions.None); + } + + /// + /// Returns a list of the licenses shown in the license picker on GitHub.com. This is not a comprehensive + /// list of all possible OSS licenses. + /// + /// Options for changing the API response + /// A list of licenses available on the site + public IObservable GetAllLicenses(ApiOptions options) + { + return _client.GetAllLicenses(options).ToObservable().SelectMany(l => l); + } + + /// + /// Retrieves a license based on the license key such as "MIT" + /// + /// + /// A that includes the license key, text, and attributes of the license. + public IObservable GetLicense(string key) + { + return _client.GetLicense(key).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableMarkdownClient.cs b/Octokit.Reactive/Clients/ObservableMarkdownClient.cs new file mode 100644 index 0000000000..e29b6d372b --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableMarkdownClient.cs @@ -0,0 +1,46 @@ +using System; +using System.Reactive.Linq; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's markdown APIs. + /// + /// + /// See the Markdown API documentation for more details. + /// + public class ObservableMarkdownClient : IObservableMarkdownClient + { + private readonly IMarkdownClient _client; + + public ObservableMarkdownClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, nameof(client)); + + _client = client.Markdown; + } + + /// + /// Gets the rendered Markdown for an arbitrary markdown document. + /// + /// An arbitrary Markdown document + /// Thrown when a general API error occurs. + /// The rendered Markdown. + public IObservable RenderArbitraryMarkdown(NewArbitraryMarkdown markdown) + { + return _client.RenderArbitraryMarkdown(markdown).ToObservable(); + } + + /// + /// Gets the rendered Markdown for the specified plain-text Markdown document. + /// + /// A plain-text Markdown document + /// Thrown when a general API error occurs. + /// The rendered Markdown. + public IObservable RenderRawMarkdown(string markdown) + { + return _client.RenderRawMarkdown(markdown).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableMetaClient.cs b/Octokit.Reactive/Clients/ObservableMetaClient.cs new file mode 100644 index 0000000000..3df88872d7 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableMetaClient.cs @@ -0,0 +1,34 @@ +using System; +using System.Reactive.Linq; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's meta APIs. + /// + /// + /// See the Meta API documentation for more details. + /// + public class ObservableMetaClient : IObservableMetaClient + { + private readonly IMetaClient _client; + + public ObservableMetaClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, nameof(client)); + + _client = client.Meta; + } + + /// + /// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation. + /// + /// Thrown when a general API error occurs. + /// An containing metadata about the GitHub instance. + public IObservable GetMetadata() + { + return _client.GetMetadata().ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs b/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs index 86973c6475..e34a341996 100644 --- a/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs +++ b/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs @@ -1,10 +1,10 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.Reactive.Linq; using System.Reactive.Threading.Tasks; namespace Octokit.Reactive { + [Obsolete("Use individual clients available on the GitHubClient for these methods")] public class ObservableMiscellaneousClient : IObservableMiscellaneousClient { readonly IMiscellaneousClient _client; @@ -21,6 +21,7 @@ public ObservableMiscellaneousClient(IGitHubClient client) /// /// Thrown when a general API error occurs. /// An of emoji and their URI. + [Obsolete("This client is being deprecated and will be removed in the future. Use EmojisClient.GetAllEmojis instead.")] public IObservable GetAllEmojis() { return _client.GetAllEmojis().ToObservable().SelectMany(e => e); @@ -32,6 +33,7 @@ public IObservable GetAllEmojis() /// An arbitrary Markdown document /// Thrown when a general API error occurs. /// The rendered Markdown. + [Obsolete("This client is being deprecated and will be removed in the future. Use MarkdownClient.RenderArbitraryMarkdown instead.")] public IObservable RenderArbitraryMarkdown(NewArbitraryMarkdown markdown) { return _client.RenderArbitraryMarkdown(markdown).ToObservable(); @@ -43,6 +45,7 @@ public IObservable RenderArbitraryMarkdown(NewArbitraryMarkdown markdown /// A plain-text Markdown document /// Thrown when a general API error occurs. /// The rendered Markdown. + [Obsolete("This client is being deprecated and will be removed in the future. Use MarkdownClient.RenderRawMarkdown instead.")] public IObservable RenderRawMarkdown(string markdown) { return _client.RenderRawMarkdown(markdown).ToObservable(); @@ -52,6 +55,7 @@ public IObservable RenderRawMarkdown(string markdown) /// List all templates available to pass as an option when creating a repository. /// /// An observable list of gitignore template names. + [Obsolete("This client is being deprecated and will be removed in the future. Use GitIgnoreClient.GetAllGitIgnoreTemplates instead.")] public IObservable GetAllGitIgnoreTemplates() { return _client.GetAllGitIgnoreTemplates().ToObservable().SelectMany(t => t); @@ -61,6 +65,7 @@ public IObservable GetAllGitIgnoreTemplates() /// Retrieves the source for a single GitIgnore template /// /// Returns the template source for the given template + [Obsolete("This client is being deprecated and will be removed in the future. Use GitIgnoreClient.GetGitIgnoreTemplate instead.")] public IObservable GetGitIgnoreTemplate(string templateName) { return _client.GetGitIgnoreTemplate(templateName).ToObservable(); @@ -71,6 +76,7 @@ public IObservable GetGitIgnoreTemplate(string templateName) /// list of all possible OSS licenses. /// /// A list of licenses available on the site + [Obsolete("This client is being deprecated and will be removed in the future. Use LicensesClient.GetAllLicenses instead.")] public IObservable GetAllLicenses() { return GetAllLicenses(ApiOptions.None); @@ -82,6 +88,7 @@ public IObservable GetAllLicenses() /// /// Options for changing the API response /// A list of licenses available on the site + [Obsolete("This client is being deprecated and will be removed in the future. Use LicensesClient.GetAllLicenses instead.")] public IObservable GetAllLicenses(ApiOptions options) { return _client.GetAllLicenses(options).ToObservable().SelectMany(l => l); @@ -92,6 +99,7 @@ public IObservable GetAllLicenses(ApiOptions options) /// /// /// A that includes the license key, text, and attributes of the license. + [Obsolete("This client is being deprecated and will be removed in the future. Use LicensesClient.GetLicense instead.")] public IObservable GetLicense(string key) { return _client.GetLicense(key).ToObservable(); @@ -102,7 +110,7 @@ public IObservable GetLicense(string key) /// /// Thrown when a general API error occurs. /// An of Rate Limits. - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [Obsolete("This client is being deprecated and will be removed in the future. Use RateLimitClient.GetRateLimits instead.")] public IObservable GetRateLimits() { return _client.GetRateLimits().ToObservable(); @@ -113,7 +121,7 @@ public IObservable GetRateLimits() /// /// Thrown when a general API error occurs. /// An containing metadata about the GitHub instance. - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [Obsolete("This client is being deprecated and will be removed in the future. Use MetaClient.GetMetadata instead.")] public IObservable GetMetadata() { return _client.GetMetadata().ToObservable(); diff --git a/Octokit.Reactive/Clients/ObservableRateLimitClient.cs b/Octokit.Reactive/Clients/ObservableRateLimitClient.cs new file mode 100644 index 0000000000..f0513a4fcc --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableRateLimitClient.cs @@ -0,0 +1,34 @@ +using System; +using System.Reactive.Linq; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's rate-limit APIs. + /// + /// + /// See the Rate-Limit API documentation for more details. + /// + public class ObservableRateLimitClient : IObservableRateLimitClient + { + private readonly IRateLimitClient _client; + + public ObservableRateLimitClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, nameof(client)); + + _client = client.RateLimit; + } + + /// + /// Gets API Rate Limits (API service rather than header info). + /// + /// Thrown when a general API error occurs. + /// An of Rate Limits. + public IObservable GetRateLimits() + { + return _client.GetRateLimits().ToObservable(); + } + } +} diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index 5563afe5c2..f5ed4393d1 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -35,5 +35,11 @@ public interface IObservableGitHubClient : IApiInfoProvider IObservableReactionsClient Reaction { get; } IObservableChecksClient Check { get; } IObservablePackagesClient Packages{ get; } + IObservableEmojisClient Emojis { get; } + IObservableMarkdownClient Markdown { get; } + IObservableGitIgnoreClient GitIgnore { get; } + IObservableLicensesClient Licenses { get; } + IObservableRateLimitClient RateLimit { get; } + IObservableMetaClient Meta { get; } } } \ No newline at end of file diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index e84e191b1f..648360f4c8 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -50,6 +50,12 @@ public ObservableGitHubClient(IGitHubClient gitHubClient) Reaction = new ObservableReactionsClient(gitHubClient); Check = new ObservableChecksClient(gitHubClient); Packages = new ObservablePackagesClient(gitHubClient); + Emojis = new ObservableEmojisClient(gitHubClient); + Markdown = new ObservableMarkdownClient(gitHubClient); + GitIgnore = new ObservableGitIgnoreClient(gitHubClient); + Licenses = new ObservableLicensesClient(gitHubClient); + RateLimit = new ObservableRateLimitClient(gitHubClient); + Meta = new ObservableMetaClient(gitHubClient); } public IConnection Connection @@ -90,6 +96,12 @@ public void SetRequestTimeout(TimeSpan timeout) public IObservableReactionsClient Reaction { get; private set; } public IObservableChecksClient Check { get; private set; } public IObservablePackagesClient Packages { get; private set; } + public IObservableEmojisClient Emojis { get; private set; } + public IObservableMarkdownClient Markdown { get; private set; } + public IObservableGitIgnoreClient GitIgnore { get; private set; } + public IObservableLicensesClient Licenses { get; private set; } + public IObservableRateLimitClient RateLimit { get; private set; } + public IObservableMetaClient Meta { get; private set; } /// /// Gets the latest API Info - this will be null if no API calls have been made diff --git a/Octokit.Tests.Integration/Clients/EmojisClientTests.cs b/Octokit.Tests.Integration/Clients/EmojisClientTests.cs new file mode 100644 index 0000000000..b76b4bddfb --- /dev/null +++ b/Octokit.Tests.Integration/Clients/EmojisClientTests.cs @@ -0,0 +1,18 @@ +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class EmojisClientTests + { + [IntegrationTest] + public async Task GetsAllTheEmojis() + { + var github = Helper.GetAuthenticatedClient(); + + var emojis = await github.Emojis.GetAllEmojis(); + + Assert.True(emojis.Count > 1); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Clients/GitIgnoreClientTests.cs b/Octokit.Tests.Integration/Clients/GitIgnoreClientTests.cs new file mode 100644 index 0000000000..3f2a34ed32 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/GitIgnoreClientTests.cs @@ -0,0 +1,18 @@ +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class GitIgnoreClientTests + { + [IntegrationTest] + public async Task ReturnsListOfGitIgnoreTemplates() + { + var github = Helper.GetAuthenticatedClient(); + + var result = await github.GitIgnore.GetAllGitIgnoreTemplates(); + + Assert.True(result.Count > 2); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Clients/LicensesClientTests.cs b/Octokit.Tests.Integration/Clients/LicensesClientTests.cs new file mode 100644 index 0000000000..8bf3c2dc9d --- /dev/null +++ b/Octokit.Tests.Integration/Clients/LicensesClientTests.cs @@ -0,0 +1,85 @@ +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class LicensesClientTests + { + public class TheGetLicensesMethod + { + [IntegrationTest] + public async Task CanRetrieveListOfLicenses() + { + var github = Helper.GetAuthenticatedClient(); + + var result = await github.Licenses.GetAllLicenses(); + + Assert.True(result.Count > 2); + Assert.Contains(result, license => license.Key == "mit"); + } + + [IntegrationTest] + public async Task CanRetrieveListOfLicensesWithPagination() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 5, + }; + + var result = await github.Licenses.GetAllLicenses(options); + + Assert.Equal(5, result.Count); + } + + [IntegrationTest] + public async Task CanRetrieveDistinctListOfLicensesBasedOnPageStart() + { + var github = Helper.GetAuthenticatedClient(); + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var firstPage = await github.Licenses.GetAllLicenses(startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await github.Licenses.GetAllLicenses(skipStartOptions); + + Assert.NotEqual(firstPage[0].Key, secondPage[0].Key); + } + } + + public class TheGetLicenseMethod + { + [IntegrationTest] + public async Task CanRetrieveListOfLicenses() + { + var github = Helper.GetAuthenticatedClient(); + + var result = await github.Licenses.GetLicense("mit"); + + Assert.Equal("mit", result.Key); + Assert.Equal("MIT License", result.Name); + } + + [IntegrationTest] + public async Task ReportsErrorWhenInvalidLicenseProvided() + { + var github = Helper.GetAuthenticatedClient(); + + await Assert.ThrowsAsync(() => github.Licenses.GetLicense("purple-monkey-dishwasher")); + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Clients/MarkdownClientTests.cs b/Octokit.Tests.Integration/Clients/MarkdownClientTests.cs new file mode 100644 index 0000000000..9e16f11c3f --- /dev/null +++ b/Octokit.Tests.Integration/Clients/MarkdownClientTests.cs @@ -0,0 +1,18 @@ +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class MarkdownClientTests + { + [IntegrationTest] + public async Task CanRenderGitHubFlavoredMarkdown() + { + var github = Helper.GetAuthenticatedClient(); + + var result = await github.Markdown.RenderRawMarkdown("This is\r\n a **test**"); + + Assert.Equal("

This is\na test

\n", result); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Clients/MetaClientTests.cs b/Octokit.Tests.Integration/Clients/MetaClientTests.cs new file mode 100644 index 0000000000..ddf5188114 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/MetaClientTests.cs @@ -0,0 +1,26 @@ +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class MetaClientTests + { + public class TheGetMetadataMethod + { + [IntegrationTest] + public async Task CanRetrieveMetadata() + { + var github = Helper.GetAnonymousClient(); + + var result = await github.Meta.GetMetadata(); + + Assert.True(result.VerifiablePasswordAuthentication); + Assert.NotEmpty(result.GitHubServicesSha); + Assert.True(result.Hooks.Count > 0); + Assert.True(result.Git.Count > 0); + Assert.True(result.Pages.Count > 0); + Assert.True(result.Importer.Count > 0); + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Clients/RateLimitClientTests.cs b/Octokit.Tests.Integration/Clients/RateLimitClientTests.cs new file mode 100644 index 0000000000..9719383836 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/RateLimitClientTests.cs @@ -0,0 +1,37 @@ +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class RateLimitClientTests + { + [IntegrationTest] + public async Task CanRetrieveResourceRateLimits() + { + var github = Helper.GetAuthenticatedClient(); + + var result = await github.RateLimit.GetRateLimits(); + + // Test the core limits + Assert.True(result.Resources.Core.Limit > 0); + Assert.True(result.Resources.Core.Remaining > -1); + Assert.True(result.Resources.Core.Remaining <= result.Resources.Core.Limit); + Assert.True(result.Resources.Core.ResetAsUtcEpochSeconds > 0); + Assert.NotEqual(default, result.Resources.Core.Reset); + + // Test the search limits + Assert.True(result.Resources.Search.Limit > 0); + Assert.True(result.Resources.Search.Remaining > -1); + Assert.True(result.Resources.Search.Remaining <= result.Resources.Search.Limit); + Assert.True(result.Resources.Search.ResetAsUtcEpochSeconds > 0); + Assert.NotEqual(default, result.Resources.Search.Reset); + + // Test the depreciated rate limits + Assert.True(result.Rate.Limit > 0); + Assert.True(result.Rate.Remaining > -1); + Assert.True(result.Rate.Remaining <= result.Rate.Limit); + Assert.True(result.Resources.Search.ResetAsUtcEpochSeconds > 0); + Assert.NotEqual(default, result.Resources.Search.Reset); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Clients/EmojisClientTests.cs b/Octokit.Tests/Clients/EmojisClientTests.cs new file mode 100644 index 0000000000..3f60d10ace --- /dev/null +++ b/Octokit.Tests/Clients/EmojisClientTests.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class EmojisClientTests + { + public class TheGetEmojisMethod + { + [Fact] + public async Task RequestsTheEmojiEndpoint() + { + IReadOnlyList response = new List + { + { new Emoji("foo", "http://example.com/foo.gif") }, + { new Emoji("bar", "http://example.com/bar.gif") } + }; + + var apiConnection = Substitute.For(); + apiConnection.GetAll(Args.Uri) + .Returns(Task.FromResult(response)); + + var client = new EmojisClient(apiConnection); + + var emojis = await client.GetAllEmojis(); + + Assert.Equal(2, emojis.Count); + Assert.Equal("foo", emojis[0].Name); + apiConnection.Received() + .GetAll(Arg.Is(u => u.ToString() == "emojis")); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new EmojisClient(null)); + } + } + } +} diff --git a/Octokit.Tests/Clients/LicensesClientTests.cs b/Octokit.Tests/Clients/LicensesClientTests.cs new file mode 100644 index 0000000000..852c50d9ec --- /dev/null +++ b/Octokit.Tests/Clients/LicensesClientTests.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class LicensesClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new LicensesClient(null)); + } + } + + public class TheGetAllLicensesMethod + { + [Fact] + public void EnsuresNonNullArguments() + { + var client = new LicensesClient(Substitute.For()); + + Assert.ThrowsAsync(() => client.GetAllLicenses(null)); + } + + [Fact] + public async Task RequestsTheLicensesEndpoint() + { + IReadOnlyList response = new ReadOnlyCollection(new List() + { + new LicenseMetadata("foo1", "node-id-1", "foo2", "something", "http://example.com/foo1", true), + new LicenseMetadata("bar1", "node-id-1", "bar2", "something else", "http://example.com/bar1", false) + }); + + var connection = Substitute.For(); + connection.GetAll(Arg.Is(u => u.ToString() == "licenses"), Args.ApiOptions) + .Returns(Task.FromResult(response)); + var client = new LicensesClient(connection); + + var licenses = await client.GetAllLicenses(); + + Assert.Equal(2, licenses.Count); + Assert.Equal("foo1", licenses[0].Key); + Assert.Equal("foo2", licenses[0].Name); + Assert.Equal("http://example.com/foo1", licenses[0].Url); + Assert.Equal("bar1", licenses[1].Key); + Assert.Equal("bar2", licenses[1].Name); + Assert.Equal("http://example.com/bar1", licenses[1].Url); + connection.Received() + .GetAll(Arg.Is(u => u.ToString() == "licenses"), Args.ApiOptions); + } + } + } +} diff --git a/Octokit.Tests/Clients/MarkdownClientTests.cs b/Octokit.Tests/Clients/MarkdownClientTests.cs new file mode 100644 index 0000000000..49e5d1dcb3 --- /dev/null +++ b/Octokit.Tests/Clients/MarkdownClientTests.cs @@ -0,0 +1,70 @@ +using System; +using System.Threading.Tasks; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class MarkdownClientTests + { + public class TheRenderRawMarkdownMethod + { + [Fact] + public async Task RequestsTheRawMarkdownEndpoint() + { + var markdown = "**Test**"; + var response = "Test"; + var apiConnection = Substitute.For(); + apiConnection.Post( + Arg.Is(u => u.ToString() == "markdown/raw"), + markdown, + "text/html", + "text/plain") + .Returns(Task.FromResult(response)); + var client = new MarkdownClient(apiConnection); + + var html = await client.RenderRawMarkdown(markdown); + + Assert.Equal("Test", html); + apiConnection.Received() + .Post(Arg.Is(u => u.ToString() == "markdown/raw"), + markdown, + "text/html", + "text/plain"); + } + } + public class TheRenderArbitraryMarkdownMethod + { + [Fact] + public async Task RequestsTheMarkdownEndpoint() + { + var response = "Test"; + + var payload = new NewArbitraryMarkdown("testMarkdown", "gfm", "testContext"); + + var apiConnection = Substitute.For(); + apiConnection.Post(Args.Uri, payload, "text/html", "text/plain") + .Returns(Task.FromResult(response)); + + var client = new MarkdownClient(apiConnection); + + var html = await client.RenderArbitraryMarkdown(payload); + Assert.Equal("Test", html); + apiConnection.Received() + .Post(Arg.Is(u => u.ToString() == "markdown"), + payload, + "text/html", + "text/plain"); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new MiscellaneousClient(null)); + } + } + } +} diff --git a/Octokit.Tests/Clients/MetaClientTests.cs b/Octokit.Tests/Clients/MetaClientTests.cs new file mode 100644 index 0000000000..c804a39726 --- /dev/null +++ b/Octokit.Tests/Clients/MetaClientTests.cs @@ -0,0 +1,51 @@ +using System; +using System.Threading.Tasks; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class MetaClientTests + { + public class TheGetMetadataMethod + { + [Fact] + public async Task RequestsTheMetadataEndpoint() + { + var meta = new Meta( + false, + "12345ABCDE", + new[] { "1.1.1.1/24", "1.1.1.2/24" }, + new[] { "1.1.2.1/24", "1.1.2.2/24" }, + new[] { "1.1.3.1/24", "1.1.3.2/24" }, + new[] { "1.1.4.1", "1.1.4.2" } + ); + + var apiConnection = Substitute.For(); + apiConnection.Get(Arg.Is(u => u.ToString() == "meta")).Returns(Task.FromResult(meta)); + var client = new MetaClient(apiConnection); + + var result = await client.GetMetadata(); + + Assert.False(result.VerifiablePasswordAuthentication); + Assert.Equal("12345ABCDE", result.GitHubServicesSha); + Assert.Equal(result.Hooks, new[] { "1.1.1.1/24", "1.1.1.2/24" }); + Assert.Equal(result.Git, new[] { "1.1.2.1/24", "1.1.2.2/24" }); + Assert.Equal(result.Pages, new[] { "1.1.3.1/24", "1.1.3.2/24" }); + Assert.Equal(result.Importer, new[] { "1.1.4.1", "1.1.4.2" }); + + apiConnection.Received() + .Get(Arg.Is(u => u.ToString() == "meta")); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new MetaClient(null)); + } + } + } +} diff --git a/Octokit.Tests/Clients/RateLimitClientTests.cs b/Octokit.Tests/Clients/RateLimitClientTests.cs new file mode 100644 index 0000000000..4c086d0b85 --- /dev/null +++ b/Octokit.Tests/Clients/RateLimitClientTests.cs @@ -0,0 +1,74 @@ +using System; +using System.Threading.Tasks; +using NSubstitute; +using Xunit; +using System.Globalization; + +namespace Octokit.Tests.Clients +{ + public class RateLimitClientTests + { + public class TheGetResourceRateLimitsMethod + { + [Fact] + public async Task RequestsTheResourceRateLimitEndpoint() + { + var rateLimit = new MiscellaneousRateLimit( + new ResourceRateLimit( + new RateLimit(5000, 4999, 1372700873), + new RateLimit(30, 18, 1372700873) + ), + new RateLimit(100, 75, 1372700873) + ); + var apiConnection = Substitute.For(); + apiConnection.Get(Arg.Is(u => u.ToString() == "rate_limit")).Returns(Task.FromResult(rateLimit)); + + var client = new RateLimitClient(apiConnection); + + var result = await client.GetRateLimits(); + + // Test the core limits + Assert.Equal(5000, result.Resources.Core.Limit); + Assert.Equal(4999, result.Resources.Core.Remaining); + Assert.Equal(1372700873, result.Resources.Core.ResetAsUtcEpochSeconds); + var expectedReset = DateTimeOffset.ParseExact( + "Mon 01 Jul 2013 5:47:53 PM -00:00", + "ddd dd MMM yyyy h:mm:ss tt zzz", + CultureInfo.InvariantCulture); + Assert.Equal(expectedReset, result.Resources.Core.Reset); + + // Test the search limits + Assert.Equal(30, result.Resources.Search.Limit); + Assert.Equal(18, result.Resources.Search.Remaining); + Assert.Equal(1372700873, result.Resources.Search.ResetAsUtcEpochSeconds); + expectedReset = DateTimeOffset.ParseExact( + "Mon 01 Jul 2013 5:47:53 PM -00:00", + "ddd dd MMM yyyy h:mm:ss tt zzz", + CultureInfo.InvariantCulture); + Assert.Equal(expectedReset, result.Resources.Search.Reset); + + // Test the depreciated rate limits + Assert.Equal(100, result.Rate.Limit); + Assert.Equal(75, result.Rate.Remaining); + Assert.Equal(1372700873, result.Rate.ResetAsUtcEpochSeconds); + expectedReset = DateTimeOffset.ParseExact( + "Mon 01 Jul 2013 5:47:53 PM -00:00", + "ddd dd MMM yyyy h:mm:ss tt zzz", + CultureInfo.InvariantCulture); + Assert.Equal(expectedReset, result.Rate.Reset); + + apiConnection.Received() + .Get(Arg.Is(u => u.ToString() == "rate_limit")); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new RateLimitClient(null)); + } + } + } +} diff --git a/Octokit.Tests/Reactive/ObservableEmojiClientTests.cs b/Octokit.Tests/Reactive/ObservableEmojiClientTests.cs new file mode 100644 index 0000000000..eac88d8771 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableEmojiClientTests.cs @@ -0,0 +1,33 @@ +using System; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableEmojiClientTests + { + public class TheGetAllEmojisMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableEmojisClient(gitHubClient); + + client.GetAllEmojis(); + + gitHubClient.Emojis.Received(1).GetAllEmojis(); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableEmojisClient((IGitHubClient)null)); + } + } + } +} diff --git a/Octokit.Tests/Reactive/ObservableGitIgnoreClientTests.cs b/Octokit.Tests/Reactive/ObservableGitIgnoreClientTests.cs new file mode 100644 index 0000000000..51e4634149 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableGitIgnoreClientTests.cs @@ -0,0 +1,47 @@ +using System; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableGitIgnoreClientTests + { + public class TheGetAllGitIgnoreTemplatesMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGitIgnoreClient(gitHubClient); + + client.GetAllGitIgnoreTemplates(); + + gitHubClient.GitIgnore.Received(1).GetAllGitIgnoreTemplates(); + } + } + + public class TheGetGitIgnoreTemplate + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGitIgnoreClient(gitHubClient); + + client.GetGitIgnoreTemplate("template"); + + gitHubClient.GitIgnore.Received(1).GetGitIgnoreTemplate("template"); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableGitIgnoreClient((IGitHubClient)null)); + } + } + } +} diff --git a/Octokit.Tests/Reactive/ObservableLicensesClientTests.cs b/Octokit.Tests/Reactive/ObservableLicensesClientTests.cs new file mode 100644 index 0000000000..b72b59924f --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableLicensesClientTests.cs @@ -0,0 +1,47 @@ +using System; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableLicensesClientTests + { + public class TheGetAllLicensesMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableLicensesClient(gitHubClient); + + client.GetAllLicenses(); + + gitHubClient.Licenses.Received(1).GetAllLicenses(Args.ApiOptions); + } + } + + public class TheGetLicenseMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableLicensesClient(gitHubClient); + + client.GetLicense("key"); + + gitHubClient.Licenses.Received(1).GetLicense("key"); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableLicensesClient((IGitHubClient)null)); + } + } + } +} diff --git a/Octokit.Tests/Reactive/ObservableMarkdownClientTests.cs b/Octokit.Tests/Reactive/ObservableMarkdownClientTests.cs new file mode 100644 index 0000000000..a61753550b --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableMarkdownClientTests.cs @@ -0,0 +1,47 @@ +using System; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableMarkdownClientTests + { + public class TheRenderArbitraryMarkdownMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMarkdownClient(gitHubClient); + + client.RenderArbitraryMarkdown(new NewArbitraryMarkdown("# test")); + + gitHubClient.Markdown.Received(1).RenderArbitraryMarkdown(Arg.Is(a => a.Text == "# test")); + } + } + + public class TheRenderRawMarkdownMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMarkdownClient(gitHubClient); + + client.RenderRawMarkdown("# test"); + + gitHubClient.Markdown.Received(1).RenderRawMarkdown("# test"); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableMarkdownClient((IGitHubClient)null)); + } + } + } +} diff --git a/Octokit.Tests/Reactive/ObservableMetaClientTests.cs b/Octokit.Tests/Reactive/ObservableMetaClientTests.cs new file mode 100644 index 0000000000..a2e0d71c41 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableMetaClientTests.cs @@ -0,0 +1,33 @@ +using System; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableMetaClientTests + { + public class TheGetMetadataMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMetaClient(gitHubClient); + + client.GetMetadata(); + + gitHubClient.Meta.Received(1).GetMetadata(); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableMetaClient((IGitHubClient)null)); + } + } + } +} diff --git a/Octokit.Tests/Reactive/ObservableRateLimitClientTests.cs b/Octokit.Tests/Reactive/ObservableRateLimitClientTests.cs new file mode 100644 index 0000000000..daad9fc330 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableRateLimitClientTests.cs @@ -0,0 +1,33 @@ +using System; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableRateLimitClientTests + { + public class TheGetRateLimitsMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRateLimitClient(gitHubClient); + + client.GetRateLimits(); + + gitHubClient.RateLimit.Received(1).GetRateLimits(); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableRateLimitClient((IGitHubClient)null)); + } + } + } +} diff --git a/Octokit/Clients/EmojisClient.cs b/Octokit/Clients/EmojisClient.cs new file mode 100644 index 0000000000..cdec98eff8 --- /dev/null +++ b/Octokit/Clients/EmojisClient.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Emojis APIs. + /// + /// + /// See the Emojis API documentation for more details. + /// + public class EmojisClient : ApiClient, IEmojisClient + { + /// + /// Initializes a new GitHub emojis API client. + /// + /// An API connection. + public EmojisClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Gets all the emojis available to use on GitHub. + /// + /// Thrown when a general API error occurs. + /// An of emoji and their URI. + [ManualRoute("GET", "/emojis")] + public Task> GetAllEmojis() + { + return ApiConnection.GetAll(ApiUrls.Emojis()); + } + } +} diff --git a/Octokit/Clients/GitIgnoreClient.cs b/Octokit/Clients/GitIgnoreClient.cs new file mode 100644 index 0000000000..8171dd1d38 --- /dev/null +++ b/Octokit/Clients/GitIgnoreClient.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's gitignore APIs. + /// + /// + /// See the GitIgnore API documentation for more details. + /// + public class GitIgnoreClient : ApiClient, IGitIgnoreClient + { + /// + /// Initializes a new GitHub gitignore API client. + /// + /// An API connection. + public GitIgnoreClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// List all templates available to pass as an option when creating a repository. + /// + /// A list of template names + [ManualRoute("GET", "/gitignore/templates")] + public Task> GetAllGitIgnoreTemplates() + { + return ApiConnection.GetAll(ApiUrls.GitIgnoreTemplates()); + } + + /// + /// Retrieves the source for a single GitIgnore template + /// + /// + /// A template and its source + [ManualRoute("GET", "/gitignore/templates/{name}")] + public Task GetGitIgnoreTemplate(string templateName) + { + Ensure.ArgumentNotNullOrEmptyString(templateName, nameof(templateName)); + + return ApiConnection.Get(ApiUrls.GitIgnoreTemplates(templateName)); + } + } +} \ No newline at end of file diff --git a/Octokit/Clients/IEmojisClient.cs b/Octokit/Clients/IEmojisClient.cs new file mode 100644 index 0000000000..5a1307ee2c --- /dev/null +++ b/Octokit/Clients/IEmojisClient.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Emojis APIs. + /// + /// + /// See the Emojis API documentation for more details. + /// + public interface IEmojisClient + { + /// + /// Gets all the emojis available to use on GitHub. + /// + /// Thrown when a general API error occurs. + /// An of emoji and their URI. + [ExcludeFromPaginationApiOptionsConventionTest("Pagination not supported by GitHub API (tested 29/08/2017)")] + Task> GetAllEmojis(); + } +} \ No newline at end of file diff --git a/Octokit/Clients/IGitIgnoreClient.cs b/Octokit/Clients/IGitIgnoreClient.cs new file mode 100644 index 0000000000..f69d6f5a88 --- /dev/null +++ b/Octokit/Clients/IGitIgnoreClient.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's gitignore APIs. + /// + /// + /// See the GitIgnore API documentation for more details. + /// + public interface IGitIgnoreClient + { + /// + /// List all templates available to pass as an option when creating a repository. + /// + /// A list of template names + [ExcludeFromPaginationApiOptionsConventionTest("Pagination not supported by GitHub API (tested 29/08/2017)")] + Task> GetAllGitIgnoreTemplates(); + + + /// + /// Retrieves the source for a single GitIgnore template + /// + /// + /// A template and its source + Task GetGitIgnoreTemplate(string templateName); + } +} \ No newline at end of file diff --git a/Octokit/Clients/ILicensesClient.cs b/Octokit/Clients/ILicensesClient.cs new file mode 100644 index 0000000000..f5b5cae9ea --- /dev/null +++ b/Octokit/Clients/ILicensesClient.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's licenses APIs. + /// + /// + /// See the Licenses API documentation for more details. + /// + public interface ILicensesClient + { + /// + /// Returns a list of the licenses shown in the license picker on GitHub.com. This is not a comprehensive + /// list of all possible OSS licenses. + /// + /// A list of licenses available on the site + Task> GetAllLicenses(); + + /// + /// Returns a list of the licenses shown in the license picker on GitHub.com. This is not a comprehensive + /// list of all possible OSS licenses. + /// + /// Options for changing the API response + /// A list of licenses available on the site + Task> GetAllLicenses(ApiOptions options); + + /// + /// Retrieves a license based on the license key such as "mit" + /// + /// + /// A that includes the license key, text, and attributes of the license. + Task GetLicense(string key); + } +} \ No newline at end of file diff --git a/Octokit/Clients/IMarkdownClient.cs b/Octokit/Clients/IMarkdownClient.cs new file mode 100644 index 0000000000..e4cd5abdc1 --- /dev/null +++ b/Octokit/Clients/IMarkdownClient.cs @@ -0,0 +1,29 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's markdown APIs. + /// + /// + /// See the Markdown API documentation for more details. + /// + public interface IMarkdownClient + { + /// + /// Gets the rendered Markdown for the specified plain-text Markdown document. + /// + /// A plain-text Markdown document + /// Thrown when a general API error occurs. + /// The rendered Markdown. + Task RenderArbitraryMarkdown(NewArbitraryMarkdown markdown); + + /// + /// Gets the rendered Markdown for an arbitrary markdown document. + /// + /// An arbitrary Markdown document + /// Thrown when a general API error occurs. + /// The rendered Markdown. + Task RenderRawMarkdown(string markdown); + } +} \ No newline at end of file diff --git a/Octokit/Clients/IMetaClient.cs b/Octokit/Clients/IMetaClient.cs new file mode 100644 index 0000000000..f4c21714d0 --- /dev/null +++ b/Octokit/Clients/IMetaClient.cs @@ -0,0 +1,20 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's meta APIs. + /// + /// + /// See the Meta API documentation for more details. + /// + public interface IMetaClient + { + /// + /// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation. + /// + /// Thrown when a general API error occurs. + /// An containing metadata about the GitHub instance. + Task GetMetadata(); + } +} \ No newline at end of file diff --git a/Octokit/Clients/IMiscellaneousClient.cs b/Octokit/Clients/IMiscellaneousClient.cs index 1766c79bb5..8463444b72 100644 --- a/Octokit/Clients/IMiscellaneousClient.cs +++ b/Octokit/Clients/IMiscellaneousClient.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; +using System; namespace Octokit { @@ -10,6 +10,7 @@ namespace Octokit /// /// See the Miscellaneous API documentation for more details. /// + [Obsolete("Use individual clients available on the GitHubClient for these methods")] public interface IMiscellaneousClient { /// @@ -17,8 +18,8 @@ public interface IMiscellaneousClient /// /// Thrown when a general API error occurs. /// An of emoji and their URI. - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] [ExcludeFromPaginationApiOptionsConventionTest("Pagination not supported by GitHub API (tested 29/08/2017)")] + [Obsolete("This client is being deprecated and will be removed in the future. Use EmojisClient.GetAllEmojis instead.")] Task> GetAllEmojis(); /// @@ -27,6 +28,7 @@ public interface IMiscellaneousClient /// A plain-text Markdown document /// Thrown when a general API error occurs. /// The rendered Markdown. + [Obsolete("This client is being deprecated and will be removed in the future. Use MarkdownClient.RenderRawMarkdown instead.")] Task RenderRawMarkdown(string markdown); /// @@ -35,14 +37,15 @@ public interface IMiscellaneousClient /// An arbitrary Markdown document /// Thrown when a general API error occurs. /// The rendered Markdown. + [Obsolete("This client is being deprecated and will be removed in the future. Use MarkdownClient.RenderArbitraryMarkdown instead.")] Task RenderArbitraryMarkdown(NewArbitraryMarkdown markdown); /// /// List all templates available to pass as an option when creating a repository. /// /// A list of template names - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] [ExcludeFromPaginationApiOptionsConventionTest("Pagination not supported by GitHub API (tested 29/08/2017)")] + [Obsolete("This client is being deprecated and will be removed in the future. Use GitIgnoreClient.GetAllGitIgnoreTemplates instead.")] Task> GetAllGitIgnoreTemplates(); /// @@ -50,6 +53,7 @@ public interface IMiscellaneousClient /// /// /// A template and its source + [Obsolete("This client is being deprecated and will be removed in the future. Use GitIgnoreClient.GetAllGitIgnoreTemplates instead.")] Task GetGitIgnoreTemplate(string templateName); /// @@ -57,7 +61,7 @@ public interface IMiscellaneousClient /// list of all possible OSS licenses. /// /// A list of licenses available on the site - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [Obsolete("This client is being deprecated and will be removed in the future. Use GitIgnoreClient.GetGitIgnoreTemplate instead.")] Task> GetAllLicenses(); /// @@ -66,6 +70,7 @@ public interface IMiscellaneousClient /// /// Options for changing the API response /// A list of licenses available on the site + [Obsolete("This client is being deprecated and will be removed in the future. Use LicensesClient.GetAllLicenses instead.")] Task> GetAllLicenses(ApiOptions options); /// @@ -73,6 +78,7 @@ public interface IMiscellaneousClient /// /// The license identifier to look for /// A that includes the license key, text, and attributes of the license. + [Obsolete("This client is being deprecated and will be removed in the future. Use LicensesClient.GetLicense instead.")] Task GetLicense(string key); /// @@ -80,7 +86,7 @@ public interface IMiscellaneousClient /// /// Thrown when a general API error occurs. /// An of Rate Limits. - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [Obsolete("This client is being deprecated and will be removed in the future. Use RateLimitClient.GetRateLimits instead.")] Task GetRateLimits(); /// @@ -88,7 +94,7 @@ public interface IMiscellaneousClient /// /// Thrown when a general API error occurs. /// An containing metadata about the GitHub instance. - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [Obsolete("This client is being deprecated and will be removed in the future. Use MetaClient.GetMetadata instead.")] Task GetMetadata(); } } diff --git a/Octokit/Clients/IRateLimitClient.cs b/Octokit/Clients/IRateLimitClient.cs new file mode 100644 index 0000000000..32e6bffdc9 --- /dev/null +++ b/Octokit/Clients/IRateLimitClient.cs @@ -0,0 +1,20 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's rate-limit APIs. + /// + /// + /// See the Rate-Limit API documentation for more details. + /// + public interface IRateLimitClient + { + /// + /// Gets API Rate Limits (API service rather than header info). + /// + /// Thrown when a general API error occurs. + /// An of Rate Limits. + Task GetRateLimits(); + } +} \ No newline at end of file diff --git a/Octokit/Clients/LicensesClient.cs b/Octokit/Clients/LicensesClient.cs new file mode 100644 index 0000000000..03cbbd18d8 --- /dev/null +++ b/Octokit/Clients/LicensesClient.cs @@ -0,0 +1,59 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's licenses APIs. + /// + /// + /// See the Licenses API documentation for more details. + /// + public class LicensesClient : ApiClient, ILicensesClient + { + /// + /// Initializes a new GitHub gitignore API client. + /// + /// An API connection. + public LicensesClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Returns a list of the licenses shown in the license picker on GitHub.com. This is not a comprehensive + /// list of all possible OSS licenses. + /// + /// A list of licenses available on the site + [ManualRoute("GET", "/licenses")] + public Task> GetAllLicenses() + { + return GetAllLicenses(ApiOptions.None); + } + + /// + /// Returns a list of the licenses shown in the license picker on GitHub.com. This is not a comprehensive + /// list of all possible OSS licenses. + /// + /// Options for changing the API response + /// A list of licenses available on the site + [ManualRoute("GET", "/licenses")] + public Task> GetAllLicenses(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Licenses(), options); + } + + /// + /// Retrieves a license based on the license key such as "mit" + /// + /// + /// A that includes the license key, text, and attributes of the license. + [ManualRoute("GET", "/licenses/{key}")] + public Task GetLicense(string key) + { + return ApiConnection.Get(ApiUrls.Licenses(key)); + } + } +} \ No newline at end of file diff --git a/Octokit/Clients/MarkdownClient.cs b/Octokit/Clients/MarkdownClient.cs new file mode 100644 index 0000000000..99944c580c --- /dev/null +++ b/Octokit/Clients/MarkdownClient.cs @@ -0,0 +1,46 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's markdown APIs. + /// + /// + /// See the Markdown API documentation for more details. + /// + public class MarkdownClient : ApiClient, IMarkdownClient + { + /// + /// Initializes a new GitHub markdown API client. + /// + /// An API connection. + public MarkdownClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Gets the rendered Markdown for the specified plain-text Markdown document. + /// + /// A plain-text Markdown document + /// Thrown when a general API error occurs. + /// The rendered Markdown. + [ManualRoute("POST", "/markdown/raw")] + public Task RenderRawMarkdown(string markdown) + { + return ApiConnection.Post(ApiUrls.RawMarkdown(), markdown, "text/html", "text/plain"); + } + + /// + /// Gets the rendered Markdown for an arbitrary markdown document. + /// + /// An arbitrary Markdown document + /// Thrown when a general API error occurs. + /// The rendered Markdown. + [ManualRoute("POST", "/markdown")] + public Task RenderArbitraryMarkdown(NewArbitraryMarkdown markdown) + { + return ApiConnection.Post(ApiUrls.Markdown(), markdown, "text/html", "text/plain"); + } + } +} diff --git a/Octokit/Clients/MetaClient.cs b/Octokit/Clients/MetaClient.cs new file mode 100644 index 0000000000..c683a34bba --- /dev/null +++ b/Octokit/Clients/MetaClient.cs @@ -0,0 +1,35 @@ +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's meta APIs. + /// + /// + /// See the Meta API documentation for more details. + /// + public class MetaClient : ApiClient, IMetaClient + { + /// + /// Initializes a new GitHub meta API client. + /// + /// An API connection. + public MetaClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation. + /// + /// Thrown when a general API error occurs. + /// An containing metadata about the GitHub instance. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [ManualRoute("GET", "/meta")] + public Task GetMetadata() + { + return ApiConnection.Get(ApiUrls.Meta()); + } + } +} \ No newline at end of file diff --git a/Octokit/Clients/MiscellaneousClient.cs b/Octokit/Clients/MiscellaneousClient.cs index 3ff32aa081..872753c393 100644 --- a/Octokit/Clients/MiscellaneousClient.cs +++ b/Octokit/Clients/MiscellaneousClient.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; namespace Octokit @@ -11,8 +10,16 @@ namespace Octokit /// /// See the Miscellaneous API documentation for more details. /// + [Obsolete("Use individual clients available on the GitHubClient for these methods")] public class MiscellaneousClient : ApiClient, IMiscellaneousClient { + private readonly IEmojisClient _emojisClient; + private readonly IMarkdownClient _markdownClient; + private readonly IGitIgnoreClient _gitIgnoreClient; + private readonly ILicensesClient _licensesClient; + private readonly IRateLimitClient _rateLimitClient; + private readonly IMetaClient _metaClient; + /// /// Initializes a new GitHub miscellaneous API client. /// @@ -20,6 +27,12 @@ public class MiscellaneousClient : ApiClient, IMiscellaneousClient public MiscellaneousClient(IApiConnection apiConnection) : base(apiConnection) { + _emojisClient = new EmojisClient(apiConnection); + _markdownClient = new MarkdownClient(apiConnection); + _gitIgnoreClient = new GitIgnoreClient(apiConnection); + _licensesClient = new LicensesClient(apiConnection); + _rateLimitClient = new RateLimitClient(apiConnection); + _metaClient = new MetaClient(apiConnection); } /// @@ -28,9 +41,10 @@ public MiscellaneousClient(IApiConnection apiConnection) /// Thrown when a general API error occurs. /// An of emoji and their URI. [ManualRoute("GET", "/emojis")] + [Obsolete("This client is being deprecated and will be removed in the future. Use EmojisClient.GetAllEmojis instead.")] public Task> GetAllEmojis() { - return ApiConnection.GetAll(ApiUrls.Emojis()); + return _emojisClient.GetAllEmojis(); } /// @@ -40,9 +54,10 @@ public Task> GetAllEmojis() /// Thrown when a general API error occurs. /// The rendered Markdown. [ManualRoute("POST", "/markdown/raw")] + [Obsolete("This client is being deprecated and will be removed in the future. Use MarkdownClient.RenderRawMarkdown instead.")] public Task RenderRawMarkdown(string markdown) { - return ApiConnection.Post(ApiUrls.RawMarkdown(), markdown, "text/html", "text/plain"); + return _markdownClient.RenderRawMarkdown(markdown); } /// @@ -52,9 +67,10 @@ public Task RenderRawMarkdown(string markdown) /// Thrown when a general API error occurs. /// The rendered Markdown. [ManualRoute("POST", "/markdown")] + [Obsolete("This client is being deprecated and will be removed in the future. Use MarkdownClient.RenderArbitraryMarkdown instead.")] public Task RenderArbitraryMarkdown(NewArbitraryMarkdown markdown) { - return ApiConnection.Post(ApiUrls.Markdown(), markdown, "text/html", "text/plain"); + return _markdownClient.RenderArbitraryMarkdown(markdown); } /// @@ -62,9 +78,10 @@ public Task RenderArbitraryMarkdown(NewArbitraryMarkdown markdown) /// /// A list of template names [ManualRoute("GET", "/gitignore/templates")] + [Obsolete("This client is being deprecated and will be removed in the future. Use GitIgnoreClient.GetAllGitIgnoreTemplates instead.")] public Task> GetAllGitIgnoreTemplates() { - return ApiConnection.GetAll(ApiUrls.GitIgnoreTemplates()); + return _gitIgnoreClient.GetAllGitIgnoreTemplates(); } /// @@ -73,11 +90,12 @@ public Task> GetAllGitIgnoreTemplates() /// /// A template and its source [ManualRoute("GET", "/gitignore/templates/{name}")] + [Obsolete("This client is being deprecated and will be removed in the future. Use GitIgnoreClient.GetGitIgnoreTemplate instead.")] public Task GetGitIgnoreTemplate(string templateName) { Ensure.ArgumentNotNullOrEmptyString(templateName, nameof(templateName)); - return ApiConnection.Get(ApiUrls.GitIgnoreTemplates(templateName)); + return _gitIgnoreClient.GetGitIgnoreTemplate(templateName); } /// @@ -85,10 +103,11 @@ public Task GetGitIgnoreTemplate(string templateName) /// list of all possible OSS licenses. /// /// A list of licenses available on the site + [Obsolete("This client is being deprecated and will be removed in the future. Use LicensesClient.GetAllLicenses instead.")] [ManualRoute("GET", "/licenses")] public Task> GetAllLicenses() { - return GetAllLicenses(ApiOptions.None); + return _licensesClient.GetAllLicenses(); } /// @@ -98,11 +117,12 @@ public Task> GetAllLicenses() /// Options for changing the API response /// A list of licenses available on the site [ManualRoute("GET", "/licenses")] + [Obsolete("This client is being deprecated and will be removed in the future. Use LicensesClient.GetAllLicenses instead.")] public Task> GetAllLicenses(ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.Licenses(), options); + return _licensesClient.GetAllLicenses(options); } /// @@ -111,9 +131,10 @@ public Task> GetAllLicenses(ApiOptions options) /// /// A that includes the license key, text, and attributes of the license. [ManualRoute("GET", "/licenses/{key}")] + [Obsolete("This client is being deprecated and will be removed in the future. Use LicensesClient.GetLicense instead.")] public Task GetLicense(string key) { - return ApiConnection.Get(ApiUrls.Licenses(key)); + return _licensesClient.GetLicense(key); } /// @@ -121,11 +142,11 @@ public Task GetLicense(string key) /// /// Thrown when a general API error occurs. /// An of Rate Limits. - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] [ManualRoute("GET", "/rate_limit")] + [Obsolete("This client is being deprecated and will be removed in the future. Use RateLimitClient.GetRateLimits instead.")] public Task GetRateLimits() { - return ApiConnection.Get(ApiUrls.RateLimit()); + return _rateLimitClient.GetRateLimits(); } /// @@ -133,11 +154,11 @@ public Task GetRateLimits() /// /// Thrown when a general API error occurs. /// An containing metadata about the GitHub instance. - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] [ManualRoute("GET", "/meta")] + [Obsolete("This client is being deprecated and will be removed in the future. Use MetaClient.GetMetadata instead.")] public Task GetMetadata() { - return ApiConnection.Get(ApiUrls.Meta()); + return _metaClient.GetMetadata(); } } -} +} \ No newline at end of file diff --git a/Octokit/Clients/RateLimitClient.cs b/Octokit/Clients/RateLimitClient.cs new file mode 100644 index 0000000000..df2d39bded --- /dev/null +++ b/Octokit/Clients/RateLimitClient.cs @@ -0,0 +1,35 @@ +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's rate-limit APIs. + /// + /// + /// See the Rate-Limit API documentation for more details. + /// + public class RateLimitClient : ApiClient, IRateLimitClient + { + /// + /// Initializes a new GitHub rate-limit API client. + /// + /// An API connection. + public RateLimitClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Gets API Rate Limits (API service rather than header info). + /// + /// Thrown when a general API error occurs. + /// An of Rate Limits. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [ManualRoute("GET", "/rate_limit")] + public Task GetRateLimits() + { + return ApiConnection.Get(ApiUrls.RateLimit()); + } + } +} \ No newline at end of file diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index d6c2cc11ab..ba2d8a2633 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -112,6 +112,12 @@ public GitHubClient(IConnection connection) Reaction = new ReactionsClient(apiConnection); Check = new ChecksClient(apiConnection); Packages = new PackagesClient(apiConnection); + Emojis = new EmojisClient(apiConnection); + Markdown = new MarkdownClient(apiConnection); + GitIgnore = new GitIgnoreClient(apiConnection); + Licenses = new LicensesClient(apiConnection); + RateLimit = new RateLimitClient(apiConnection); + Meta = new MetaClient(apiConnection); } /// @@ -186,6 +192,14 @@ public Uri BaseAddress /// public IActivitiesClient Activity { get; private set; } + /// + /// Access GitHub's Emojis API. + /// + /// + /// Refer to the API documentation for more information: https://docs.github.com/rest/emojis + /// + public IEmojisClient Emojis { get; private set; } + /// /// Access GitHub's Issue API. /// @@ -314,6 +328,46 @@ public Uri BaseAddress /// public IChecksClient Check { get; private set; } + /// + /// Access GitHub's Meta API. + /// + /// + /// Refer to the API documentation for more information: https://docs.github.com/rest/meta + /// + public IMetaClient Meta { get; private set; } + + /// + /// Access GitHub's Rate Limit API + /// + /// + /// Refer to the API documentation for more information: https://docs.github.com/rest/rate-limit + /// + public IRateLimitClient RateLimit { get; private set; } + + /// + /// Access GitHub's Licenses API + /// + /// + /// Refer to the API documentation for more information: https://docs.github.com/rest/licenses + /// + public ILicensesClient Licenses { get; private set; } + + /// + /// Access GitHub's Git Ignore API + /// + /// + /// Refer to the API documentation for more information: https://docs.github.com/rest/gitignore + /// + public IGitIgnoreClient GitIgnore { get; private set; } + + /// + /// Access GitHub's Markdown API + /// + /// + /// Refer to the API documentation for more information: https://docs.github.com/rest/markdown + /// + public IMarkdownClient Markdown { get; private set; } + static Uri FixUpBaseUri(Uri uri) { Ensure.ArgumentNotNull(uri, nameof(uri)); diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index 8ce93a976a..2de41eb246 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -166,5 +166,46 @@ public interface IGitHubClient : IApiInfoProvider /// Refer to the API documentation for more information: https://developer.github.com/v3/checks/ /// IChecksClient Check { get; } + + /// + /// Access GitHub's Meta API. + /// + /// + /// Refer to the API documentation for more information: https://docs.github.com/rest/meta + /// + IMetaClient Meta { get; } + + /// + /// Access GitHub's Rate Limit API + /// + /// + /// Refer to the API documentation for more information: https://docs.github.com/rest/rate-limit + /// + IRateLimitClient RateLimit { get; } + + /// + /// Access GitHub's Markdown API + /// + /// + /// Refer to the API documentation for more information: https://docs.github.com/rest/markdown + /// + IMarkdownClient Markdown { get; } + + /// + /// Access GitHub's Git Ignore API + /// + /// + /// Refer to the API documentation for more information: https://docs.github.com/rest/gitignore + /// + IGitIgnoreClient GitIgnore { get; } + + /// + /// Access GitHub's Licenses API + /// + /// + /// Refer to the API documentation for more information: https://docs.github.com/rest/licenses + /// + ILicensesClient Licenses { get; } + IEmojisClient Emojis { get; } } }