mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
* bugfix - PUT should have a payload for Mark as Read (#1579) * bugfix - PUT should have a payload for Mark as Read * also fix the Observable client test * add integration tests for MarkRead methods * Fixup MarkReadForRepository methods to specify a body in the PUT request * Fix unit tests for regular and observable client * helps if the new files are included in the test project :) * Cloning ApiInfo object should work when some fields are null (#1580) * Adjust ApiInfo.Clone() to work even if some elements (eg ETag) are null * Remove c# 6 language feature and do it the old school way * Add a test for cloning ApiInfo when some fields are null * The 3 lists can never be null anyway so remove some un-needed statements * Add test for null RateLimit * Remove Rx-Main dependency from samples This resolves #1592 - LINQPad doesn't understand how to restore this unlisted package and it's not actually needed in the samples. * Adding RemovedFromProject and other missing EventInfoState types. (#1591) * Adding missing review types to event info. * Fixing whitespace. * Reword `BaseRefChanged` comment * Adding missing event types. * Change response models 'Url' properties from `Uri` to `string` (#1585) * Add convention test to ensure 'Url' properties are of type string Closes #1582 * Change 'Url' properties from Uri to string Global Find/Replace FTW! * fix compilation errors in the integration tests project * Extend 'Url' properties type check to request models * Stick to convention tests naming convention * Remove unused using directives in models Changing from `Uri` to `string` means the `using System;` directive was not needed anymore in some files * Update exception message wording * empty commit to trigger a new build - hopefully Travis passes * add convention test to ensure request models have Uri 'Url' properties * make request models 'Url' properties Uri fix typo in convention test name * revert some request models 'Url' properties as `string` see https://github.com/octokit/octokit.net/pull/1585#issuecomment-297186728 * Change test so that all model types must have 'Url' properties of type string - Filter test input to only get types which have 'Url' properties - Merge response and request model types tests into one - Unparameterize the exception since we only check for the string type now * Fix string.Format tokens If this PR doesn't get rebased, it'll be my wall of shame FOREVER! * and then it's even more embarrassing when the commit message says rebased but you really meant squashed * Remove exclusion of `Release` from request models
150 lines
6.8 KiB
C#
150 lines
6.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace Octokit
|
|
{
|
|
/// <summary>
|
|
/// A client for GitHub's miscellaneous APIs.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/misc/">Miscellaneous API documentation</a> for more details.
|
|
/// </remarks>
|
|
public class MiscellaneousClient : IMiscellaneousClient
|
|
{
|
|
readonly IConnection _connection;
|
|
|
|
/// <summary>
|
|
/// Initializes a new GitHub miscellaneous API client.
|
|
/// </summary>
|
|
/// <param name="connection">An API connection</param>
|
|
public MiscellaneousClient(IConnection connection)
|
|
{
|
|
Ensure.ArgumentNotNull(connection, "connection");
|
|
|
|
_connection = connection;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets all the emojis available to use on GitHub.
|
|
/// </summary>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>An <see cref="IReadOnlyDictionary{TKey,TValue}"/> of emoji and their URI.</returns>
|
|
public async Task<IReadOnlyList<Emoji>> GetAllEmojis()
|
|
{
|
|
var endpoint = new Uri("emojis", UriKind.Relative);
|
|
var response = await _connection.Get<Dictionary<string, string>>(endpoint, null, null).ConfigureAwait(false);
|
|
return new ReadOnlyCollection<Emoji>(
|
|
response.Body.Select(kvp => new Emoji(kvp.Key, kvp.Value)).ToArray());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the rendered Markdown for the specified plain-text Markdown document.
|
|
/// </summary>
|
|
/// <param name="markdown">A plain-text Markdown document</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>The rendered Markdown.</returns>
|
|
public async Task<string> RenderRawMarkdown(string markdown)
|
|
{
|
|
var endpoint = new Uri("markdown/raw", UriKind.Relative);
|
|
var response = await _connection.Post<string>(endpoint, markdown, "text/html", "text/plain").ConfigureAwait(false);
|
|
return response.Body;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the rendered Markdown for an arbitrary markdown document.
|
|
/// </summary>
|
|
/// <param name="markdown">An arbitrary Markdown document</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>The rendered Markdown.</returns>
|
|
public async Task<string> RenderArbitraryMarkdown(NewArbitraryMarkdown markdown)
|
|
{
|
|
var endpoint = new Uri("markdown", UriKind.Relative);
|
|
var response = await _connection.Post<string>(endpoint, markdown, "text/html", "text/plain").ConfigureAwait(false);
|
|
return response.Body;
|
|
}
|
|
|
|
/// <summary>
|
|
/// List all templates available to pass as an option when creating a repository.
|
|
/// </summary>
|
|
/// <returns>A list of template names</returns>
|
|
public async Task<IReadOnlyList<string>> GetAllGitIgnoreTemplates()
|
|
{
|
|
var endpoint = new Uri("gitignore/templates", UriKind.Relative);
|
|
|
|
var response = await _connection.Get<string[]>(endpoint, null, null).ConfigureAwait(false);
|
|
return new ReadOnlyCollection<string>(response.Body);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves the source for a single GitIgnore template
|
|
/// </summary>
|
|
/// <param name="templateName"></param>
|
|
/// <returns>A template and its source</returns>
|
|
public async Task<GitIgnoreTemplate> GetGitIgnoreTemplate(string templateName)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(templateName, "templateName");
|
|
|
|
var endpoint = new Uri("gitignore/templates/" + Uri.EscapeUriString(templateName), UriKind.Relative);
|
|
|
|
var response = await _connection.Get<GitIgnoreTemplate>(endpoint, null, null).ConfigureAwait(false);
|
|
return response.Body;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
/// <remarks>This is a PREVIEW API! Use it at your own risk.</remarks>
|
|
/// <returns>A list of licenses available on the site</returns>
|
|
public async Task<IReadOnlyList<LicenseMetadata>> GetAllLicenses()
|
|
{
|
|
var endpoint = new Uri("licenses", UriKind.Relative);
|
|
|
|
var response = await _connection.Get<LicenseMetadata[]>(endpoint, null, AcceptHeaders.LicensesApiPreview).ConfigureAwait(false);
|
|
return new ReadOnlyCollection<LicenseMetadata>(response.Body);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves a license based on the license key such as "mit"
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <returns>A <see cref="License" /> that includes the license key, text, and attributes of the license.</returns>
|
|
public async Task<License> GetLicense(string key)
|
|
{
|
|
var endpoint = new Uri("licenses/" + Uri.EscapeUriString(key), UriKind.Relative);
|
|
|
|
var response = await _connection.Get<License>(endpoint, null, AcceptHeaders.LicensesApiPreview).ConfigureAwait(false);
|
|
return response.Body;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets API Rate Limits (API service rather than header info).
|
|
/// </summary>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>An <see cref="MiscellaneousRateLimit"/> of Rate Limits.</returns>
|
|
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
|
|
public async Task<MiscellaneousRateLimit> GetRateLimits()
|
|
{
|
|
var endpoint = new Uri("rate_limit", UriKind.Relative);
|
|
var response = await _connection.Get<MiscellaneousRateLimit>(endpoint, null, null).ConfigureAwait(false);
|
|
return response.Body;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation.
|
|
/// </summary>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>An <see cref="Meta"/> containing metadata about the GitHub instance.</returns>
|
|
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
|
|
public async Task<Meta> GetMetadata()
|
|
{
|
|
var endpoint = new Uri("meta", UriKind.Relative);
|
|
var response = await _connection.Get<Meta>(endpoint, null, null).ConfigureAwait(false);
|
|
return response.Body;
|
|
}
|
|
}
|
|
} |